forked from absmach/magistrala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint.go
38 lines (30 loc) · 1005 Bytes
/
endpoint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package policies
import (
"context"
"github.com/go-kit/kit/endpoint"
"github.com/mainflux/mainflux/auth"
)
func createPolicyEndpoint(svc auth.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(policiesReq)
if err := req.validate(); err != nil {
return createPolicyRes{}, err
}
if err := svc.AddPolicies(ctx, req.token, req.Object, req.SubjectIDs, req.Policies); err != nil {
return createPolicyRes{}, err
}
return createPolicyRes{created: true}, nil
}
}
func deletePoliciesEndpoint(svc auth.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(policiesReq)
if err := req.validate(); err != nil {
return deletePoliciesRes{}, err
}
if err := svc.DeletePolicies(ctx, req.token, req.Object, req.SubjectIDs, req.Policies); err != nil {
return deletePoliciesRes{}, err
}
return deletePoliciesRes{deleted: true}, nil
}
}