Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMQ-2604 - Change PAT repo implementation #2680

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
94d3565
initial implemenation
nyagamunene Feb 3, 2025
27719f0
fix postgres error
nyagamunene Feb 3, 2025
511bc32
remove comments
nyagamunene Feb 3, 2025
4225694
fix tests
nyagamunene Feb 4, 2025
803c373
fix linter error
nyagamunene Feb 4, 2025
106150a
address comments
nyagamunene Feb 5, 2025
dddf73f
fix linter error
nyagamunene Feb 5, 2025
8092f64
debug add and remove scope issue
nyagamunene Feb 6, 2025
75bfca7
fix linter error
nyagamunene Feb 6, 2025
553291f
address comments
nyagamunene Feb 10, 2025
d8cf9eb
fix linter error
nyagamunene Feb 10, 2025
1d51759
refactor scope
nyagamunene Feb 11, 2025
6e29593
fix linter error
nyagamunene Feb 11, 2025
b7aa41e
update protos file
nyagamunene Feb 11, 2025
e38b10a
fix linter error
nyagamunene Feb 11, 2025
963b880
add list scopes endpoints
nyagamunene Feb 12, 2025
acfaf8d
fix linter error
nyagamunene Feb 12, 2025
94d1a92
fix linter error
nyagamunene Feb 12, 2025
dadcedc
update json scope example
nyagamunene Feb 12, 2025
63c719d
address comments
nyagamunene Feb 17, 2025
c5f48a0
fix linter error
nyagamunene Feb 17, 2025
5897847
address comments
nyagamunene Feb 18, 2025
2500c73
fix linter error
nyagamunene Feb 18, 2025
b809457
refactor cache
nyagamunene Feb 18, 2025
79e2eea
fix tests
nyagamunene Feb 18, 2025
358dbbd
fix linter error
nyagamunene Feb 18, 2025
86d1d08
add context to checkscope
nyagamunene Feb 19, 2025
292a1b4
add authnAuthzUserPAT
nyagamunene Feb 19, 2025
290da0f
address comments
nyagamunene Feb 20, 2025
6996f9f
add delete all pats endpoint
nyagamunene Feb 20, 2025
ffbf1d4
fix linter error
nyagamunene Feb 20, 2025
d72c665
address comments
nyagamunene Feb 24, 2025
cd45456
fix cache
nyagamunene Feb 24, 2025
58e4ec5
remove entry prefix
nyagamunene Feb 24, 2025
999f925
fix repo code
nyagamunene Feb 24, 2025
1fb20b1
remove unique constrain
nyagamunene Feb 24, 2025
200f857
add nginx config for path
arvindh123 Feb 24, 2025
bf44c39
add fix update methods in postgres
nyagamunene Feb 24, 2025
e3d7703
fix decodeClearAllScopeRequest method
nyagamunene Feb 24, 2025
bb1c63d
fix null time in the db
nyagamunene Feb 24, 2025
d0e47b4
fix failing linter
nyagamunene Feb 24, 2025
89672f6
fix revoke method
nyagamunene Feb 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 46 additions & 59 deletions api/grpc/auth/v1/auth.pb.go

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

