mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-02 22:17:10 +08:00

* MF-325 - Add SPDX license and copyright headers Signed-off-by: Ivan Milošević <iva@blokovi.com> * MF-325 - Add SPDX license and copyright headers Signed-off-by: Ivan Milošević <iva@blokovi.com> * MF-325 - Add SPDX license and copyright headers Signed-off-by: Ivan Milošević <iva@blokovi.com> * MF-325 - Add SPDX license and copyright headers Signed-off-by: Ivan Milošević <iva@blokovi.com> * MF-325 - Change mainflux version from 0.4.0 to 0.5.0 Signed-off-by: Ivan Milošević <iva@blokovi.com>
41 lines
943 B
Go
41 lines
943 B
Go
//
|
|
// Copyright (c) 2018
|
|
// Mainflux
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package grpc
|
|
|
|
import (
|
|
"github.com/go-kit/kit/endpoint"
|
|
"github.com/mainflux/mainflux/things"
|
|
context "golang.org/x/net/context"
|
|
)
|
|
|
|
func canAccessEndpoint(svc things.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(accessReq)
|
|
if err := req.validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
id, err := svc.CanAccess(req.chanID, req.thingKey)
|
|
if err != nil {
|
|
return identityRes{id: 0, err: err}, err
|
|
}
|
|
return identityRes{id: id, err: nil}, nil
|
|
}
|
|
}
|
|
|
|
func identifyEndpoint(svc things.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(identifyReq)
|
|
id, err := svc.Identify(req.key)
|
|
if err != nil {
|
|
return identityRes{id: 0, err: err}, err
|
|
}
|
|
return identityRes{id: id, err: nil}, nil
|
|
}
|
|
}
|