2018-05-10 23:53:25 +02:00
|
|
|
package mocks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/mainflux/mainflux"
|
2018-05-15 17:13:09 +02:00
|
|
|
"github.com/mainflux/mainflux/things"
|
2018-05-10 23:53:25 +02:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
var _ mainflux.ThingsServiceClient = (*thingsClient)(nil)
|
2018-05-10 23:53:25 +02:00
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
type thingsClient struct {
|
|
|
|
things map[string]string
|
2018-05-10 23:53:25 +02:00
|
|
|
}
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
// NewThingsClient returns mock implementation of things service client.
|
|
|
|
func NewThingsClient(data map[string]string) mainflux.ThingsServiceClient {
|
|
|
|
return &thingsClient{data}
|
2018-05-10 23:53:25 +02:00
|
|
|
}
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
func (tc thingsClient) CanAccess(ctx context.Context, req *mainflux.AccessReq, opts ...grpc.CallOption) (*mainflux.Identity, error) {
|
2018-05-10 23:53:25 +02:00
|
|
|
key := req.GetToken()
|
|
|
|
if key == "" {
|
2018-05-15 17:13:09 +02:00
|
|
|
return nil, things.ErrUnauthorizedAccess
|
2018-05-10 23:53:25 +02:00
|
|
|
}
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
id, ok := tc.things[key]
|
2018-05-10 23:53:25 +02:00
|
|
|
if !ok {
|
2018-05-15 17:13:09 +02:00
|
|
|
return nil, things.ErrUnauthorizedAccess
|
2018-05-10 23:53:25 +02:00
|
|
|
}
|
|
|
|
|
2018-05-11 01:00:10 +02:00
|
|
|
return &mainflux.Identity{Value: id}, nil
|
2018-05-10 23:53:25 +02:00
|
|
|
}
|
2018-05-17 20:17:02 +02:00
|
|
|
|
|
|
|
func (tc thingsClient) Identify(ctx context.Context, req *mainflux.Token, opts ...grpc.CallOption) (*mainflux.Identity, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|