26 changes: 12 additions & 14 deletions auth/api/grpc/auth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,12 @@ func (client authGrpcClient) AuthorizePAT(ctx context.Context, req *grpcAuthV1.A
defer cancel()

res, err := client.authorizePAT(ctx, authPATReq{
userID: req.GetUserId(),
patID: req.GetPatId(),
platformEntityType: auth.PlatformEntityType(req.GetPlatformEntityType()),
optionalDomainID: req.GetOptionalDomainId(),
optionalDomainEntityType: auth.DomainEntityType(req.GetOptionalDomainEntityType()),
operation: auth.OperationType(req.GetOperation()),
entityIDs: req.GetEntityIds(),
userID: req.GetUserId(),
patID: req.GetPatId(),
entityType: auth.EntityType(req.GetEntityType()),
optionalDomainID: req.GetOptionalDomainId(),
operation: auth.Operation(req.GetOperation()),
entityID: req.GetEntityId(),
})
if err != nil {
return &grpcAuthV1.AuthZRes{}, grpcapi.DecodeError(err)
Expand All @@ -170,12 +169,11 @@ func (client authGrpcClient) AuthorizePAT(ctx context.Context, req *grpcAuthV1.A
func encodeAuthorizePATRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
req := grpcReq.(authPATReq)
return &grpcAuthV1.AuthZPatReq{
UserId: req.userID,
PatId: req.patID,
PlatformEntityType: uint32(req.platformEntityType),
OptionalDomainId: req.optionalDomainID,
OptionalDomainEntityType: uint32(req.optionalDomainEntityType),
Operation: uint32(req.operation),
EntityIds: req.entityIDs,
UserId: req.userID,
PatId: req.patID,
EntityType: uint32(req.entityType),
OptionalDomainId: req.optionalDomainID,
Operation: uint32(req.operation),
EntityId: req.entityID,
}, nil
}
2 changes: 1 addition & 1 deletion auth/api/grpc/auth/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func authorizePATEndpoint(svc auth.Service) endpoint.Endpoint {
if err := req.validate(); err != nil {
return authorizeRes{}, err
}
err := svc.AuthorizePAT(ctx, req.userID, req.patID, req.platformEntityType, req.optionalDomainID, req.optionalDomainEntityType, req.operation, req.entityIDs...)
err := svc.AuthorizePAT(ctx, req.userID, req.patID, req.entityType, req.optionalDomainID, req.operation, req.entityID)
if err != nil {
return authorizeRes{authorized: false}, err
}
Expand Down
48 changes: 22 additions & 26 deletions auth/api/grpc/auth/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,12 @@ func TestAuthorizePAT(t *testing.T) {
desc: "authorize user with authorized token",
token: validPATToken,
authRequest: &grpcAuthV1.AuthZPatReq{
UserId: id,
PatId: id,
PlatformEntityType: uint32(auth.PlatformDomainsScope),
OptionalDomainId: domainID,
OptionalDomainEntityType: uint32(auth.DomainClientsScope),
Operation: uint32(auth.CreateOp),
EntityIds: []string{clientID},
UserId: id,
PatId: id,
EntityType: uint32(auth.ClientsType),
OptionalDomainId: domainID,
Operation: uint32(auth.CreateOp),
EntityId: clientID,
},
authResponse: &grpcAuthV1.AuthZRes{Authorized: true},
err: nil,
Expand All @@ -316,13 +315,12 @@ func TestAuthorizePAT(t *testing.T) {
desc: "authorize user with unauthorized token",
token: inValidPATToken,
authRequest: &grpcAuthV1.AuthZPatReq{
UserId: id,
PatId: id,
PlatformEntityType: uint32(auth.PlatformDomainsScope),
OptionalDomainId: domainID,
OptionalDomainEntityType: uint32(auth.DomainClientsScope),
Operation: uint32(auth.CreateOp),
EntityIds: []string{clientID},
UserId: id,
PatId: id,
EntityType: uint32(auth.ClientsType),
OptionalDomainId: domainID,
Operation: uint32(auth.CreateOp),
EntityId: clientID,
},
authResponse: &grpcAuthV1.AuthZRes{Authorized: false},
err: svcerr.ErrAuthorization,
Expand All @@ -331,12 +329,11 @@ func TestAuthorizePAT(t *testing.T) {
desc: "authorize user with missing user id",
token: validPATToken,
authRequest: &grpcAuthV1.AuthZPatReq{
PatId: id,
PlatformEntityType: uint32(auth.PlatformDomainsScope),
OptionalDomainId: domainID,
OptionalDomainEntityType: uint32(auth.DomainClientsScope),
Operation: uint32(auth.CreateOp),
EntityIds: []string{clientID},
PatId: id,
EntityType: uint32(auth.ClientsType),
OptionalDomainId: domainID,
Operation: uint32(auth.CreateOp),
EntityId: clientID,
},
authResponse: &grpcAuthV1.AuthZRes{Authorized: false},
err: apiutil.ErrMissingUserID,
Expand All @@ -345,12 +342,11 @@ func TestAuthorizePAT(t *testing.T) {
desc: "authorize user with missing pat id",
token: validPATToken,
authRequest: &grpcAuthV1.AuthZPatReq{
UserId: id,
PlatformEntityType: uint32(auth.PlatformDomainsScope),
OptionalDomainId: domainID,
OptionalDomainEntityType: uint32(auth.DomainClientsScope),
Operation: uint32(auth.CreateOp),
EntityIds: []string{clientID},
UserId: id,
EntityType: uint32(auth.ClientsType),
OptionalDomainId: domainID,
Operation: uint32(auth.CreateOp),
EntityId: clientID,
},
authResponse: &grpcAuthV1.AuthZRes{Authorized: false},
err: apiutil.ErrMissingPATID,
Expand Down
13 changes: 6 additions & 7 deletions auth/api/grpc/auth/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ func (req authReq) validate() error {
}

type authPATReq struct {
userID string
patID string
platformEntityType auth.PlatformEntityType
optionalDomainID string
optionalDomainEntityType auth.DomainEntityType
operation auth.OperationType
entityIDs []string
userID string
patID string
entityType auth.EntityType
optionalDomainID string
operation auth.Operation
entityID string
}

func (req authPATReq) validate() error {
Expand Down
13 changes: 6 additions & 7 deletions auth/api/grpc/auth/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,12 @@ func encodeAuthorizeResponse(_ context.Context, grpcRes interface{}) (interface{
func decodeAuthorizePATRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
req := grpcReq.(*grpcAuthV1.AuthZPatReq)
return authPATReq{
userID: req.GetUserId(),
patID: req.GetPatId(),
platformEntityType: auth.PlatformEntityType(req.GetPlatformEntityType()),
optionalDomainID: req.GetOptionalDomainId(),
optionalDomainEntityType: auth.DomainEntityType(req.GetOptionalDomainEntityType()),
operation: auth.OperationType(req.GetOperation()),
entityIDs: req.GetEntityIds(),
userID: req.GetUserId(),
patID: req.GetPatId(),
entityType: auth.EntityType(req.GetEntityType()),
optionalDomainID: req.GetOptionalDomainId(),
operation: auth.Operation(req.GetOperation()),
entityID: req.GetEntityId(),
}, nil
}

Expand Down
3 changes: 2 additions & 1 deletion auth/api/http/keys/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ func (tr testRequest) make() (*http.Response, error) {
func newService() (auth.Service, *mocks.KeyRepository) {
krepo := new(mocks.KeyRepository)
pRepo := new(mocks.PATSRepository)
cache := new(mocks.Cache)
hash := new(mocks.Hasher)
idProvider := uuid.NewMock()
pService := new(policymocks.Service)
pEvaluator := new(policymocks.Evaluator)
t := jwt.New([]byte(secret))

return auth.New(krepo, pRepo, hash, idProvider, t, pEvaluator, pService, loginDuration, refreshDuration, invalidDuration), krepo
return auth.New(krepo, pRepo, cache, hash, idProvider, t, pEvaluator, pService, loginDuration, refreshDuration, invalidDuration), krepo
}

func newServer(svc auth.Service) *httptest.Server {
Expand Down
Loading
Loading