mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-29 13:49:28 +08:00
35 lines
798 B
Go
35 lines
798 B
Go
package mocks
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/mainflux/mainflux"
|
|
"github.com/mainflux/mainflux/clients"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
var _ mainflux.ClientsServiceClient = (*clientsClient)(nil)
|
|
|
|
type clientsClient struct {
|
|
clients map[string]string
|
|
}
|
|
|
|
// NewClientsClient returns mock implementation of clients service client.
|
|
func NewClientsClient(data map[string]string) mainflux.ClientsServiceClient {
|
|
return &clientsClient{data}
|
|
}
|
|
|
|
func (client clientsClient) CanAccess(ctx context.Context, req *mainflux.AccessReq, opts ...grpc.CallOption) (*mainflux.Identity, error) {
|
|
key := req.GetToken()
|
|
if key == "" {
|
|
return nil, clients.ErrUnauthorizedAccess
|
|
}
|
|
|
|
id, ok := client.clients[key]
|
|
if !ok {
|
|
return nil, clients.ErrAccessForbidden
|
|
}
|
|
|
|
return &mainflux.Identity{Value: id}, nil
|
|
}
|