Skip to content

Commit

Permalink
Update grpc api
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene committed Oct 31, 2024
1 parent 9b06240 commit 3ad5253
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 283 deletions.
42 changes: 0 additions & 42 deletions auth/api/grpc/auth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ func NewAuthClient(conn *grpc.ClientConn, timeout time.Duration) grpcAuthV1.Auth
grpcAuthV1.AuthZRes{},
).Endpoint(),
timeout: timeout,
authorizePAT: kitgrpc.NewClient(
conn,
authSvcName,
"AuthorizePAT",
encodeAuthorizePATRequest,
decodeAuthorizeResponse,
grpcAuthV1.AuthZRes{},
).Endpoint(),
timeout: timeout,
}
}

Expand Down Expand Up @@ -119,36 +110,3 @@ func encodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}
}, nil
}

func (client authGrpcClient) AuthorizePAT(ctx context.Context, req *grpcAuthV1.AuthZReq, _ ...grpc.CallOption) (r *grpcAuthV1.AuthZRes, err error) {
ctx, cancel := context.WithTimeout(ctx, client.timeout)
defer cancel()

res, err := client.authorize(ctx, authReq{
Domain: req.GetDomain(),
SubjectType: req.GetSubjectType(),
Subject: req.GetSubject(),
SubjectKind: req.GetSubjectKind(),
Relation: req.GetRelation(),
Permission: req.GetPermission(),
ObjectType: req.GetObjectType(),
Object: req.GetObject(),
})
if err != nil {
return &grpcAuthV1.AuthZRes{}, grpcapi.DecodeError(err)
}

ar := res.(authorizeRes)
return &grpcAuthV1.AuthZRes{Authorized: ar.authorized, Id: ar.id}, nil
}

func encodeAuthorizePATRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
req := grpcReq.(authPATReq)
return &grpcAuthV1.AuthZpatReq{
PaToken: req.paToken,
PlatformEntityType: req.platformEntityType,
OptionalDomainID: req.optionalDomainID,
OptionalDomainEntityType: req.optionalDomainEntityType,
Operation: req.operation,
EntityIDs: req.entityIDs,
}, nil
}
15 changes: 0 additions & 15 deletions auth/api/grpc/auth/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,3 @@ func authorizeEndpoint(svc auth.Service) endpoint.Endpoint {
return authorizeRes{authorized: true}, nil
}
}

func authorizePATEndpoint(svc auth.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(authPATReq)

if err := req.validate(); err != nil {
return authorizeRes{}, err
}
err := svc.AuthorizePAT(ctx, req.paToken, req.platformEntityType, req.optionalDomainID,req.optionalDomainEntityType, req.operation, req.entityIDs)
if err != nil {
return authorizeRes{authorized: false}, err
}
return authorizeRes{authorized: true}, nil
}
}
19 changes: 0 additions & 19 deletions auth/api/grpc/auth/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type authGrpcServer struct {
grpcAuthV1.UnimplementedAuthServiceServer
authorize kitgrpc.Handler
authenticate kitgrpc.Handler
authorizePAT kitgrpc.Handler
}

// NewAuthServer returns new AuthnServiceServer instance.
Expand All @@ -35,12 +34,6 @@ func NewAuthServer(svc auth.Service) grpcAuthV1.AuthServiceServer {
decodeAuthenticateRequest,
encodeAuthenticateResponse,
),

authorizePAT: kitgrpc.NewServer(
(authorizePATEndpoint(svc)),
decodeAuthorizePATRequest,
encodeAuthorizeResponse,
),
}
}

Expand Down Expand Up @@ -88,15 +81,3 @@ func encodeAuthorizeResponse(_ context.Context, grpcRes interface{}) (interface{
res := grpcRes.(authorizeRes)
return &grpcAuthV1.AuthZRes{Authorized: res.authorized, Id: res.id}, nil
}

func decodeAuthorizePATRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
req := grpcReq.(*grpcAuthV1.AuthZpatReq)
return authPATReq{
paToken: req.GetPaToken(),
platformEntityType: req.GetPlatformEntityType(),
optionalDomainID: req.GetOptionalDomainID(),
optionalDomainEntityType: req.GetOptionalDomainEntityType(),
operation: req.GetOperation(),
entityIDs: req.GetEntityIDs(),
}, nil
}
164 changes: 21 additions & 143 deletions internal/grpc/auth/v1/auth.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3ad5253

Please sign in to comment.