Skip to content

Commit

Permalink
MG-2216 - Rename delete policy function (absmach#2218)
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
  • Loading branch information
nyagamunene authored Jun 21, 2024
1 parent ef1322b commit 424aa7c
Show file tree
Hide file tree
Showing 30 changed files with 960 additions and 792 deletions.
827 changes: 491 additions & 336 deletions auth.pb.go

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ service AuthService {
rpc Authorize(AuthorizeReq) returns (AuthorizeRes) {}
rpc AddPolicy(AddPolicyReq) returns (AddPolicyRes) {}
rpc AddPolicies(AddPoliciesReq) returns (AddPoliciesRes) {}
rpc DeletePolicy(DeletePolicyReq) returns (DeletePolicyRes) {}
rpc DeletePolicyFilter(DeletePolicyFilterReq) returns (DeletePolicyFilterRes) {}
rpc DeletePolicies(DeletePoliciesReq) returns (DeletePoliciesRes) {}
rpc ListObjects(ListObjectsReq) returns (ListObjectsRes) {}
rpc ListAllObjects(ListObjectsReq) returns (ListObjectsRes) {}
Expand Down Expand Up @@ -102,7 +102,7 @@ message AddPolicyRes { bool added = 1; }

message AddPoliciesRes { bool added = 1; }

message DeletePolicyReq {
message DeletePolicyFilterReq {
string domain = 1;
string subject_type = 2;
string subject_relation = 3;
Expand All @@ -115,11 +115,24 @@ message DeletePolicyReq {
string object_type = 10;
}

message DeletePolicyFilterRes { bool deleted = 1; }

message DeletePoliciesReq {
repeated DeletePolicyReq deletePoliciesReq = 1;
}

message DeletePolicyRes { bool deleted = 1; }
message DeletePolicyReq {
string domain = 1;
string subject_type = 2;
string subject_relation = 3;
string subject_kind = 4;
string subject = 5;
string relation = 6;
string permission = 7;
string object = 8;
string object_kind = 9;
string object_type = 10;
}

message DeletePoliciesRes { bool deleted = 1; }

Expand Down
62 changes: 31 additions & 31 deletions auth/api/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ const svcName = "magistrala.AuthService"
var _ magistrala.AuthServiceClient = (*grpcClient)(nil)

type grpcClient struct {
issue endpoint.Endpoint
refresh endpoint.Endpoint
identify endpoint.Endpoint
authorize endpoint.Endpoint
addPolicy endpoint.Endpoint
addPolicies endpoint.Endpoint
deletePolicy endpoint.Endpoint
deletePolicies endpoint.Endpoint
listObjects endpoint.Endpoint
listAllObjects endpoint.Endpoint
countObjects endpoint.Endpoint
listSubjects endpoint.Endpoint
listAllSubjects endpoint.Endpoint
countSubjects endpoint.Endpoint
listPermissions endpoint.Endpoint
timeout time.Duration
issue endpoint.Endpoint
refresh endpoint.Endpoint
identify endpoint.Endpoint
authorize endpoint.Endpoint
addPolicy endpoint.Endpoint
addPolicies endpoint.Endpoint
deletePolicyFilter endpoint.Endpoint
deletePolicies endpoint.Endpoint
listObjects endpoint.Endpoint
listAllObjects endpoint.Endpoint
countObjects endpoint.Endpoint
listSubjects endpoint.Endpoint
listAllSubjects endpoint.Endpoint
countSubjects endpoint.Endpoint
listPermissions endpoint.Endpoint
timeout time.Duration
}

// NewClient returns new gRPC client instance.
Expand Down Expand Up @@ -93,13 +93,13 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) magistrala.AuthServ
decodeAddPoliciesResponse,
magistrala.AddPoliciesRes{},
).Endpoint(),
deletePolicy: kitgrpc.NewClient(
deletePolicyFilter: kitgrpc.NewClient(
conn,
svcName,
"DeletePolicy",
encodeDeletePolicyRequest,
decodeDeletePolicyResponse,
magistrala.DeletePolicyRes{},
"DeletePolicyFilter",
encodeDeletePolicyFilterRequest,
decodeDeletePolicyFilterResponse,
magistrala.DeletePolicyFilterRes{},
).Endpoint(),
deletePolicies: kitgrpc.NewClient(
conn,
Expand Down Expand Up @@ -379,11 +379,11 @@ func encodeAddPoliciesRequest(_ context.Context, grpcReq interface{}) (interface
return &magistrala.AddPoliciesReq{AddPoliciesReq: addPolicies}, nil
}

func (client grpcClient) DeletePolicy(ctx context.Context, in *magistrala.DeletePolicyReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
func (client grpcClient) DeletePolicyFilter(ctx context.Context, in *magistrala.DeletePolicyFilterReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyFilterRes, error) {
ctx, cancel := context.WithTimeout(ctx, client.timeout)
defer cancel()

res, err := client.deletePolicy(ctx, policyReq{
res, err := client.deletePolicyFilter(ctx, policyReq{
Domain: in.GetDomain(),
SubjectType: in.GetSubjectType(),
SubjectKind: in.GetSubjectKind(),
Expand All @@ -395,21 +395,21 @@ func (client grpcClient) DeletePolicy(ctx context.Context, in *magistrala.Delete
Object: in.GetObject(),
})
if err != nil {
return &magistrala.DeletePolicyRes{}, decodeError(err)
return &magistrala.DeletePolicyFilterRes{}, decodeError(err)
}

dpr := res.(deletePolicyRes)
return &magistrala.DeletePolicyRes{Deleted: dpr.deleted}, nil
dpr := res.(deletePolicyFilterRes)
return &magistrala.DeletePolicyFilterRes{Deleted: dpr.deleted}, nil
}

func decodeDeletePolicyResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
res := grpcRes.(*magistrala.DeletePolicyRes)
return deletePolicyRes{deleted: res.GetDeleted()}, nil
func decodeDeletePolicyFilterResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
res := grpcRes.(*magistrala.DeletePolicyFilterRes)
return deletePolicyFilterRes{deleted: res.GetDeleted()}, nil
}

func encodeDeletePolicyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
func encodeDeletePolicyFilterRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
req := grpcReq.(policyReq)
return &magistrala.DeletePolicyReq{
return &magistrala.DeletePolicyFilterReq{
Domain: req.Domain,
SubjectType: req.SubjectType,
SubjectKind: req.SubjectKind,
Expand Down
10 changes: 5 additions & 5 deletions auth/api/grpc/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ func addPoliciesEndpoint(svc auth.Service) endpoint.Endpoint {
}
}

func deletePolicyEndpoint(svc auth.Service) endpoint.Endpoint {
func deletePolicyFilterEndpoint(svc auth.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(policyReq)
if err := req.validate(); err != nil {
return deletePolicyRes{}, err
return deletePolicyFilterRes{}, err
}

err := svc.DeletePolicy(ctx, auth.PolicyReq{
err := svc.DeletePolicyFilter(ctx, auth.PolicyReq{
Domain: req.Domain,
SubjectKind: req.SubjectKind,
SubjectType: req.SubjectType,
Expand All @@ -170,9 +170,9 @@ func deletePolicyEndpoint(svc auth.Service) endpoint.Endpoint {
Object: req.Object,
})
if err != nil {
return deletePolicyRes{}, err
return deletePolicyFilterRes{}, err
}
return deletePolicyRes{deleted: true}, nil
return deletePolicyFilterRes{deleted: true}, nil
}
}

Expand Down
Loading

0 comments on commit 424aa7c

Please sign in to comment.