mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-29 13:49:28 +08:00

* Change CanAccess to CanAccessByKey for things Signed-off-by: Nick Neisen <nwneisen@gmail.com> * Change CanAccess in remaining occurances Signed-off-by: Nick Neisen <nwneisen@gmail.com> * Regenerate generated files Signed-off-by: Nick Neisen <nwneisen@gmail.com> * Generate pb.go files with protoc 3.6.1 Signed-off-by: Nick Neisen <nwneisen@gmail.com>
68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package http
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-kit/kit/endpoint"
|
|
"github.com/mainflux/mainflux/things"
|
|
)
|
|
|
|
func identifyEndpoint(svc things.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(identifyReq)
|
|
if err := req.validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
id, err := svc.Identify(ctx, req.Token)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res := identityRes{
|
|
ID: id,
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
}
|
|
|
|
func canAccessByKeyEndpoint(svc things.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(canAccessByKeyReq)
|
|
if err := req.validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
id, err := svc.CanAccessByKey(ctx, req.chanID, req.Token)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res := identityRes{
|
|
ID: id,
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
}
|
|
|
|
func canAccessByIDEndpoint(svc things.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(canAccessByIDReq)
|
|
if err := req.validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := svc.CanAccessByID(ctx, req.chanID, req.ThingID); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res := canAccessByIDRes{}
|
|
return res, nil
|
|
}
|
|
}
|