diff options
Diffstat (limited to 'pkg/rpc/ability_service.go')
| -rw-r--r-- | pkg/rpc/ability_service.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/rpc/ability_service.go b/pkg/rpc/ability_service.go new file mode 100644 index 0000000..bf299da --- /dev/null +++ b/pkg/rpc/ability_service.go @@ -0,0 +1,26 @@ +package rpc + +import ( + context "context" + + "github.com/cedar-policy/cedar-go" + "gitlab.com/mokhax/spike/pkg/policies" +) + +type AbilityService struct { + UnimplementedAbilityServer +} + +func NewAbilityService() *AbilityService { + return &AbilityService{} +} + +func (h *AbilityService) Allowed(ctx context.Context, req *AllowRequest) (*AllowReply, error) { + ok := policies.Allowed(cedar.Request{ + Principal: cedar.NewEntityUID("User", cedar.String(req.Subject)), + Action: cedar.NewEntityUID("Action", cedar.String(req.Permission)), + Resource: cedar.NewEntityUID("Album", cedar.String(req.Resource)), + Context: cedar.NewRecord(cedar.RecordMap{}), + }) + return &AllowReply{Result: ok}, nil +} |
