From f400eef493dfce138e544611227c30123e894425 Mon Sep 17 00:00:00 2001 From: Rahmat Hidayat Date: Wed, 19 Jan 2022 11:14:28 +0700 Subject: [PATCH] fix!: migrate to uuid (#115) * fix!: migrate to uuid * fix(appeal): remove fatal logging in revoke expired access job handler --- Makefile | 2 +- api/handler/v1beta1/adapter.go | 30 ++-- api/handler/v1beta1/grpc.go | 18 +- .../odpf/guardian/v1beta1/guardian.pb.go | 136 +++++++------- .../odpf/guardian/v1beta1/guardian.pb.gw.go | 36 ++-- cmd/appeal.go | 31 ++-- cmd/provider.go | 16 +- cmd/resource.go | 15 +- core/appeal/job_handler.go | 8 +- core/appeal/service.go | 30 ++-- core/appeal/service_test.go | 166 +++++++++--------- core/policy/service_test.go | 12 +- core/provider/service.go | 4 +- core/provider/service_test.go | 10 +- core/resource/service.go | 4 +- core/resource/service_test.go | 20 +-- domain/appeal.go | 14 +- domain/approval.go | 4 +- domain/approver.go | 6 +- domain/policy.go | 2 +- domain/provider.go | 6 +- domain/resource.go | 4 +- go.mod | 1 + go.sum | 1 + mocks/AppealRepository.go | 16 +- mocks/AppealService.go | 36 ++-- mocks/ApprovalRepository.go | 2 +- mocks/ApprovalService.go | 2 +- mocks/PolicyRepository.go | 2 +- mocks/PolicyService.go | 2 +- mocks/ProviderRepository.go | 26 +-- mocks/ProviderService.go | 22 +-- mocks/ResourceRepository.go | 16 +- mocks/ResourceService.go | 16 +- plugins/providers/gcloudiam/provider_test.go | 8 +- plugins/providers/grafana/provider_test.go | 4 +- plugins/providers/metabase/provider_test.go | 8 +- plugins/providers/tableau/provider_test.go | 20 +-- store/model/appeal.go | 18 +- store/model/approval.go | 20 ++- store/model/approver.go | 20 ++- store/model/provider.go | 20 ++- store/model/resource.go | 24 ++- store/postgres/appeal_repository.go | 15 +- store/postgres/appeal_repository_test.go | 63 ++++--- store/postgres/approval_repository.go | 2 +- store/postgres/approval_repository_test.go | 11 +- store/postgres/provider_repository.go | 8 +- store/postgres/provider_repository_test.go | 24 +-- store/postgres/resource_repository.go | 8 +- store/postgres/resource_repository_test.go | 35 ++-- store/postgres/store.go | 22 ++- store/repository.go | 8 +- 53 files changed, 561 insertions(+), 493 deletions(-) diff --git a/Makefile b/Makefile index 31e6616ef..7d3761b33 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ NAME="github.com/odpf/guardian" LAST_COMMIT := $(shell git rev-parse --short HEAD) LAST_TAG := "$(shell git rev-list --tags --max-count=1)" APP_VERSION := "$(shell git describe --tags ${LAST_TAG})-next" -PROTON_COMMIT := "ef83b9e9248e064a1c366da4fe07b3068266fe59" +PROTON_COMMIT := "60f4fe9e5fc95660b56cf76b434d9557d9f483d7" .PHONY: all build test clean dist vet proto install diff --git a/api/handler/v1beta1/adapter.go b/api/handler/v1beta1/adapter.go index 2a7ef00a2..b809f54e6 100644 --- a/api/handler/v1beta1/adapter.go +++ b/api/handler/v1beta1/adapter.go @@ -23,7 +23,7 @@ func (a *adapter) FromProviderProto(p *guardianv1beta1.Provider) (*domain.Provid } return &domain.Provider{ - ID: uint(p.GetId()), + ID: p.GetId(), Type: p.GetType(), URN: p.GetUrn(), Config: providerConfig, @@ -87,7 +87,7 @@ func (a *adapter) ToProviderProto(p *domain.Provider) (*guardianv1beta1.Provider } return &guardianv1beta1.Provider{ - Id: uint32(p.ID), + Id: p.ID, Type: p.Type, Urn: p.URN, Config: config, @@ -210,7 +210,7 @@ func (a *adapter) FromPolicyProto(p *guardianv1beta1.Policy) (*domain.Policy, er ProviderURN: aa.GetResource().GetProviderUrn(), Type: aa.GetResource().GetType(), URN: aa.GetResource().GetUrn(), - ID: uint(aa.GetResource().GetId()), + ID: aa.GetResource().GetId(), } } @@ -304,7 +304,7 @@ func (a *adapter) ToPolicyProto(p *domain.Policy) (*guardianv1beta1.Policy, erro ProviderUrn: aa.Resource.ProviderURN, Type: aa.Resource.Type, Urn: aa.Resource.URN, - Id: uint32(aa.Resource.ID), + Id: aa.Resource.ID, } } @@ -357,7 +357,7 @@ func (a *adapter) FromResourceProto(r *guardianv1beta1.Resource) *domain.Resourc details = r.GetDetails().AsMap() } return &domain.Resource{ - ID: uint(r.GetId()), + ID: r.GetId(), ProviderType: r.GetProviderType(), ProviderURN: r.GetProviderUrn(), Type: r.GetType(), @@ -382,7 +382,7 @@ func (a *adapter) ToResourceProto(r *domain.Resource) (*guardianv1beta1.Resource } return &guardianv1beta1.Resource{ - Id: uint32(r.ID), + Id: r.ID, ProviderType: r.ProviderType, ProviderUrn: r.ProviderURN, Type: r.Type, @@ -408,9 +408,9 @@ func (a *adapter) FromAppealProto(appeal *guardianv1beta1.Appeal) (*domain.Appea } approvals = append(approvals, &domain.Approval{ - ID: uint(a.GetId()), + ID: a.GetId(), Name: a.GetName(), - AppealID: uint(a.GetId()), + AppealID: a.GetId(), Status: a.GetStatus(), Actor: actor, Reason: a.GetReason(), @@ -428,8 +428,8 @@ func (a *adapter) FromAppealProto(appeal *guardianv1beta1.Appeal) (*domain.Appea } return &domain.Appeal{ - ID: uint(appeal.GetId()), - ResourceID: uint(appeal.GetResourceId()), + ID: appeal.GetId(), + ResourceID: appeal.GetResourceId(), PolicyID: appeal.GetPolicyId(), PolicyVersion: uint(appeal.GetPolicyVersion()), Status: appeal.GetStatus(), @@ -486,8 +486,8 @@ func (a *adapter) ToAppealProto(appeal *domain.Appeal) (*guardianv1beta1.Appeal, } return &guardianv1beta1.Appeal{ - Id: uint32(appeal.ID), - ResourceId: uint32(appeal.ResourceID), + Id: appeal.ID, + ResourceId: appeal.ResourceID, PolicyId: appeal.PolicyID, PolicyVersion: uint32(appeal.PolicyVersion), Status: appeal.Status, @@ -524,7 +524,7 @@ func (a *adapter) FromCreateAppealProto(ca *guardianv1beta1.CreateAppealRequest, AccountID: ca.GetAccountId(), AccountType: ca.GetAccountType(), CreatedBy: authenticatedUser, - ResourceID: uint(r.GetId()), + ResourceID: r.GetId(), Role: r.GetRole(), Options: options, Details: r.GetDetails().AsMap(), @@ -550,9 +550,9 @@ func (a *adapter) ToApprovalProto(approval *domain.Approval) (*guardianv1beta1.A } return &guardianv1beta1.Approval{ - Id: uint32(approval.ID), + Id: approval.ID, Name: approval.Name, - AppealId: uint32(approval.AppealID), + AppealId: approval.AppealID, Appeal: appealProto, Status: approval.Status, Actor: actor, diff --git a/api/handler/v1beta1/grpc.go b/api/handler/v1beta1/grpc.go index 41ddfa1ee..d4b270a42 100644 --- a/api/handler/v1beta1/grpc.go +++ b/api/handler/v1beta1/grpc.go @@ -92,7 +92,7 @@ func (s *GRPCServer) ListProviders(ctx context.Context, req *guardianv1beta1.Lis } func (s *GRPCServer) GetProvider(ctx context.Context, req *guardianv1beta1.GetProviderRequest) (*guardianv1beta1.GetProviderResponse, error) { - p, err := s.providerService.GetByID(uint(req.GetId())) + p, err := s.providerService.GetByID(req.GetId()) if err != nil { switch err { case provider.ErrRecordNotFound: @@ -145,7 +145,7 @@ func (s *GRPCServer) UpdateProvider(ctx context.Context, req *guardianv1beta1.Up } p := &domain.Provider{ - ID: uint(id), + ID: id, Type: providerConfig.Type, URN: providerConfig.URN, Config: providerConfig, @@ -165,7 +165,7 @@ func (s *GRPCServer) UpdateProvider(ctx context.Context, req *guardianv1beta1.Up } func (s *GRPCServer) ListRoles(ctx context.Context, req *guardianv1beta1.ListRolesRequest) (*guardianv1beta1.ListRolesResponse, error) { - roles, err := s.providerService.GetRoles(uint(req.GetId()), req.GetResourceType()) + roles, err := s.providerService.GetRoles(req.GetId(), req.GetResourceType()) if err != nil { return nil, status.Errorf(codes.Internal, "failed to list roles: %v", err) } @@ -314,7 +314,7 @@ func (s *GRPCServer) ListResources(ctx context.Context, req *guardianv1beta1.Lis } func (s *GRPCServer) GetResource(ctx context.Context, req *guardianv1beta1.GetResourceRequest) (*guardianv1beta1.GetResourceResponse, error) { - r, err := s.resourceService.GetOne(uint(req.GetId())) + r, err := s.resourceService.GetOne(req.GetId()) if err != nil { switch err { case resource.ErrRecordNotFound: @@ -336,7 +336,7 @@ func (s *GRPCServer) GetResource(ctx context.Context, req *guardianv1beta1.GetRe func (s *GRPCServer) UpdateResource(ctx context.Context, req *guardianv1beta1.UpdateResourceRequest) (*guardianv1beta1.UpdateResourceResponse, error) { r := s.adapter.FromResourceProto(req.GetResource()) - r.ID = uint(req.GetId()) + r.ID = req.GetId() if err := s.resourceService.Update(r); err != nil { return nil, status.Errorf(codes.Internal, "failed to update resource: %v", err) @@ -500,7 +500,7 @@ func (s *GRPCServer) ListApprovals(ctx context.Context, req *guardianv1beta1.Lis func (s *GRPCServer) GetAppeal(ctx context.Context, req *guardianv1beta1.GetAppealRequest) (*guardianv1beta1.GetAppealResponse, error) { id := req.GetId() - appeal, err := s.appealService.GetByID(uint(id)) + appeal, err := s.appealService.GetByID(id) if err != nil { return nil, status.Errorf(codes.Internal, "failed to retrieve appeal: %v", err) } @@ -526,7 +526,7 @@ func (s *GRPCServer) UpdateApproval(ctx context.Context, req *guardianv1beta1.Up id := req.GetId() a, err := s.appealService.MakeAction(domain.ApprovalAction{ - AppealID: uint(id), + AppealID: id, ApprovalName: req.GetApprovalName(), Actor: actor, Action: req.GetAction().GetAction(), @@ -568,7 +568,7 @@ func (s *GRPCServer) UpdateApproval(ctx context.Context, req *guardianv1beta1.Up func (s *GRPCServer) CancelAppeal(ctx context.Context, req *guardianv1beta1.CancelAppealRequest) (*guardianv1beta1.CancelAppealResponse, error) { id := req.GetId() - a, err := s.appealService.Cancel(uint(id)) + a, err := s.appealService.Cancel(id) if err != nil { switch err { case appeal.ErrAppealNotFound: @@ -602,7 +602,7 @@ func (s *GRPCServer) RevokeAppeal(ctx context.Context, req *guardianv1beta1.Revo } reason := req.GetReason().GetReason() - a, err := s.appealService.Revoke(uint(id), actor, reason) + a, err := s.appealService.Revoke(id, actor, reason) if err != nil { switch err { case appeal.ErrAppealNotFound: diff --git a/api/proto/odpf/guardian/v1beta1/guardian.pb.go b/api/proto/odpf/guardian/v1beta1/guardian.pb.go index 87ed79f92..5f072fb5f 100644 --- a/api/proto/odpf/guardian/v1beta1/guardian.pb.go +++ b/api/proto/odpf/guardian/v1beta1/guardian.pb.go @@ -114,7 +114,7 @@ type GetProviderRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` } func (x *GetProviderRequest) Reset() { @@ -149,11 +149,11 @@ func (*GetProviderRequest) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{2} } -func (x *GetProviderRequest) GetId() uint32 { +func (x *GetProviderRequest) GetId() string { if x != nil { return x.Id } - return 0 + return "" } type GetProviderResponse struct { @@ -302,7 +302,7 @@ type UpdateProviderRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Config *ProviderConfig `protobuf:"bytes,2,opt,name=config,proto3" json:"config,omitempty"` } @@ -338,11 +338,11 @@ func (*UpdateProviderRequest) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{6} } -func (x *UpdateProviderRequest) GetId() uint32 { +func (x *UpdateProviderRequest) GetId() string { if x != nil { return x.Id } - return 0 + return "" } func (x *UpdateProviderRequest) GetConfig() *ProviderConfig { @@ -404,7 +404,7 @@ type ListRolesRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` ResourceType string `protobuf:"bytes,2,opt,name=resource_type,json=resourceType,proto3" json:"resource_type,omitempty"` } @@ -440,11 +440,11 @@ func (*ListRolesRequest) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{8} } -func (x *ListRolesRequest) GetId() uint32 { +func (x *ListRolesRequest) GetId() string { if x != nil { return x.Id } - return 0 + return "" } func (x *ListRolesRequest) GetResourceType() string { @@ -1031,7 +1031,7 @@ type GetResourceRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` } func (x *GetResourceRequest) Reset() { @@ -1066,11 +1066,11 @@ func (*GetResourceRequest) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{20} } -func (x *GetResourceRequest) GetId() uint32 { +func (x *GetResourceRequest) GetId() string { if x != nil { return x.Id } - return 0 + return "" } type GetResourceResponse struct { @@ -1125,7 +1125,7 @@ type UpdateResourceRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` } @@ -1161,11 +1161,11 @@ func (*UpdateResourceRequest) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{22} } -func (x *UpdateResourceRequest) GetId() uint32 { +func (x *UpdateResourceRequest) GetId() string { if x != nil { return x.Id } - return 0 + return "" } func (x *UpdateResourceRequest) GetResource() *Resource { @@ -1519,7 +1519,7 @@ type GetAppealRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` } func (x *GetAppealRequest) Reset() { @@ -1554,11 +1554,11 @@ func (*GetAppealRequest) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{28} } -func (x *GetAppealRequest) GetId() uint32 { +func (x *GetAppealRequest) GetId() string { if x != nil { return x.Id } - return 0 + return "" } type GetAppealResponse struct { @@ -1613,7 +1613,7 @@ type CancelAppealRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` } func (x *CancelAppealRequest) Reset() { @@ -1648,11 +1648,11 @@ func (*CancelAppealRequest) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{30} } -func (x *CancelAppealRequest) GetId() uint32 { +func (x *CancelAppealRequest) GetId() string { if x != nil { return x.Id } - return 0 + return "" } type CancelAppealResponse struct { @@ -1707,7 +1707,7 @@ type RevokeAppealRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Reason *RevokeAppealRequest_Reason `protobuf:"bytes,2,opt,name=reason,proto3" json:"reason,omitempty"` } @@ -1743,11 +1743,11 @@ func (*RevokeAppealRequest) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{32} } -func (x *RevokeAppealRequest) GetId() uint32 { +func (x *RevokeAppealRequest) GetId() string { if x != nil { return x.Id } - return 0 + return "" } func (x *RevokeAppealRequest) GetReason() *RevokeAppealRequest_Reason { @@ -2131,7 +2131,7 @@ type UpdateApprovalRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` ApprovalName string `protobuf:"bytes,2,opt,name=approval_name,json=approvalName,proto3" json:"approval_name,omitempty"` Action *UpdateApprovalRequest_Action `protobuf:"bytes,3,opt,name=action,proto3" json:"action,omitempty"` } @@ -2168,11 +2168,11 @@ func (*UpdateApprovalRequest) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{40} } -func (x *UpdateApprovalRequest) GetId() uint32 { +func (x *UpdateApprovalRequest) GetId() string { if x != nil { return x.Id } - return 0 + return "" } func (x *UpdateApprovalRequest) GetApprovalName() string { @@ -2463,7 +2463,7 @@ type Provider struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` Urn string `protobuf:"bytes,3,opt,name=urn,proto3" json:"urn,omitempty"` Config *ProviderConfig `protobuf:"bytes,4,opt,name=config,proto3" json:"config,omitempty"` @@ -2503,11 +2503,11 @@ func (*Provider) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{45} } -func (x *Provider) GetId() uint32 { +func (x *Provider) GetId() string { if x != nil { return x.Id } - return 0 + return "" } func (x *Provider) GetType() string { @@ -2773,8 +2773,8 @@ type Appeal struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - ResourceId uint32 `protobuf:"varint,2,opt,name=resource_id,json=resourceId,proto3" json:"resource_id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + ResourceId string `protobuf:"bytes,2,opt,name=resource_id,json=resourceId,proto3" json:"resource_id,omitempty"` PolicyId string `protobuf:"bytes,3,opt,name=policy_id,json=policyId,proto3" json:"policy_id,omitempty"` PolicyVersion uint32 `protobuf:"varint,4,opt,name=policy_version,json=policyVersion,proto3" json:"policy_version,omitempty"` Status string `protobuf:"bytes,5,opt,name=status,proto3" json:"status,omitempty"` @@ -2827,18 +2827,18 @@ func (*Appeal) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{49} } -func (x *Appeal) GetId() uint32 { +func (x *Appeal) GetId() string { if x != nil { return x.Id } - return 0 + return "" } -func (x *Appeal) GetResourceId() uint32 { +func (x *Appeal) GetResourceId() string { if x != nil { return x.ResourceId } - return 0 + return "" } func (x *Appeal) GetPolicyId() string { @@ -2973,9 +2973,9 @@ type Approval struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - AppealId uint32 `protobuf:"varint,3,opt,name=appeal_id,json=appealId,proto3" json:"appeal_id,omitempty"` + AppealId string `protobuf:"bytes,3,opt,name=appeal_id,json=appealId,proto3" json:"appeal_id,omitempty"` Status string `protobuf:"bytes,4,opt,name=status,proto3" json:"status,omitempty"` Actor string `protobuf:"bytes,5,opt,name=actor,proto3" json:"actor,omitempty"` PolicyId string `protobuf:"bytes,6,opt,name=policy_id,json=policyId,proto3" json:"policy_id,omitempty"` @@ -3019,11 +3019,11 @@ func (*Approval) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{50} } -func (x *Approval) GetId() uint32 { +func (x *Approval) GetId() string { if x != nil { return x.Id } - return 0 + return "" } func (x *Approval) GetName() string { @@ -3033,11 +3033,11 @@ func (x *Approval) GetName() string { return "" } -func (x *Approval) GetAppealId() uint32 { +func (x *Approval) GetAppealId() string { if x != nil { return x.AppealId } - return 0 + return "" } func (x *Approval) GetStatus() string { @@ -3109,7 +3109,7 @@ type Resource struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` ProviderType string `protobuf:"bytes,2,opt,name=provider_type,json=providerType,proto3" json:"provider_type,omitempty"` ProviderUrn string `protobuf:"bytes,3,opt,name=provider_urn,json=providerUrn,proto3" json:"provider_urn,omitempty"` Type string `protobuf:"bytes,4,opt,name=type,proto3" json:"type,omitempty"` @@ -3154,11 +3154,11 @@ func (*Resource) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{51} } -func (x *Resource) GetId() uint32 { +func (x *Resource) GetId() string { if x != nil { return x.Id } - return 0 + return "" } func (x *Resource) GetProviderType() string { @@ -3283,7 +3283,7 @@ type CreateAppealRequest_Resource struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` Options *structpb.Struct `protobuf:"bytes,3,opt,name=options,proto3" json:"options,omitempty"` Details *structpb.Struct `protobuf:"bytes,4,opt,name=details,proto3" json:"details,omitempty"` @@ -3321,11 +3321,11 @@ func (*CreateAppealRequest_Resource) Descriptor() ([]byte, []int) { return file_odpf_guardian_v1beta1_guardian_proto_rawDescGZIP(), []int{34, 0} } -func (x *CreateAppealRequest_Resource) GetId() uint32 { +func (x *CreateAppealRequest_Resource) GetId() string { if x != nil { return x.Id } - return 0 + return "" } func (x *CreateAppealRequest_Resource) GetRole() string { @@ -3949,7 +3949,7 @@ type Policy_Requirement_AdditionalAppeal_ResourceIdentifier struct { ProviderUrn string `protobuf:"bytes,2,opt,name=provider_urn,json=providerUrn,proto3" json:"provider_urn,omitempty"` Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"` Urn string `protobuf:"bytes,4,opt,name=urn,proto3" json:"urn,omitempty"` - Id uint32 `protobuf:"varint,5,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,5,opt,name=id,proto3" json:"id,omitempty"` } func (x *Policy_Requirement_AdditionalAppeal_ResourceIdentifier) Reset() { @@ -4012,11 +4012,11 @@ func (x *Policy_Requirement_AdditionalAppeal_ResourceIdentifier) GetUrn() string return "" } -func (x *Policy_Requirement_AdditionalAppeal_ResourceIdentifier) GetId() uint32 { +func (x *Policy_Requirement_AdditionalAppeal_ResourceIdentifier) GetId() string { if x != nil { return x.Id } - return 0 + return "" } var File_odpf_guardian_v1beta1_guardian_proto protoreflect.FileDescriptor @@ -4043,7 +4043,7 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x73, 0x22, 0x24, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, + 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x52, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x6f, 0x64, 0x70, 0x66, @@ -4062,7 +4062,7 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x2e, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x22, 0x66, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, - 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x3d, 0x0a, 0x06, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x3d, 0x0a, 0x06, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x6f, 0x64, 0x70, 0x66, 0x2e, 0x67, 0x75, 0x61, 0x72, 0x64, 0x69, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x43, 0x6f, 0x6e, @@ -4074,7 +4074,7 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x22, 0x47, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x6f, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, + 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0x46, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x6f, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, @@ -4137,7 +4137,7 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x6e, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x52, 0x09, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x22, 0x24, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x52, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x6f, @@ -4145,7 +4145,7 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x65, 0x74, 0x61, 0x31, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x52, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x64, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, + 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x3b, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x6f, 0x64, 0x70, 0x66, 0x2e, 0x67, 0x75, 0x61, 0x72, 0x64, 0x69, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, @@ -4200,7 +4200,7 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x75, 0x61, 0x72, 0x64, 0x69, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x41, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x52, 0x07, 0x61, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x73, 0x22, 0x22, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x4a, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x35, 0x0a, 0x06, 0x61, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x6f, 0x64, 0x70, 0x66, 0x2e, @@ -4208,14 +4208,14 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x2e, 0x41, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x52, 0x06, 0x61, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x22, 0x25, 0x0a, 0x13, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x41, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x22, 0x4d, 0x0a, 0x14, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, + 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x4d, 0x0a, 0x14, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x41, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x35, 0x0a, 0x06, 0x61, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x6f, 0x64, 0x70, 0x66, 0x2e, 0x67, 0x75, 0x61, 0x72, 0x64, 0x69, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x41, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x52, 0x06, 0x61, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x22, 0x92, 0x01, 0x0a, 0x13, 0x52, 0x65, 0x76, 0x6f, 0x6b, 0x65, 0x41, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x49, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x49, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x31, 0x2e, 0x6f, 0x64, 0x70, 0x66, 0x2e, 0x67, 0x75, 0x61, 0x72, 0x64, 0x69, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x52, 0x65, 0x76, 0x6f, 0x6b, 0x65, 0x41, 0x70, 0x70, 0x65, @@ -4239,7 +4239,7 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x63, 0x65, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x1a, 0x94, 0x01, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x6f, 0x75, - 0x72, 0x63, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x72, 0x63, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x12, 0x31, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, @@ -4278,7 +4278,7 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x41, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x61, 0x6c, 0x52, 0x09, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x61, 0x6c, 0x73, 0x22, 0xd3, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x61, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x23, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x61, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x61, 0x6c, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x4b, 0x0a, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, @@ -4355,7 +4355,7 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x64, 0x70, 0x66, 0x2e, 0x67, 0x75, 0x61, 0x72, 0x64, 0x69, 0x61, 0x6e, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x52, 0x6f, 0x6c, 0x65, 0x52, 0x05, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x22, 0xf5, 0x01, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6e, 0x12, 0x3d, 0x0a, 0x06, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x04, 0x20, @@ -4479,7 +4479,7 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x64, 0x65, 0x72, 0x55, 0x72, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6e, 0x12, 0x0e, 0x0a, 0x02, - 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x1a, 0xd3, 0x01, 0x0a, + 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x1a, 0xd3, 0x01, 0x0a, 0x03, 0x49, 0x41, 0x4d, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x2e, 0x0a, 0x06, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, @@ -4501,9 +4501,9 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x61, 0x74, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x9e, 0x07, 0x0a, 0x06, 0x41, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x12, - 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, + 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x49, 0x64, 0x12, 0x25, 0x0a, 0x0e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, @@ -4559,10 +4559,10 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xa0, 0x03, 0x0a, 0x08, 0x41, 0x70, 0x70, 0x72, 0x6f, 0x76, - 0x61, 0x6c, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, + 0x61, 0x6c, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x70, 0x70, 0x65, 0x61, 0x6c, - 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x61, 0x70, 0x70, 0x65, 0x61, + 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x61, 0x70, 0x70, 0x65, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x63, 0x74, 0x6f, @@ -4586,7 +4586,7 @@ var file_odpf_guardian_v1beta1_guardian_proto_rawDesc = []byte{ 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0xe4, 0x03, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, + 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x5f, 0x75, 0x72, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, diff --git a/api/proto/odpf/guardian/v1beta1/guardian.pb.gw.go b/api/proto/odpf/guardian/v1beta1/guardian.pb.gw.go index 494e2b8d5..979b04693 100644 --- a/api/proto/odpf/guardian/v1beta1/guardian.pb.gw.go +++ b/api/proto/odpf/guardian/v1beta1/guardian.pb.gw.go @@ -65,7 +65,7 @@ func request_GuardianService_GetProvider_0(ctx context.Context, marshaler runtim return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -91,7 +91,7 @@ func local_request_GuardianService_GetProvider_0(ctx context.Context, marshaler return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -159,7 +159,7 @@ func request_GuardianService_UpdateProvider_0(ctx context.Context, marshaler run return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -193,7 +193,7 @@ func local_request_GuardianService_UpdateProvider_0(ctx context.Context, marshal return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -219,7 +219,7 @@ func request_GuardianService_ListRoles_0(ctx context.Context, marshaler runtime. return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -255,7 +255,7 @@ func local_request_GuardianService_ListRoles_0(ctx context.Context, marshaler ru return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -519,7 +519,7 @@ func request_GuardianService_GetResource_0(ctx context.Context, marshaler runtim return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -545,7 +545,7 @@ func local_request_GuardianService_GetResource_0(ctx context.Context, marshaler return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -579,7 +579,7 @@ func request_GuardianService_UpdateResource_0(ctx context.Context, marshaler run return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -613,7 +613,7 @@ func local_request_GuardianService_UpdateResource_0(ctx context.Context, marshal return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -711,7 +711,7 @@ func request_GuardianService_GetAppeal_0(ctx context.Context, marshaler runtime. return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -737,7 +737,7 @@ func local_request_GuardianService_GetAppeal_0(ctx context.Context, marshaler ru return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -763,7 +763,7 @@ func request_GuardianService_CancelAppeal_0(ctx context.Context, marshaler runti return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -789,7 +789,7 @@ func local_request_GuardianService_CancelAppeal_0(ctx context.Context, marshaler return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -823,7 +823,7 @@ func request_GuardianService_RevokeAppeal_0(ctx context.Context, marshaler runti return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -857,7 +857,7 @@ func local_request_GuardianService_RevokeAppeal_0(ctx context.Context, marshaler return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -997,7 +997,7 @@ func request_GuardianService_UpdateApproval_0(ctx context.Context, marshaler run return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } @@ -1041,7 +1041,7 @@ func local_request_GuardianService_UpdateApproval_0(ctx context.Context, marshal return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } - protoReq.Id, err = runtime.Uint32(val) + protoReq.Id, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) } diff --git a/cmd/appeal.go b/cmd/appeal.go index c2d786890..a64255291 100644 --- a/cmd/appeal.go +++ b/cmd/appeal.go @@ -99,10 +99,7 @@ func listAppealsCommand(c *app.CLIConfig) *cobra.Command { } func createAppealCommand(c *app.CLIConfig) *cobra.Command { - var accountID string - var resourceID uint - var role string - var optionsDuration string + var accountID, resourceID, role, optionsDuration string cmd := &cobra.Command{ Use: "create", @@ -133,13 +130,14 @@ func createAppealCommand(c *app.CLIConfig) *cobra.Command { AccountId: accountID, Resources: []*guardianv1beta1.CreateAppealRequest_Resource{ { - Id: uint32(resourceID), + Id: resourceID, Role: role, Options: optionsProto, }, }, }) if err != nil { + fmt.Println("Create error") return err } @@ -153,7 +151,7 @@ func createAppealCommand(c *app.CLIConfig) *cobra.Command { cmd.Flags().StringVarP(&accountID, "account", "a", "", "Email of the account to appeal") cmd.MarkFlagRequired("account") - cmd.Flags().UintVarP(&resourceID, "resource", "R", 0, "ID of the resource") + cmd.Flags().StringVarP(&resourceID, "resource", "R", "", "ID of the resource") cmd.MarkFlagRequired("resource") cmd.Flags().StringVarP(&role, "role", "r", "", "Role to be assigned") @@ -165,8 +163,7 @@ func createAppealCommand(c *app.CLIConfig) *cobra.Command { } func revokeAppealCommand(c *app.CLIConfig) *cobra.Command { - var id uint - var reason string + var id, reason string cmd := &cobra.Command{ Use: "revoke", @@ -180,7 +177,7 @@ func revokeAppealCommand(c *app.CLIConfig) *cobra.Command { defer cancel() _, err = client.RevokeAppeal(ctx, &guardianv1beta1.RevokeAppealRequest{ - Id: uint32(id), + Id: id, Reason: &guardianv1beta1.RevokeAppealRequest_Reason{ Reason: reason, }, @@ -195,7 +192,7 @@ func revokeAppealCommand(c *app.CLIConfig) *cobra.Command { }, } - cmd.Flags().UintVar(&id, "id", 0, "ID of the appeal") + cmd.Flags().StringVar(&id, "id", "", "ID of the appeal") cmd.MarkFlagRequired("id") cmd.Flags().StringVarP(&reason, "reason", "r", "", "Reason of the revocation") @@ -204,8 +201,7 @@ func revokeAppealCommand(c *app.CLIConfig) *cobra.Command { } func approveApprovalStepCommand(c *app.CLIConfig) *cobra.Command { - var id uint - var approvalName string + var id, approvalName string cmd := &cobra.Command{ Use: "approve", @@ -219,7 +215,7 @@ func approveApprovalStepCommand(c *app.CLIConfig) *cobra.Command { defer cancel() _, err = client.UpdateApproval(ctx, &guardianv1beta1.UpdateApprovalRequest{ - Id: uint32(id), + Id: id, ApprovalName: approvalName, Action: &guardianv1beta1.UpdateApprovalRequest_Action{ Action: "approve", @@ -235,7 +231,7 @@ func approveApprovalStepCommand(c *app.CLIConfig) *cobra.Command { }, } - cmd.Flags().UintVar(&id, "id", 0, "ID of the appeal") + cmd.Flags().StringVar(&id, "id", "", "ID of the appeal") cmd.MarkFlagRequired("id") cmd.Flags().StringVarP(&approvalName, "step", "s", "", "Name of approval step") cmd.MarkFlagRequired("approval-name") @@ -244,8 +240,7 @@ func approveApprovalStepCommand(c *app.CLIConfig) *cobra.Command { } func rejectApprovalStepCommand(c *app.CLIConfig) *cobra.Command { - var id uint - var approvalName string + var id, approvalName string cmd := &cobra.Command{ Use: "reject", @@ -260,7 +255,7 @@ func rejectApprovalStepCommand(c *app.CLIConfig) *cobra.Command { defer cancel() _, err = client.UpdateApproval(ctx, &guardianv1beta1.UpdateApprovalRequest{ - Id: uint32(id), + Id: id, ApprovalName: approvalName, Action: &guardianv1beta1.UpdateApprovalRequest_Action{ Action: "reject", @@ -276,7 +271,7 @@ func rejectApprovalStepCommand(c *app.CLIConfig) *cobra.Command { }, } - cmd.Flags().UintVar(&id, "id", 0, "ID of the appeal") + cmd.Flags().StringVar(&id, "id", "", "ID of the appeal") cmd.MarkFlagRequired("id") cmd.Flags().StringVarP(&approvalName, "step", "s", "", "Name of approval step") cmd.MarkFlagRequired("approval-name") diff --git a/cmd/provider.go b/cmd/provider.go index d8d6c2d5b..7ec8d0ff7 100644 --- a/cmd/provider.go +++ b/cmd/provider.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "os" - "strconv" "github.com/MakeNowJust/heredoc" handlerv1beta1 "github.com/odpf/guardian/api/handler/v1beta1" @@ -113,13 +112,9 @@ func getProviderCmd(c *app.CLIConfig, adapter handlerv1beta1.ProtoAdapter) *cobr } defer cancel() - id, err := strconv.ParseUint(args[0], 10, 32) - if err != nil { - return fmt.Errorf("invalid provider id: %v", err) - } - + id := args[0] res, err := client.GetProvider(ctx, &guardianv1beta1.GetProviderRequest{ - Id: uint32(id), + Id: id, }) if err != nil { return err @@ -191,8 +186,7 @@ func createProviderCmd(c *app.CLIConfig, adapter handlerv1beta1.ProtoAdapter) *c } func updateProviderCmd(c *app.CLIConfig, adapter handlerv1beta1.ProtoAdapter) *cobra.Command { - var id uint - var filePath string + var id, filePath string cmd := &cobra.Command{ Use: "edit", Short: "Edit a provider", @@ -221,7 +215,7 @@ func updateProviderCmd(c *app.CLIConfig, adapter handlerv1beta1.ProtoAdapter) *c defer cancel() _, err = client.UpdateProvider(ctx, &guardianv1beta1.UpdateProviderRequest{ - Id: uint32(id), + Id: id, Config: configProto, }) if err != nil { @@ -234,7 +228,7 @@ func updateProviderCmd(c *app.CLIConfig, adapter handlerv1beta1.ProtoAdapter) *c }, } - cmd.Flags().UintVar(&id, "id", 0, "provider id") + cmd.Flags().StringVar(&id, "id", "", "provider id") cmd.MarkFlagRequired("id") cmd.Flags().StringVarP(&filePath, "file", "f", "", "Path to the provider config") cmd.MarkFlagRequired("file") diff --git a/cmd/resource.go b/cmd/resource.go index d5550ad4d..7fb41b948 100644 --- a/cmd/resource.go +++ b/cmd/resource.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "os" - "strconv" "strings" "github.com/MakeNowJust/heredoc" @@ -140,13 +139,9 @@ func getResourceCmd(c *app.CLIConfig, adapter handlerv1beta1.ProtoAdapter) *cobr } defer cancel() - id, err := strconv.ParseUint(args[0], 10, 32) - if err != nil { - return fmt.Errorf("invalid resource id: %v", err) - } - + id := args[0] res, err := client.GetResource(ctx, &guardianv1beta1.GetResourceRequest{ - Id: uint32(id), + Id: id, }) if err != nil { return err @@ -166,7 +161,7 @@ func getResourceCmd(c *app.CLIConfig, adapter handlerv1beta1.ProtoAdapter) *cobr } func metadataCmd(c *app.CLIConfig) *cobra.Command { - var id uint + var id string var values []string cmd := &cobra.Command{ @@ -202,7 +197,7 @@ func metadataCmd(c *app.CLIConfig) *cobra.Command { // TODO: get one resource _, err = client.UpdateResource(ctx, &guardianv1beta1.UpdateResourceRequest{ - Id: uint32(id), + Id: id, Resource: &guardianv1beta1.Resource{ Details: metadataProto, }, @@ -219,7 +214,7 @@ func metadataCmd(c *app.CLIConfig) *cobra.Command { cmd.Flags().StringArrayVar(&values, "values", []string{}, "list of key-value pair. Example: key=value foo=bar") - cmd.PersistentFlags().UintVar(&id, "id", 0, "resource id") + cmd.PersistentFlags().StringVar(&id, "id", "", "resource id") cmd.MarkPersistentFlagRequired("id") return cmd diff --git a/core/appeal/job_handler.go b/core/appeal/job_handler.go index 61a6c2bb9..383ba0d30 100644 --- a/core/appeal/job_handler.go +++ b/core/appeal/job_handler.go @@ -37,18 +37,18 @@ func (h *JobHandler) RevokeExpiredAccess() error { } h.logger.Info(fmt.Sprintf("found %d access that should be expired\n", len(appeals))) - successRevoke := []uint{} + successRevoke := []string{} failedRevoke := []map[string]interface{}{} for _, a := range appeals { - h.logger.Info(fmt.Sprintf("revoking access with appeal id: %d\n", a.ID)) + h.logger.Info(fmt.Sprintf("revoking access with appeal id: %s\n", a.ID)) if _, err := h.appealService.Revoke(a.ID, domain.SystemActorName, "Automatically revoked"); err != nil { - h.logger.Info(fmt.Sprintf("failed to revoke access %d, error: %s\n", a.ID, err.Error())) + h.logger.Info(fmt.Sprintf("failed to revoke access %s, error: %s\n", a.ID, err.Error())) failedRevoke = append(failedRevoke, map[string]interface{}{ "id": a.ID, "error": err.Error(), }) } else { - h.logger.Info(fmt.Sprintf("access %d revoked successfully\n", a.ID)) + h.logger.Info(fmt.Sprintf("access %s revoked successfully\n", a.ID)) successRevoke = append(successRevoke, a.ID) } } diff --git a/core/appeal/service.go b/core/appeal/service.go index afe0bad20..5c99c9374 100644 --- a/core/appeal/service.go +++ b/core/appeal/service.go @@ -59,8 +59,8 @@ func NewService( } // GetByID returns one record by id -func (s *Service) GetByID(id uint) (*domain.Appeal, error) { - if id == 0 { +func (s *Service) GetByID(id string) (*domain.Appeal, error) { + if id == "" { return nil, ErrAppealIDEmptyParam } @@ -74,7 +74,7 @@ func (s *Service) Find(filters *domain.ListAppealsFilter) ([]*domain.Appeal, err // Create record func (s *Service) Create(appeals []*domain.Appeal) error { - resourceIDs := []uint{} + resourceIDs := []string{} for _, a := range appeals { resourceIDs = append(resourceIDs, a.ResourceID) } @@ -293,7 +293,7 @@ func (s *Service) MakeAction(approvalAction domain.ApprovalAction) (*domain.Appe return nil, ErrApprovalNameNotFound } -func (s *Service) Cancel(id uint) (*domain.Appeal, error) { +func (s *Service) Cancel(id string) (*domain.Appeal, error) { appeal, err := s.GetByID(id) if err != nil { return nil, err @@ -313,7 +313,7 @@ func (s *Service) Cancel(id uint) (*domain.Appeal, error) { return appeal, nil } -func (s *Service) Revoke(id uint, actor, reason string) (*domain.Appeal, error) { +func (s *Service) Revoke(id string, actor, reason string) (*domain.Appeal, error) { appeal, err := s.repo.GetByID(id) if err != nil { return nil, err @@ -353,7 +353,7 @@ func (s *Service) Revoke(id uint, actor, reason string) (*domain.Appeal, error) return revokedAppeal, nil } -func (s *Service) getExistingAppealsMap() (map[string]map[uint]map[string]*domain.Appeal, map[string]map[uint]map[string]*domain.Appeal, error) { +func (s *Service) getExistingAppealsMap() (map[string]map[string]map[string]*domain.Appeal, map[string]map[string]map[string]*domain.Appeal, error) { appeals, err := s.repo.Find(&domain.ListAppealsFilter{ Statuses: []string{domain.AppealStatusPending, domain.AppealStatusActive}, }) @@ -361,12 +361,12 @@ func (s *Service) getExistingAppealsMap() (map[string]map[uint]map[string]*domai return nil, nil, err } - pendingAppealsMap := map[string]map[uint]map[string]*domain.Appeal{} - activeAppealsMap := map[string]map[uint]map[string]*domain.Appeal{} + pendingAppealsMap := map[string]map[string]map[string]*domain.Appeal{} + activeAppealsMap := map[string]map[string]map[string]*domain.Appeal{} for _, a := range appeals { if a.Status == domain.AppealStatusPending { if pendingAppealsMap[a.AccountID] == nil { - pendingAppealsMap[a.AccountID] = map[uint]map[string]*domain.Appeal{} + pendingAppealsMap[a.AccountID] = map[string]map[string]*domain.Appeal{} } if pendingAppealsMap[a.AccountID][a.ResourceID] == nil { pendingAppealsMap[a.AccountID][a.ResourceID] = map[string]*domain.Appeal{} @@ -374,7 +374,7 @@ func (s *Service) getExistingAppealsMap() (map[string]map[uint]map[string]*domai pendingAppealsMap[a.AccountID][a.ResourceID][a.Role] = a } else if a.Status == domain.AppealStatusActive { if activeAppealsMap[a.AccountID] == nil { - activeAppealsMap[a.AccountID] = map[uint]map[string]*domain.Appeal{} + activeAppealsMap[a.AccountID] = map[string]map[string]*domain.Appeal{} } if activeAppealsMap[a.AccountID][a.ResourceID] == nil { activeAppealsMap[a.AccountID][a.ResourceID] = map[string]*domain.Appeal{} @@ -386,14 +386,14 @@ func (s *Service) getExistingAppealsMap() (map[string]map[uint]map[string]*domai return pendingAppealsMap, activeAppealsMap, nil } -func (s *Service) getResourcesMap(ids []uint) (map[uint]*domain.Resource, error) { +func (s *Service) getResourcesMap(ids []string) (map[string]*domain.Resource, error) { filters := map[string]interface{}{"ids": ids} resources, err := s.resourceService.Find(filters) if err != nil { return nil, err } - result := map[uint]*domain.Resource{} + result := map[string]*domain.Resource{} for _, r := range resources { result[r.ID] = r } @@ -683,7 +683,7 @@ func (s *Service) createAccess(a *domain.Appeal) error { return nil } -func (s *Service) checkAppealExtension(a *domain.Appeal, p *domain.Provider, activeAppealsMap map[string]map[uint]map[string]*domain.Appeal) (*domain.Appeal, error) { +func (s *Service) checkAppealExtension(a *domain.Appeal, p *domain.Provider, activeAppealsMap map[string]map[string]map[string]*domain.Appeal) (*domain.Appeal, error) { if activeAppealsMap[a.AccountID] != nil && activeAppealsMap[a.AccountID][a.ResourceID] != nil && activeAppealsMap[a.AccountID][a.ResourceID][a.Role] != nil { @@ -769,7 +769,7 @@ func (s *Service) addCreatorDetails(a *domain.Appeal, p *domain.Policy) error { return nil } -func addResource(a *domain.Appeal, resourcesMap map[uint]*domain.Resource) error { +func addResource(a *domain.Appeal, resourcesMap map[string]*domain.Resource) error { r := resourcesMap[a.ResourceID] if r == nil { return ErrResourceNotFound @@ -791,7 +791,7 @@ func getProvider(a *domain.Appeal, providersMap map[string]map[string]*domain.Pr return providersMap[a.Resource.ProviderType][a.Resource.ProviderURN], nil } -func validateAppeal(a *domain.Appeal, pendingAppealsMap map[string]map[uint]map[string]*domain.Appeal) error { +func validateAppeal(a *domain.Appeal, pendingAppealsMap map[string]map[string]map[string]*domain.Appeal) error { if a.AccountType == domain.DefaultAppealAccountType && a.AccountID != a.CreatedBy { return ErrCannotCreateAppealForOtherUser } diff --git a/core/appeal/service_test.go b/core/appeal/service_test.go index a41e9522c..6c6dc2df3 100644 --- a/core/appeal/service_test.go +++ b/core/appeal/service_test.go @@ -61,7 +61,7 @@ func (s *ServiceTestSuite) TestGetByID() { s.Run("should return error if id is empty/0", func() { expectedError := appeal.ErrAppealIDEmptyParam - actualResult, actualError := s.service.GetByID(0) + actualResult, actualError := s.service.GetByID("") s.Nil(actualResult) s.EqualError(actualError, expectedError.Error()) @@ -71,14 +71,14 @@ func (s *ServiceTestSuite) TestGetByID() { expectedError := errors.New("repository error") s.mockRepository.On("GetByID", mock.Anything).Return(nil, expectedError).Once() - actualResult, actualError := s.service.GetByID(1) + actualResult, actualError := s.service.GetByID("1") s.Nil(actualResult) s.EqualError(actualError, expectedError.Error()) }) s.Run("should return record on success", func() { - expectedID := uint(1) + expectedID := "1" expectedResult := &domain.Appeal{ ID: expectedID, } @@ -108,8 +108,8 @@ func (s *ServiceTestSuite) TestFind() { } expectedResult := []*domain.Appeal{ { - ID: 1, - ResourceID: 1, + ID: "1", + ResourceID: "1", AccountID: "user@email.com", Role: "viewer", }, @@ -178,7 +178,7 @@ func (s *ServiceTestSuite) TestCreate() { s.Run("should return error for invalid appeals", func() { testProvider := &domain.Provider{ - ID: 1, + ID: "1", Type: "provider_type", URN: "provider_urn", Config: &domain.ProviderConfig{ @@ -219,7 +219,7 @@ func (s *ServiceTestSuite) TestCreate() { appeals: []*domain.Appeal{{ CreatedBy: "test-user", AccountID: "test-user-2", - ResourceID: 1, + ResourceID: "1", Role: "test-role", }}, expectedError: appeal.ErrCannotCreateAppealForOtherUser, @@ -229,14 +229,14 @@ func (s *ServiceTestSuite) TestCreate() { existingAppeals: []*domain.Appeal{{ CreatedBy: "test-user", AccountID: "test-user", - ResourceID: 1, + ResourceID: "1", Role: "test-role", Status: domain.AppealStatusPending, }}, appeals: []*domain.Appeal{{ CreatedBy: "test-user", AccountID: "test-user", - ResourceID: 1, + ResourceID: "1", Role: "test-role", }}, expectedError: appeal.ErrAppealDuplicate, @@ -244,12 +244,12 @@ func (s *ServiceTestSuite) TestCreate() { { name: "resource not found", resources: []*domain.Resource{{ - ID: 1, + ID: "1", }}, appeals: []*domain.Appeal{{ CreatedBy: "test-user", AccountID: "test-user", - ResourceID: 2, + ResourceID: "2", Role: "test-role", }}, expectedError: appeal.ErrResourceNotFound, @@ -257,32 +257,32 @@ func (s *ServiceTestSuite) TestCreate() { { name: "provider type not found", resources: []*domain.Resource{{ - ID: 1, + ID: "1", ProviderType: "invalid_provider_type", ProviderURN: "provider_urn", }}, providers: []*domain.Provider{testProvider}, - appeals: []*domain.Appeal{{ResourceID: 1}}, + appeals: []*domain.Appeal{{ResourceID: "1"}}, expectedError: appeal.ErrProviderTypeNotFound, }, { name: "user still have active access", resources: []*domain.Resource{{ - ID: 1, + ID: "1", ProviderType: testProvider.Type, ProviderURN: testProvider.URN, }}, existingAppeals: []*domain.Appeal{{ CreatedBy: "test-user", AccountID: "test-user", - ResourceID: 1, + ResourceID: "1", Role: "test-role", Status: domain.AppealStatusActive, }}, appeals: []*domain.Appeal{{ CreatedBy: "test-user", AccountID: "test-user", - ResourceID: 1, + ResourceID: "1", Role: "test-role", }}, providers: []*domain.Provider{testProvider}, @@ -291,25 +291,25 @@ func (s *ServiceTestSuite) TestCreate() { { name: "invalid extension duration", resources: []*domain.Resource{{ - ID: 1, + ID: "1", ProviderType: testProvider.Type, ProviderURN: testProvider.URN, }}, existingAppeals: []*domain.Appeal{{ CreatedBy: "test-user", AccountID: "test-user", - ResourceID: 1, + ResourceID: "1", Role: "test-role", Status: domain.AppealStatusActive, }}, appeals: []*domain.Appeal{{ CreatedBy: "test-user", AccountID: "test-user", - ResourceID: 1, + ResourceID: "1", Role: "test-role", }}, providers: []*domain.Provider{{ - ID: 1, + ID: "1", Type: testProvider.Type, URN: testProvider.URN, Config: &domain.ProviderConfig{ @@ -323,14 +323,14 @@ func (s *ServiceTestSuite) TestCreate() { { name: "extension not eligible", resources: []*domain.Resource{{ - ID: 1, + ID: "1", ProviderType: testProvider.Type, ProviderURN: testProvider.URN, }}, existingAppeals: []*domain.Appeal{{ CreatedBy: "test-user", AccountID: "test-user", - ResourceID: 1, + ResourceID: "1", Role: "test-role", Status: domain.AppealStatusActive, Options: &domain.AppealOptions{ @@ -340,11 +340,11 @@ func (s *ServiceTestSuite) TestCreate() { appeals: []*domain.Appeal{{ CreatedBy: "test-user", AccountID: "test-user", - ResourceID: 1, + ResourceID: "1", Role: "test-role", }}, providers: []*domain.Provider{{ - ID: 1, + ID: "1", Type: testProvider.Type, URN: testProvider.URN, Config: &domain.ProviderConfig{ @@ -358,18 +358,18 @@ func (s *ServiceTestSuite) TestCreate() { { name: "provider urn not found", resources: []*domain.Resource{{ - ID: 1, + ID: "1", ProviderType: "provider_type", ProviderURN: "invalid_provider_urn", }}, providers: []*domain.Provider{testProvider}, - appeals: []*domain.Appeal{{ResourceID: 1}}, + appeals: []*domain.Appeal{{ResourceID: "1"}}, expectedError: appeal.ErrProviderURNNotFound, }, { name: "duration not found when the appeal config prevents permanent access", resources: []*domain.Resource{{ - ID: 1, + ID: "1", ProviderType: "provider_type", ProviderURN: "provider_urn", Type: "resource_type", @@ -378,14 +378,14 @@ func (s *ServiceTestSuite) TestCreate() { callMockValidateAppeal: true, expectedAppealValidationError: provider.ErrOptionsDurationNotFound, appeals: []*domain.Appeal{{ - ResourceID: 1, + ResourceID: "1", }}, expectedError: appeal.ErrOptionsDurationNotFound, }, { name: "empty duration option", resources: []*domain.Resource{{ - ID: 1, + ID: "1", ProviderType: "provider_type", ProviderURN: "provider_urn", Type: "resource_type", @@ -394,7 +394,7 @@ func (s *ServiceTestSuite) TestCreate() { callMockValidateAppeal: true, expectedAppealValidationError: provider.ErrDurationIsRequired, appeals: []*domain.Appeal{{ - ResourceID: 1, + ResourceID: "1", Options: &domain.AppealOptions{ Duration: "", }, @@ -404,7 +404,7 @@ func (s *ServiceTestSuite) TestCreate() { { name: "invalid role", resources: []*domain.Resource{{ - ID: 1, + ID: "1", ProviderType: "provider_type", ProviderURN: "provider_urn", Type: "resource_type", @@ -413,7 +413,7 @@ func (s *ServiceTestSuite) TestCreate() { callMockValidateAppeal: true, expectedAppealValidationError: provider.ErrInvalidRole, appeals: []*domain.Appeal{{ - ResourceID: 1, + ResourceID: "1", Role: "invalid_role", Options: &domain.AppealOptions{ ExpirationDate: &timeNow, @@ -424,20 +424,20 @@ func (s *ServiceTestSuite) TestCreate() { { name: "resource type not found", resources: []*domain.Resource{{ - ID: 1, + ID: "1", ProviderType: "provider_type", ProviderURN: "provider_urn", Type: "invalid_resource_type", }}, providers: []*domain.Provider{testProvider}, callMockValidateAppeal: true, - appeals: []*domain.Appeal{{ResourceID: 1}}, + appeals: []*domain.Appeal{{ResourceID: "1"}}, expectedError: appeal.ErrResourceTypeNotFound, }, { name: "policy id not found", resources: []*domain.Resource{{ - ID: 1, + ID: "1", ProviderType: "provider_type", ProviderURN: "provider_urn", Type: "resource_type", @@ -445,7 +445,7 @@ func (s *ServiceTestSuite) TestCreate() { providers: []*domain.Provider{testProvider}, callMockValidateAppeal: true, appeals: []*domain.Appeal{{ - ResourceID: 1, + ResourceID: "1", Role: "role_1", Options: &domain.AppealOptions{ ExpirationDate: &timeNow, @@ -456,7 +456,7 @@ func (s *ServiceTestSuite) TestCreate() { { name: "policy version not found", resources: []*domain.Resource{{ - ID: 1, + ID: "1", ProviderType: "provider_type", ProviderURN: "provider_urn", Type: "resource_type", @@ -467,7 +467,7 @@ func (s *ServiceTestSuite) TestCreate() { ID: "policy_id", }}, appeals: []*domain.Appeal{{ - ResourceID: 1, + ResourceID: "1", Role: "role_1", Options: &domain.AppealOptions{ ExpirationDate: &timeNow, @@ -512,7 +512,7 @@ func (s *ServiceTestSuite) TestCreate() { }) accountID := "test@email.com" - resourceIDs := []uint{1, 2} + resourceIDs := []string{"1", "2"} resources := []*domain.Resource{} for _, id := range resourceIDs { resources = append(resources, &domain.Resource{ @@ -527,7 +527,7 @@ func (s *ServiceTestSuite) TestCreate() { } providers := []*domain.Provider{ { - ID: 1, + ID: "1", Type: "provider_type", URN: "provider1", Config: &domain.ProviderConfig{ @@ -554,11 +554,11 @@ func (s *ServiceTestSuite) TestCreate() { } expDate := timeNow.Add(23 * time.Hour) currentActiveAppeal := &domain.Appeal{ - ID: 99, + ID: "99", AccountID: accountID, - ResourceID: 2, + ResourceID: "2", Resource: &domain.Resource{ - ID: 2, + ID: "2", URN: "urn", }, Role: "role_id", @@ -638,8 +638,8 @@ func (s *ServiceTestSuite) TestCreate() { expectedAppealsInsertionParam = append(expectedAppealsInsertionParam, insertionParamExpiredAppeal) expectedResult := []*domain.Appeal{ { - ID: 1, - ResourceID: 1, + ID: "1", + ResourceID: "1", Resource: resources[0], PolicyID: "policy_1", PolicyVersion: 1, @@ -651,7 +651,7 @@ func (s *ServiceTestSuite) TestCreate() { Role: "role_id", Approvals: []*domain.Approval{ { - ID: 1, + ID: "1", Name: "step_1", Index: 0, Status: domain.ApprovalStatusPending, @@ -660,7 +660,7 @@ func (s *ServiceTestSuite) TestCreate() { Approvers: []string{"resource.owner@email.com"}, }, { - ID: 2, + ID: "2", Name: "step_2", Index: 1, Status: domain.ApprovalStatusBlocked, @@ -671,8 +671,8 @@ func (s *ServiceTestSuite) TestCreate() { }, }, { - ID: 2, - ResourceID: 2, + ID: "2", + ResourceID: "2", Resource: resources[1], PolicyID: "policy_1", PolicyVersion: 1, @@ -684,7 +684,7 @@ func (s *ServiceTestSuite) TestCreate() { Role: "role_id", Approvals: []*domain.Approval{ { - ID: 1, + ID: "1", Name: "step_1", Index: 0, Status: domain.ApprovalStatusPending, @@ -693,7 +693,7 @@ func (s *ServiceTestSuite) TestCreate() { Approvers: []string{"resource.owner@email.com"}, }, { - ID: 2, + ID: "2", Name: "step_2", Index: 1, Status: domain.ApprovalStatusBlocked, @@ -741,9 +741,9 @@ func (s *ServiceTestSuite) TestCreate() { { CreatedBy: accountID, AccountID: accountID, - ResourceID: 1, + ResourceID: "1", Resource: &domain.Resource{ - ID: 1, + ID: "1", URN: "urn", }, Role: "role_id", @@ -751,9 +751,9 @@ func (s *ServiceTestSuite) TestCreate() { { CreatedBy: accountID, AccountID: accountID, - ResourceID: 2, + ResourceID: "2", Resource: &domain.Resource{ - ID: 2, + ID: "2", URN: "urn", }, Role: "role_id", @@ -779,23 +779,23 @@ func (s *ServiceTestSuite) TestMakeAction() { Action: "name", }, { - AppealID: 1, + AppealID: "1", Actor: "user@email.com", Action: "name", }, { - AppealID: 1, + AppealID: "1", ApprovalName: "approval_1", Actor: "invalidemail", Action: "name", }, { - AppealID: 1, + AppealID: "1", ApprovalName: "approval_1", Action: "name", }, { - AppealID: 1, + AppealID: "1", ApprovalName: "approval_1", Actor: "user@email.com", }, @@ -810,7 +810,7 @@ func (s *ServiceTestSuite) TestMakeAction() { }) validApprovalActionParam := domain.ApprovalAction{ - AppealID: 1, + AppealID: "1", ApprovalName: "approval_1", Actor: "user@email.com", Action: "approve", @@ -1106,10 +1106,10 @@ func (s *ServiceTestSuite) TestMakeAction() { ID: validApprovalActionParam.AppealID, AccountID: "user@email.com", CreatedBy: creator, - ResourceID: 1, + ResourceID: "1", Role: "test-role", Resource: &domain.Resource{ - ID: 1, + ID: "1", URN: "urn", Name: "test-resource-name", ProviderType: "test-provider", @@ -1131,10 +1131,10 @@ func (s *ServiceTestSuite) TestMakeAction() { ID: validApprovalActionParam.AppealID, AccountID: "user@email.com", CreatedBy: creator, - ResourceID: 1, + ResourceID: "1", Role: "test-role", Resource: &domain.Resource{ - ID: 1, + ID: "1", URN: "urn", Name: "test-resource-name", ProviderType: "test-provider", @@ -1170,7 +1170,7 @@ func (s *ServiceTestSuite) TestMakeAction() { { name: "reject", expectedApprovalAction: domain.ApprovalAction{ - AppealID: 1, + AppealID: "1", ApprovalName: "approval_1", Actor: "user@email.com", Action: domain.AppealActionNameReject, @@ -1180,10 +1180,10 @@ func (s *ServiceTestSuite) TestMakeAction() { ID: validApprovalActionParam.AppealID, AccountID: "user@email.com", CreatedBy: creator, - ResourceID: 1, + ResourceID: "1", Role: "test-role", Resource: &domain.Resource{ - ID: 1, + ID: "1", URN: "urn", Name: "test-resource-name", ProviderType: "test-provider", @@ -1205,10 +1205,10 @@ func (s *ServiceTestSuite) TestMakeAction() { ID: validApprovalActionParam.AppealID, AccountID: "user@email.com", CreatedBy: creator, - ResourceID: 1, + ResourceID: "1", Role: "test-role", Resource: &domain.Resource{ - ID: 1, + ID: "1", URN: "urn", Name: "test-resource-name", ProviderType: "test-provider", @@ -1245,7 +1245,7 @@ func (s *ServiceTestSuite) TestMakeAction() { { name: "reject in the middle step", expectedApprovalAction: domain.ApprovalAction{ - AppealID: 1, + AppealID: "1", ApprovalName: "approval_1", Actor: user, Action: domain.AppealActionNameReject, @@ -1254,10 +1254,10 @@ func (s *ServiceTestSuite) TestMakeAction() { ID: validApprovalActionParam.AppealID, AccountID: "user@email.com", CreatedBy: creator, - ResourceID: 1, + ResourceID: "1", Role: "test-role", Resource: &domain.Resource{ - ID: 1, + ID: "1", URN: "urn", Name: "test-resource-name", ProviderType: "test-provider", @@ -1283,10 +1283,10 @@ func (s *ServiceTestSuite) TestMakeAction() { ID: validApprovalActionParam.AppealID, AccountID: "user@email.com", CreatedBy: creator, - ResourceID: 1, + ResourceID: "1", Role: "test-role", Resource: &domain.Resource{ - ID: 1, + ID: "1", URN: "urn", Name: "test-resource-name", ProviderType: "test-provider", @@ -1336,10 +1336,10 @@ func (s *ServiceTestSuite) TestMakeAction() { ID: validApprovalActionParam.AppealID, AccountID: "user@email.com", CreatedBy: creator, - ResourceID: 1, + ResourceID: "1", Role: "test-role", Resource: &domain.Resource{ - ID: 1, + ID: "1", URN: "urn", Name: "test-resource-name", ProviderType: "test-provider", @@ -1365,10 +1365,10 @@ func (s *ServiceTestSuite) TestMakeAction() { ID: validApprovalActionParam.AppealID, AccountID: "user@email.com", CreatedBy: creator, - ResourceID: 1, + ResourceID: "1", Role: "test-role", Resource: &domain.Resource{ - ID: 1, + ID: "1", URN: "urn", Name: "test-resource-name", ProviderType: "test-provider", @@ -1457,7 +1457,7 @@ func (s *ServiceTestSuite) TestRevoke() { expectedError := errors.New("repository error") s.mockRepository.On("GetByID", mock.Anything).Return(nil, expectedError).Once() - actualResult, actualError := s.service.Revoke(0, "", "") + actualResult, actualError := s.service.Revoke("", "", "") s.Nil(actualResult) s.EqualError(actualError, expectedError.Error()) @@ -1467,21 +1467,21 @@ func (s *ServiceTestSuite) TestRevoke() { s.mockRepository.On("GetByID", mock.Anything).Return(nil, appeal.ErrAppealNotFound).Once() expectedError := appeal.ErrAppealNotFound - actualResult, actualError := s.service.Revoke(0, "", "") + actualResult, actualError := s.service.Revoke("", "", "") s.Nil(actualResult) s.EqualError(actualError, expectedError.Error()) }) - appealID := uint(1) + appealID := "1" actor := "user@email.com" reason := "test-reason" appealDetails := &domain.Appeal{ ID: appealID, - ResourceID: 1, + ResourceID: "1", Resource: &domain.Resource{ - ID: 1, + ID: "1", URN: "urn", }, } diff --git a/core/policy/service_test.go b/core/policy/service_test.go index ea81e2e11..3514b30e7 100644 --- a/core/policy/service_test.go +++ b/core/policy/service_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/go-playground/validator/v10" + "github.com/google/uuid" "github.com/odpf/guardian/core/policy" "github.com/odpf/guardian/core/provider" "github.com/odpf/guardian/core/resource" @@ -325,7 +326,7 @@ func (s *ServiceTestSuite) TestPolicyRequirements() { Appeals: []*domain.AdditionalAppeal{ { Resource: &domain.ResourceIdentifier{ - ID: 1, + ID: "1", }, }, }, @@ -341,7 +342,7 @@ func (s *ServiceTestSuite) TestPolicyRequirements() { Appeals: []*domain.AdditionalAppeal{ { Resource: &domain.ResourceIdentifier{ - ID: 1, + ID: "1", }, }, }, @@ -361,7 +362,7 @@ func (s *ServiceTestSuite) TestPolicyRequirements() { Appeals: []*domain.AdditionalAppeal{ { Resource: &domain.ResourceIdentifier{ - ID: 1, + ID: "1", }, }, }, @@ -427,8 +428,9 @@ func (s *ServiceTestSuite) TestPolicyRequirements() { }) s.Run("valid requirements", func() { + resourceID := uuid.New().String() expectedResource := &domain.Resource{ - ID: 1, + ID: resourceID, ProviderType: "provider-type-test", ProviderURN: "provider-urn-test", } @@ -436,7 +438,7 @@ func (s *ServiceTestSuite) TestPolicyRequirements() { additionalAppeals := []*domain.AdditionalAppeal{ { Resource: &domain.ResourceIdentifier{ - ID: 1, + ID: resourceID, }, Role: "viewer", }, diff --git a/core/provider/service.go b/core/provider/service.go index cd06dc754..734f0e4c0 100644 --- a/core/provider/service.go +++ b/core/provider/service.go @@ -92,7 +92,7 @@ func (s *Service) Find() ([]*domain.Provider, error) { return providers, nil } -func (s *Service) GetByID(id uint) (*domain.Provider, error) { +func (s *Service) GetByID(id string) (*domain.Provider, error) { return s.providerRepository.GetByID(id) } @@ -156,7 +156,7 @@ func (s *Service) FetchResources() error { return s.resourceService.BulkUpsert(resources) } -func (s *Service) GetRoles(id uint, resourceType string) ([]*domain.Role, error) { +func (s *Service) GetRoles(id string, resourceType string) ([]*domain.Role, error) { p, err := s.GetByID(id) if err != nil { return nil, err diff --git a/core/provider/service_test.go b/core/provider/service_test.go index 5e5ae1c54..2567b2192 100644 --- a/core/provider/service_test.go +++ b/core/provider/service_test.go @@ -209,7 +209,7 @@ func (s *ServiceTestSuite) TestUpdate() { for _, tc := range testCases { expectedProvider := &domain.Provider{ - ID: 1, + ID: "1", } expectedError := tc.expectedError s.mockProviderRepository.On("GetByID", expectedProvider.ID).Return(tc.expectedExistingProvider, tc.expectedRepositoryError).Once() @@ -228,7 +228,7 @@ func (s *ServiceTestSuite) TestUpdate() { }{ { updatePayload: &domain.Provider{ - ID: 1, + ID: "1", Config: &domain.ProviderConfig{ Labels: map[string]string{ "foo": "bar", @@ -236,7 +236,7 @@ func (s *ServiceTestSuite) TestUpdate() { }, }, existingProvider: &domain.Provider{ - ID: 1, + ID: "1", Type: mockProviderType, Config: &domain.ProviderConfig{ Appeal: &domain.AppealConfig{ @@ -248,7 +248,7 @@ func (s *ServiceTestSuite) TestUpdate() { }, }, expectedNewProvider: &domain.Provider{ - ID: 1, + ID: "1", Type: mockProviderType, Config: &domain.ProviderConfig{ Appeal: &domain.AppealConfig{ @@ -291,7 +291,7 @@ func (s *ServiceTestSuite) TestFetchResources() { providers := []*domain.Provider{ { - ID: 1, + ID: "1", Type: mockProviderType, Config: &domain.ProviderConfig{}, }, diff --git a/core/resource/service.go b/core/resource/service.go index 3d8723a2c..06ac85e9e 100644 --- a/core/resource/service.go +++ b/core/resource/service.go @@ -21,7 +21,7 @@ func (s *Service) Find(filters map[string]interface{}) ([]*domain.Resource, erro return s.repo.Find(filters) } -func (s *Service) GetOne(id uint) (*domain.Resource, error) { +func (s *Service) GetOne(id string) (*domain.Resource, error) { r, err := s.repo.GetOne(id) if err != nil { return nil, err @@ -61,7 +61,7 @@ func (s *Service) Update(r *domain.Resource) error { func (s *Service) Get(ri *domain.ResourceIdentifier) (*domain.Resource, error) { var resource *domain.Resource - if ri.ID != 0 { + if ri.ID != "" { if r, err := s.GetOne(ri.ID); err != nil { return nil, err } else { diff --git a/core/resource/service_test.go b/core/resource/service_test.go index f2989ccbc..74a028d8f 100644 --- a/core/resource/service_test.go +++ b/core/resource/service_test.go @@ -78,7 +78,7 @@ func (s *ServiceTestSuite) TestUpdate() { for _, tc := range testCases { expectedResource := &domain.Resource{ - ID: 1, + ID: "1", } expectedError := tc.expectedError s.mockRepository.On("GetOne", expectedResource.ID).Return(tc.expectedExistingResource, tc.expectedRepositoryError).Once() @@ -107,16 +107,16 @@ func (s *ServiceTestSuite) TestUpdate() { }{ { resourceUpdatePayload: &domain.Resource{ - ID: 1, + ID: "1", Labels: map[string]string{ "key": "value", }, }, existingResource: &domain.Resource{ - ID: 1, + ID: "1", }, expectedUpdatedValues: &domain.Resource{ - ID: 1, + ID: "1", Labels: map[string]string{ "key": "value", }, @@ -124,16 +124,16 @@ func (s *ServiceTestSuite) TestUpdate() { }, { resourceUpdatePayload: &domain.Resource{ - ID: 2, + ID: "2", Details: map[string]interface{}{ "key": "value", }, }, existingResource: &domain.Resource{ - ID: 2, + ID: "2", }, expectedUpdatedValues: &domain.Resource{ - ID: 2, + ID: "2", Details: map[string]interface{}{ "key": "value", }, @@ -141,14 +141,14 @@ func (s *ServiceTestSuite) TestUpdate() { }, { resourceUpdatePayload: &domain.Resource{ - ID: 2, + ID: "2", Type: "test", }, existingResource: &domain.Resource{ - ID: 2, + ID: "2", }, expectedUpdatedValues: &domain.Resource{ - ID: 2, + ID: "2", }, }, } diff --git a/domain/appeal.go b/domain/appeal.go index 59cf20b46..f19212e1c 100644 --- a/domain/appeal.go +++ b/domain/appeal.go @@ -27,8 +27,8 @@ type AppealOptions struct { // Appeal struct type Appeal struct { - ID uint `json:"id" yaml:"id"` - ResourceID uint `json:"resource_id" yaml:"resource_id"` + ID string `json:"id" yaml:"id"` + ResourceID string `json:"resource_id" yaml:"resource_id"` PolicyID string `json:"policy_id" yaml:"policy_id"` PolicyVersion uint `json:"policy_version" yaml:"policy_version"` Status string `json:"status" yaml:"status"` @@ -89,7 +89,7 @@ func (a *Appeal) SetDefaults() { } type ApprovalAction struct { - AppealID uint `validate:"required"` + AppealID string `validate:"required"` ApprovalName string `validate:"required"` Actor string `validate:"email"` Action string `validate:"required,oneof=approve reject"` @@ -98,7 +98,7 @@ type ApprovalAction struct { type ListAppealsFilter struct { AccountID string `mapstructure:"account_id" validate:"omitempty,required"` - ResourceID uint `mapstructure:"resource_id" validate:"omitempty,required"` + ResourceID string `mapstructure:"resource_id" validate:"omitempty,required"` Role string `mapstructure:"role" validate:"omitempty,required"` Statuses []string `mapstructure:"statuses" validate:"omitempty,min=1"` ExpirationDateLessThan time.Time `mapstructure:"expiration_date_lt" validate:"omitempty,required"` @@ -114,8 +114,8 @@ type ListAppealsFilter struct { type AppealService interface { Create([]*Appeal) error Find(*ListAppealsFilter) ([]*Appeal, error) - GetByID(uint) (*Appeal, error) + GetByID(id string) (*Appeal, error) MakeAction(ApprovalAction) (*Appeal, error) - Cancel(uint) (*Appeal, error) - Revoke(id uint, actor, reason string) (*Appeal, error) + Cancel(id string) (*Appeal, error) + Revoke(id string, actor, reason string) (*Appeal, error) } diff --git a/domain/approval.go b/domain/approval.go index 6ff69cb6f..c35cccf7f 100644 --- a/domain/approval.go +++ b/domain/approval.go @@ -11,10 +11,10 @@ const ( ) type Approval struct { - ID uint `json:"id" yaml:"id"` + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Index int `json:"-" yaml:"-"` - AppealID uint `json:"appeal_id" yaml:"appeal_id"` + AppealID string `json:"appeal_id" yaml:"appeal_id"` Status string `json:"status" yaml:"status"` Actor *string `json:"actor" yaml:"actor"` Reason string `json:"reason,omitempty" yaml:"reason,omitempty"` diff --git a/domain/approver.go b/domain/approver.go index 3ffaf8d29..66a4ffcb0 100644 --- a/domain/approver.go +++ b/domain/approver.go @@ -3,9 +3,9 @@ package domain import "time" type Approver struct { - ID uint `json:"id" yaml:"id"` - ApprovalID uint `json:"approval_id" yaml:"approval_id"` - AppealID uint `json:"appeal_id" yaml:"appeal_id"` + ID string `json:"id" yaml:"id"` + ApprovalID string `json:"approval_id" yaml:"approval_id"` + AppealID string `json:"appeal_id" yaml:"appeal_id"` Email string `json:"email" yaml:"email"` CreatedAt time.Time `json:"created_at,omitempty" yaml:"created_at,omitempty"` diff --git a/domain/policy.go b/domain/policy.go index 0c5533a91..16fbdd60f 100644 --- a/domain/policy.go +++ b/domain/policy.go @@ -162,7 +162,7 @@ type ResourceIdentifier struct { ProviderURN string `json:"provider_urn" yaml:"provider_urn" validate:"required_with=ProviderType Type URN"` Type string `json:"type" yaml:"type" validate:"required_with=ProviderType ProviderURN URN"` URN string `json:"urn" yaml:"urn" validate:"required_with=ProviderType ProviderURN Type"` - ID uint `json:"id" yaml:"id" validate:"required_without_all=ProviderType ProviderURN Type URN"` + ID string `json:"id" yaml:"id" validate:"required_without_all=ProviderType ProviderURN Type URN"` } type AdditionalAppeal struct { diff --git a/domain/provider.go b/domain/provider.go index 6824fe9cb..dda206d0e 100644 --- a/domain/provider.go +++ b/domain/provider.go @@ -57,7 +57,7 @@ type ProviderConfig struct { // Provider domain structure type Provider struct { - ID uint `json:"id" yaml:"id"` + ID string `json:"id" yaml:"id"` Type string `json:"type" yaml:"type"` URN string `json:"urn" yaml:"urn"` Config *ProviderConfig `json:"config" yaml:"config"` @@ -69,11 +69,11 @@ type Provider struct { type ProviderService interface { Create(*Provider) error Find() ([]*Provider, error) - GetByID(uint) (*Provider, error) + GetByID(id string) (*Provider, error) GetOne(pType, urn string) (*Provider, error) Update(*Provider) error FetchResources() error - GetRoles(id uint, resourceType string) ([]*Role, error) + GetRoles(id string, resourceType string) ([]*Role, error) ValidateAppeal(*Appeal, *Provider) error GrantAccess(*Appeal) error RevokeAccess(*Appeal) error diff --git a/domain/resource.go b/domain/resource.go index 7972f7d2a..0d5130b1f 100644 --- a/domain/resource.go +++ b/domain/resource.go @@ -4,7 +4,7 @@ import "time" // Resource struct type Resource struct { - ID uint `json:"id" yaml:"id"` + ID string `json:"id" yaml:"id"` ProviderType string `json:"provider_type" yaml:"provider_type"` ProviderURN string `json:"provider_urn" yaml:"provider_urn"` Type string `json:"type" yaml:"type"` @@ -20,7 +20,7 @@ type Resource struct { // ResourceService interface type ResourceService interface { Find(filters map[string]interface{}) ([]*Resource, error) - GetOne(uint) (*Resource, error) + GetOne(id string) (*Resource, error) Get(*ResourceIdentifier) (*Resource, error) BulkUpsert([]*Resource) error Update(*Resource) error diff --git a/go.mod b/go.mod index 819a505ff..69a046b00 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/MakeNowJust/heredoc v1.0.0 github.com/antonmedv/expr v1.9.0 github.com/go-playground/validator/v10 v10.4.1 + github.com/google/uuid v1.1.2 github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.6.0 github.com/imdario/mergo v0.3.11 diff --git a/go.sum b/go.sum index 72c8e27d7..b2512a6d7 100644 --- a/go.sum +++ b/go.sum @@ -217,6 +217,7 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM= diff --git a/mocks/AppealRepository.go b/mocks/AppealRepository.go index b9eed7b58..135ae14cc 100644 --- a/mocks/AppealRepository.go +++ b/mocks/AppealRepository.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v2.9.4. DO NOT EDIT. package mocks @@ -49,13 +49,13 @@ func (_m *AppealRepository) Find(_a0 *domain.ListAppealsFilter) ([]*domain.Appea return r0, r1 } -// GetByID provides a mock function with given fields: _a0 -func (_m *AppealRepository) GetByID(_a0 uint) (*domain.Appeal, error) { - ret := _m.Called(_a0) +// GetByID provides a mock function with given fields: id +func (_m *AppealRepository) GetByID(id string) (*domain.Appeal, error) { + ret := _m.Called(id) var r0 *domain.Appeal - if rf, ok := ret.Get(0).(func(uint) *domain.Appeal); ok { - r0 = rf(_a0) + if rf, ok := ret.Get(0).(func(string) *domain.Appeal); ok { + r0 = rf(id) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*domain.Appeal) @@ -63,8 +63,8 @@ func (_m *AppealRepository) GetByID(_a0 uint) (*domain.Appeal, error) { } var r1 error - if rf, ok := ret.Get(1).(func(uint) error); ok { - r1 = rf(_a0) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(id) } else { r1 = ret.Error(1) } diff --git a/mocks/AppealService.go b/mocks/AppealService.go index 63a3997ef..9da1ba0a8 100644 --- a/mocks/AppealService.go +++ b/mocks/AppealService.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v2.9.4. DO NOT EDIT. package mocks @@ -12,13 +12,13 @@ type AppealService struct { mock.Mock } -// Cancel provides a mock function with given fields: _a0 -func (_m *AppealService) Cancel(_a0 uint) (*domain.Appeal, error) { - ret := _m.Called(_a0) +// Cancel provides a mock function with given fields: id +func (_m *AppealService) Cancel(id string) (*domain.Appeal, error) { + ret := _m.Called(id) var r0 *domain.Appeal - if rf, ok := ret.Get(0).(func(uint) *domain.Appeal); ok { - r0 = rf(_a0) + if rf, ok := ret.Get(0).(func(string) *domain.Appeal); ok { + r0 = rf(id) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*domain.Appeal) @@ -26,8 +26,8 @@ func (_m *AppealService) Cancel(_a0 uint) (*domain.Appeal, error) { } var r1 error - if rf, ok := ret.Get(1).(func(uint) error); ok { - r1 = rf(_a0) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(id) } else { r1 = ret.Error(1) } @@ -72,13 +72,13 @@ func (_m *AppealService) Find(_a0 *domain.ListAppealsFilter) ([]*domain.Appeal, return r0, r1 } -// GetByID provides a mock function with given fields: _a0 -func (_m *AppealService) GetByID(_a0 uint) (*domain.Appeal, error) { - ret := _m.Called(_a0) +// GetByID provides a mock function with given fields: id +func (_m *AppealService) GetByID(id string) (*domain.Appeal, error) { + ret := _m.Called(id) var r0 *domain.Appeal - if rf, ok := ret.Get(0).(func(uint) *domain.Appeal); ok { - r0 = rf(_a0) + if rf, ok := ret.Get(0).(func(string) *domain.Appeal); ok { + r0 = rf(id) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*domain.Appeal) @@ -86,8 +86,8 @@ func (_m *AppealService) GetByID(_a0 uint) (*domain.Appeal, error) { } var r1 error - if rf, ok := ret.Get(1).(func(uint) error); ok { - r1 = rf(_a0) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(id) } else { r1 = ret.Error(1) } @@ -119,11 +119,11 @@ func (_m *AppealService) MakeAction(_a0 domain.ApprovalAction) (*domain.Appeal, } // Revoke provides a mock function with given fields: id, actor, reason -func (_m *AppealService) Revoke(id uint, actor string, reason string) (*domain.Appeal, error) { +func (_m *AppealService) Revoke(id string, actor string, reason string) (*domain.Appeal, error) { ret := _m.Called(id, actor, reason) var r0 *domain.Appeal - if rf, ok := ret.Get(0).(func(uint, string, string) *domain.Appeal); ok { + if rf, ok := ret.Get(0).(func(string, string, string) *domain.Appeal); ok { r0 = rf(id, actor, reason) } else { if ret.Get(0) != nil { @@ -132,7 +132,7 @@ func (_m *AppealService) Revoke(id uint, actor string, reason string) (*domain.A } var r1 error - if rf, ok := ret.Get(1).(func(uint, string, string) error); ok { + if rf, ok := ret.Get(1).(func(string, string, string) error); ok { r1 = rf(id, actor, reason) } else { r1 = ret.Error(1) diff --git a/mocks/ApprovalRepository.go b/mocks/ApprovalRepository.go index 15be2ffa8..1b498ccfb 100644 --- a/mocks/ApprovalRepository.go +++ b/mocks/ApprovalRepository.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v2.9.4. DO NOT EDIT. package mocks diff --git a/mocks/ApprovalService.go b/mocks/ApprovalService.go index c747c7ada..4f9a7ec83 100644 --- a/mocks/ApprovalService.go +++ b/mocks/ApprovalService.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v2.9.4. DO NOT EDIT. package mocks diff --git a/mocks/PolicyRepository.go b/mocks/PolicyRepository.go index d19fe9da9..485657b9e 100644 --- a/mocks/PolicyRepository.go +++ b/mocks/PolicyRepository.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v2.9.4. DO NOT EDIT. package mocks diff --git a/mocks/PolicyService.go b/mocks/PolicyService.go index b6db325a2..e9aa4cdb1 100644 --- a/mocks/PolicyService.go +++ b/mocks/PolicyService.go @@ -1,4 +1,4 @@ -// Code generated by mockery 2.9.0. DO NOT EDIT. +// Code generated by mockery v2.9.4. DO NOT EDIT. package mocks diff --git a/mocks/ProviderRepository.go b/mocks/ProviderRepository.go index c487d7d63..dcda95823 100644 --- a/mocks/ProviderRepository.go +++ b/mocks/ProviderRepository.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v2.9.4. DO NOT EDIT. package mocks @@ -26,13 +26,13 @@ func (_m *ProviderRepository) Create(_a0 *domain.Provider) error { return r0 } -// Delete provides a mock function with given fields: _a0 -func (_m *ProviderRepository) Delete(_a0 uint) error { - ret := _m.Called(_a0) +// Delete provides a mock function with given fields: id +func (_m *ProviderRepository) Delete(id string) error { + ret := _m.Called(id) var r0 error - if rf, ok := ret.Get(0).(func(uint) error); ok { - r0 = rf(_a0) + if rf, ok := ret.Get(0).(func(string) error); ok { + r0 = rf(id) } else { r0 = ret.Error(0) } @@ -63,13 +63,13 @@ func (_m *ProviderRepository) Find() ([]*domain.Provider, error) { return r0, r1 } -// GetByID provides a mock function with given fields: _a0 -func (_m *ProviderRepository) GetByID(_a0 uint) (*domain.Provider, error) { - ret := _m.Called(_a0) +// GetByID provides a mock function with given fields: id +func (_m *ProviderRepository) GetByID(id string) (*domain.Provider, error) { + ret := _m.Called(id) var r0 *domain.Provider - if rf, ok := ret.Get(0).(func(uint) *domain.Provider); ok { - r0 = rf(_a0) + if rf, ok := ret.Get(0).(func(string) *domain.Provider); ok { + r0 = rf(id) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*domain.Provider) @@ -77,8 +77,8 @@ func (_m *ProviderRepository) GetByID(_a0 uint) (*domain.Provider, error) { } var r1 error - if rf, ok := ret.Get(1).(func(uint) error); ok { - r1 = rf(_a0) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(id) } else { r1 = ret.Error(1) } diff --git a/mocks/ProviderService.go b/mocks/ProviderService.go index 1d79de636..2ed6ab119 100644 --- a/mocks/ProviderService.go +++ b/mocks/ProviderService.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v2.9.4. DO NOT EDIT. package mocks @@ -63,13 +63,13 @@ func (_m *ProviderService) Find() ([]*domain.Provider, error) { return r0, r1 } -// GetByID provides a mock function with given fields: _a0 -func (_m *ProviderService) GetByID(_a0 uint) (*domain.Provider, error) { - ret := _m.Called(_a0) +// GetByID provides a mock function with given fields: id +func (_m *ProviderService) GetByID(id string) (*domain.Provider, error) { + ret := _m.Called(id) var r0 *domain.Provider - if rf, ok := ret.Get(0).(func(uint) *domain.Provider); ok { - r0 = rf(_a0) + if rf, ok := ret.Get(0).(func(string) *domain.Provider); ok { + r0 = rf(id) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*domain.Provider) @@ -77,8 +77,8 @@ func (_m *ProviderService) GetByID(_a0 uint) (*domain.Provider, error) { } var r1 error - if rf, ok := ret.Get(1).(func(uint) error); ok { - r1 = rf(_a0) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(id) } else { r1 = ret.Error(1) } @@ -110,11 +110,11 @@ func (_m *ProviderService) GetOne(pType string, urn string) (*domain.Provider, e } // GetRoles provides a mock function with given fields: id, resourceType -func (_m *ProviderService) GetRoles(id uint, resourceType string) ([]*domain.Role, error) { +func (_m *ProviderService) GetRoles(id string, resourceType string) ([]*domain.Role, error) { ret := _m.Called(id, resourceType) var r0 []*domain.Role - if rf, ok := ret.Get(0).(func(uint, string) []*domain.Role); ok { + if rf, ok := ret.Get(0).(func(string, string) []*domain.Role); ok { r0 = rf(id, resourceType) } else { if ret.Get(0) != nil { @@ -123,7 +123,7 @@ func (_m *ProviderService) GetRoles(id uint, resourceType string) ([]*domain.Rol } var r1 error - if rf, ok := ret.Get(1).(func(uint, string) error); ok { + if rf, ok := ret.Get(1).(func(string, string) error); ok { r1 = rf(id, resourceType) } else { r1 = ret.Error(1) diff --git a/mocks/ResourceRepository.go b/mocks/ResourceRepository.go index d2c1dd31e..11a1d2b44 100644 --- a/mocks/ResourceRepository.go +++ b/mocks/ResourceRepository.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v2.9.4. DO NOT EDIT. package mocks @@ -49,13 +49,13 @@ func (_m *ResourceRepository) Find(filters map[string]interface{}) ([]*domain.Re return r0, r1 } -// GetOne provides a mock function with given fields: _a0 -func (_m *ResourceRepository) GetOne(_a0 uint) (*domain.Resource, error) { - ret := _m.Called(_a0) +// GetOne provides a mock function with given fields: id +func (_m *ResourceRepository) GetOne(id string) (*domain.Resource, error) { + ret := _m.Called(id) var r0 *domain.Resource - if rf, ok := ret.Get(0).(func(uint) *domain.Resource); ok { - r0 = rf(_a0) + if rf, ok := ret.Get(0).(func(string) *domain.Resource); ok { + r0 = rf(id) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*domain.Resource) @@ -63,8 +63,8 @@ func (_m *ResourceRepository) GetOne(_a0 uint) (*domain.Resource, error) { } var r1 error - if rf, ok := ret.Get(1).(func(uint) error); ok { - r1 = rf(_a0) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(id) } else { r1 = ret.Error(1) } diff --git a/mocks/ResourceService.go b/mocks/ResourceService.go index 0a0665f32..352dac45a 100644 --- a/mocks/ResourceService.go +++ b/mocks/ResourceService.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v2.9.4. DO NOT EDIT. package mocks @@ -72,13 +72,13 @@ func (_m *ResourceService) Get(_a0 *domain.ResourceIdentifier) (*domain.Resource return r0, r1 } -// GetOne provides a mock function with given fields: _a0 -func (_m *ResourceService) GetOne(_a0 uint) (*domain.Resource, error) { - ret := _m.Called(_a0) +// GetOne provides a mock function with given fields: id +func (_m *ResourceService) GetOne(id string) (*domain.Resource, error) { + ret := _m.Called(id) var r0 *domain.Resource - if rf, ok := ret.Get(0).(func(uint) *domain.Resource); ok { - r0 = rf(_a0) + if rf, ok := ret.Get(0).(func(string) *domain.Resource); ok { + r0 = rf(id) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*domain.Resource) @@ -86,8 +86,8 @@ func (_m *ResourceService) GetOne(_a0 uint) (*domain.Resource, error) { } var r1 error - if rf, ok := ret.Get(1).(func(uint) error); ok { - r1 = rf(_a0) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(id) } else { r1 = ret.Error(1) } diff --git a/plugins/providers/gcloudiam/provider_test.go b/plugins/providers/gcloudiam/provider_test.go index 1cd68e294..44a63dcff 100644 --- a/plugins/providers/gcloudiam/provider_test.go +++ b/plugins/providers/gcloudiam/provider_test.go @@ -168,8 +168,8 @@ func TestGrantAccess(t *testing.T) { Role: expectedRole, AccountType: expectedAccountType, AccountID: expectedAccountID, - ResourceID: 999, - ID: 999, + ResourceID: "999", + ID: "999", } actualError := p.GrantAccess(pc, a) @@ -271,8 +271,8 @@ func TestRevokeAccess(t *testing.T) { Role: expectedRole, AccountType: expectedAccountType, AccountID: expectedAccountID, - ResourceID: 999, - ID: 999, + ResourceID: "999", + ID: "999", } actualError := p.RevokeAccess(pc, a) diff --git a/plugins/providers/grafana/provider_test.go b/plugins/providers/grafana/provider_test.go index 014a9481e..434243fa9 100644 --- a/plugins/providers/grafana/provider_test.go +++ b/plugins/providers/grafana/provider_test.go @@ -419,8 +419,8 @@ func TestGrantAccess(t *testing.T) { }, Role: "viewer", AccountID: expectedUser, - ResourceID: 999, - ID: 999, + ResourceID: "999", + ID: "999", } actualError := p.GrantAccess(pc, a) diff --git a/plugins/providers/metabase/provider_test.go b/plugins/providers/metabase/provider_test.go index c5bbbc062..84941ecd6 100644 --- a/plugins/providers/metabase/provider_test.go +++ b/plugins/providers/metabase/provider_test.go @@ -442,8 +442,8 @@ func TestGrantAccess(t *testing.T) { }, Role: "viewer", AccountID: expectedUser, - ResourceID: 999, - ID: 999, + ResourceID: "999", + ID: "999", } actualError := p.GrantAccess(pc, a) @@ -541,8 +541,8 @@ func TestGrantAccess(t *testing.T) { }, Role: "viewer", AccountID: expectedUser, - ResourceID: 999, - ID: 999, + ResourceID: "999", + ID: "999", } actualError := p.GrantAccess(pc, a) diff --git a/plugins/providers/tableau/provider_test.go b/plugins/providers/tableau/provider_test.go index a41faf142..c5ff64f08 100644 --- a/plugins/providers/tableau/provider_test.go +++ b/plugins/providers/tableau/provider_test.go @@ -641,8 +641,8 @@ func TestGrantAccess(t *testing.T) { }, Role: "viewer", AccountID: expectedUser, - ResourceID: 999, - ID: 999, + ResourceID: "999", + ID: "999", } actualError := p.GrantAccess(pc, a) @@ -749,8 +749,8 @@ func TestGrantAccess(t *testing.T) { }, Role: "viewer", AccountID: expectedUser, - ResourceID: 999, - ID: 999, + ResourceID: "999", + ID: "999", } actualError := p.GrantAccess(pc, a) @@ -857,8 +857,8 @@ func TestGrantAccess(t *testing.T) { }, Role: "viewer", AccountID: expectedUser, - ResourceID: 99, - ID: 99, + ResourceID: "99", + ID: "99", } actualError := p.GrantAccess(pc, a) @@ -965,8 +965,8 @@ func TestGrantAccess(t *testing.T) { }, Role: "viewer", AccountID: expectedUser, - ResourceID: 99, - ID: 99, + ResourceID: "99", + ID: "99", } actualError := p.GrantAccess(pc, a) @@ -1073,8 +1073,8 @@ func TestGrantAccess(t *testing.T) { }, Role: "viewer", AccountID: expectedUser, - ResourceID: 99, - ID: 99, + ResourceID: "99", + ID: "99", } actualError := p.GrantAccess(pc, a) diff --git a/store/model/appeal.go b/store/model/appeal.go index 12cbf8c53..f795062fd 100644 --- a/store/model/appeal.go +++ b/store/model/appeal.go @@ -2,8 +2,10 @@ package model import ( "encoding/json" + "fmt" "time" + "github.com/google/uuid" "github.com/odpf/guardian/domain" "gorm.io/datatypes" "gorm.io/gorm" @@ -11,8 +13,8 @@ import ( // Appeal database model type Appeal struct { - ID uint `gorm:"primaryKey"` - ResourceID uint + ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` + ResourceID string PolicyID string PolicyVersion uint Status string @@ -79,7 +81,15 @@ func (m *Appeal) FromDomain(a *domain.Appeal) error { m.Resource = r } - m.ID = a.ID + var id uuid.UUID + if a.ID != "" { + uuid, err := uuid.Parse(a.ID) + if err != nil { + return fmt.Errorf("parsing uuid: %w", err) + } + id = uuid + } + m.ID = id m.ResourceID = a.ResourceID m.PolicyID = a.PolicyID m.PolicyVersion = a.PolicyVersion @@ -150,7 +160,7 @@ func (m *Appeal) ToDomain() (*domain.Appeal, error) { } return &domain.Appeal{ - ID: m.ID, + ID: m.ID.String(), ResourceID: m.ResourceID, PolicyID: m.PolicyID, PolicyVersion: m.PolicyVersion, diff --git a/store/model/approval.go b/store/model/approval.go index f72d9056d..41d680413 100644 --- a/store/model/approval.go +++ b/store/model/approval.go @@ -1,18 +1,20 @@ package model import ( + "fmt" "time" + "github.com/google/uuid" "github.com/odpf/guardian/domain" "gorm.io/gorm" ) // Approval database model type Approval struct { - ID uint `gorm:"primaryKey"` - Name string `gorm:"index"` + ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` + Name string `gorm:"index"` Index int - AppealID uint + AppealID string Status string Actor *string Reason string @@ -48,7 +50,15 @@ func (m *Approval) FromDomain(a *domain.Approval) error { m.Appeal = appealModel } - m.ID = a.ID + var id uuid.UUID + if a.ID != "" { + uuid, err := uuid.Parse(a.ID) + if err != nil { + return fmt.Errorf("parsing uuid: %w", err) + } + id = uuid + } + m.ID = id m.Name = a.Name m.Index = a.Index m.AppealID = a.AppealID @@ -87,7 +97,7 @@ func (m *Approval) ToDomain() (*domain.Approval, error) { } return &domain.Approval{ - ID: m.ID, + ID: m.ID.String(), Name: m.Name, Index: m.Index, AppealID: m.AppealID, diff --git a/store/model/approver.go b/store/model/approver.go index c6283db5a..8def9f98a 100644 --- a/store/model/approver.go +++ b/store/model/approver.go @@ -1,17 +1,19 @@ package model import ( + "fmt" "time" + "github.com/google/uuid" "github.com/odpf/guardian/domain" "gorm.io/gorm" ) // Approver database model type Approver struct { - ID uint `gorm:"autoIncrement;uniqueIndex"` - ApprovalID uint - AppealID uint `gorm:"index"` + ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` + ApprovalID string + AppealID string `gorm:"index"` Email string `gorm:"index"` CreatedAt time.Time `gorm:"autoCreateTime"` @@ -21,7 +23,15 @@ type Approver struct { // FromDomain transforms *domain.Approver values into the model func (m *Approver) FromDomain(a *domain.Approver) error { - m.ID = a.ID + var id uuid.UUID + if a.ID != "" { + uuid, err := uuid.Parse(a.ID) + if err != nil { + return fmt.Errorf("parsing uuid: %w", err) + } + id = uuid + } + m.ID = id m.ApprovalID = a.ApprovalID m.AppealID = a.AppealID m.Email = a.Email @@ -34,7 +44,7 @@ func (m *Approver) FromDomain(a *domain.Approver) error { // ToDomain transforms model into *domain.Approver func (m *Approver) ToDomain() (*domain.Approver, error) { return &domain.Approver{ - ID: m.ID, + ID: m.ID.String(), ApprovalID: m.ApprovalID, AppealID: m.AppealID, Email: m.Email, diff --git a/store/model/provider.go b/store/model/provider.go index 37f4f89ed..35c031c2d 100644 --- a/store/model/provider.go +++ b/store/model/provider.go @@ -2,8 +2,10 @@ package model import ( "encoding/json" + "fmt" "time" + "github.com/google/uuid" "github.com/odpf/guardian/domain" "gorm.io/datatypes" "gorm.io/gorm" @@ -11,9 +13,9 @@ import ( // Provider is the database model for provider type Provider struct { - ID uint `gorm:"autoIncrement;uniqueIndex"` - Type string `gorm:"primaryKey"` - URN string `gorm:"primaryKey"` + ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` + Type string `gorm:"uniqueIndex:provider_index"` + URN string `gorm:"uniqueIndex:provider_index"` Config datatypes.JSON CreatedAt time.Time `gorm:"autoCreateTime"` UpdatedAt time.Time `gorm:"autoUpdateTime"` @@ -32,7 +34,15 @@ func (m *Provider) FromDomain(p *domain.Provider) error { return err } - m.ID = p.ID + var id uuid.UUID + if p.ID != "" { + uuid, err := uuid.Parse(p.ID) + if err != nil { + return fmt.Errorf("parsing uuid: %w", err) + } + id = uuid + } + m.ID = id m.Type = p.Type m.URN = p.URN m.Config = datatypes.JSON(config) @@ -50,7 +60,7 @@ func (m *Provider) ToDomain() (*domain.Provider, error) { } return &domain.Provider{ - ID: m.ID, + ID: m.ID.String(), Type: m.Type, URN: m.URN, Config: config, diff --git a/store/model/resource.go b/store/model/resource.go index a642f73ba..bb90898b6 100644 --- a/store/model/resource.go +++ b/store/model/resource.go @@ -2,8 +2,10 @@ package model import ( "encoding/json" + "fmt" "time" + "github.com/google/uuid" "github.com/odpf/guardian/domain" "gorm.io/datatypes" "gorm.io/gorm" @@ -11,11 +13,11 @@ import ( // Resource is the database model for resource type Resource struct { - ID uint `gorm:"autoIncrement;uniqueIndex"` - ProviderType string `gorm:"primaryKey"` - ProviderURN string `gorm:"primaryKey"` - Type string `gorm:"primaryKey"` - URN string `gorm:"primaryKey"` + ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` + ProviderType string `gorm:"uniqueIndex:resource_index"` + ProviderURN string `gorm:"uniqueIndex:resource_index"` + Type string `gorm:"uniqueIndex:resource_index"` + URN string `gorm:"uniqueIndex:resource_index"` Name string Details datatypes.JSON Labels datatypes.JSON @@ -45,7 +47,15 @@ func (m *Resource) FromDomain(r *domain.Resource) error { return err } - m.ID = r.ID + var id uuid.UUID + if r.ID != "" { + uuid, err := uuid.Parse(r.ID) + if err != nil { + return fmt.Errorf("parsing uuid: %w", err) + } + id = uuid + } + m.ID = id m.ProviderType = r.ProviderType m.ProviderURN = r.ProviderURN m.Type = r.Type @@ -72,7 +82,7 @@ func (m *Resource) ToDomain() (*domain.Resource, error) { } return &domain.Resource{ - ID: m.ID, + ID: m.ID.String(), ProviderType: m.ProviderType, ProviderURN: m.ProviderURN, Type: m.Type, diff --git a/store/postgres/appeal_repository.go b/store/postgres/appeal_repository.go index 6246debab..a8e50dad5 100644 --- a/store/postgres/appeal_repository.go +++ b/store/postgres/appeal_repository.go @@ -2,6 +2,7 @@ package postgres import ( "errors" + "fmt" "github.com/odpf/guardian/core/appeal" "github.com/odpf/guardian/domain" @@ -32,7 +33,7 @@ func NewAppealRepository(db *gorm.DB) *AppealRepository { } // GetByID returns appeal record by id along with the approvals and the approvers -func (r *AppealRepository) GetByID(id uint) (*domain.Appeal, error) { +func (r *AppealRepository) GetByID(id string) (*domain.Appeal, error) { m := new(model.Appeal) if err := r.db. Preload("Approvals", func(db *gorm.DB) *gorm.DB { @@ -40,7 +41,7 @@ func (r *AppealRepository) GetByID(id uint) (*domain.Appeal, error) { }). Preload("Approvals.Approvers"). Preload("Resource"). - First(&m, id). + First(&m, "id = ?", id). Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return nil, appeal.ErrAppealNotFound @@ -50,7 +51,7 @@ func (r *AppealRepository) GetByID(id uint) (*domain.Appeal, error) { a, err := m.ToDomain() if err != nil { - return nil, err + return nil, fmt.Errorf("parsing appeal: %w", err) } return a, nil @@ -68,7 +69,7 @@ func (r *AppealRepository) Find(filters *domain.ListAppealsFilter) ([]*domain.Ap if filters.Statuses != nil { db = db.Where(`"status" IN ?`, filters.Statuses) } - if filters.ResourceID != 0 { + if filters.ResourceID != "" { db = db.Where(`"resource_id" = ?`, filters.ResourceID) } if filters.Role != "" { @@ -109,7 +110,7 @@ func (r *AppealRepository) Find(filters *domain.ListAppealsFilter) ([]*domain.Ap for _, m := range models { a, err := m.ToDomain() if err != nil { - return nil, err + return nil, fmt.Errorf("parsing appeal: %w", err) } records = append(records, a) @@ -140,7 +141,7 @@ func (r *AppealRepository) BulkUpsert(appeals []*domain.Appeal) error { for i, m := range models { newAppeal, err := m.ToDomain() if err != nil { - return err + return fmt.Errorf("parsing appeal: %w", err) } *appeals[i] = *newAppeal @@ -164,7 +165,7 @@ func (r *AppealRepository) Update(a *domain.Appeal) error { newRecord, err := m.ToDomain() if err != nil { - return err + return fmt.Errorf("parsing appeal: %w", err) } *a = *newRecord diff --git a/store/postgres/appeal_repository_test.go b/store/postgres/appeal_repository_test.go index 64d0cc1ee..9d5cd5a5f 100644 --- a/store/postgres/appeal_repository_test.go +++ b/store/postgres/appeal_repository_test.go @@ -11,6 +11,7 @@ import ( "time" "github.com/DATA-DOG/go-sqlmock" + "github.com/google/uuid" "github.com/odpf/guardian/core/appeal" "github.com/odpf/guardian/domain" "github.com/odpf/guardian/mocks" @@ -91,10 +92,10 @@ func (s *AppealRepositoryTestSuite) TearDownTest() { } func (s *AppealRepositoryTestSuite) TestGetByID() { - expectedQuery := regexp.QuoteMeta(`SELECT * FROM "appeals" WHERE "appeals"."id" = $1 AND "appeals"."deleted_at" IS NULL ORDER BY "appeals"."id" LIMIT 1`) + expectedQuery := regexp.QuoteMeta(`SELECT * FROM "appeals" WHERE id = $1 AND "appeals"."deleted_at" IS NULL ORDER BY "appeals"."id" LIMIT 1`) s.Run("should return error if got any from db", func() { - expectedID := uint(1) + expectedID := uuid.New().String() expectedError := errors.New("db error") s.dbmock. ExpectQuery(expectedQuery). @@ -108,7 +109,7 @@ func (s *AppealRepositoryTestSuite) TestGetByID() { }) s.Run("should return error if record not found", func() { - expectedID := uint(1) + expectedID := uuid.New().String() expectedDBError := gorm.ErrRecordNotFound s.dbmock. ExpectQuery(expectedQuery). @@ -124,21 +125,24 @@ func (s *AppealRepositoryTestSuite) TestGetByID() { s.Run("should return records on success", func() { timeNow := time.Now() + expectedID := uuid.New().String() + approvalID1 := uuid.New().String() + approvalID2 := uuid.New().String() testCases := []struct { - expectedID uint + expectedID string expectedRecord *domain.Appeal }{ { - expectedID: 1, + expectedID: expectedID, expectedRecord: &domain.Appeal{ - ID: 1, + ID: expectedID, PolicyID: "policy_1", PolicyVersion: 1, Approvals: []*domain.Approval{ { - ID: 11, + ID: approvalID1, Name: "approval_1", - AppealID: 1, + AppealID: expectedID, Status: "pending", PolicyID: "policy_1", PolicyVersion: 1, @@ -146,9 +150,9 @@ func (s *AppealRepositoryTestSuite) TestGetByID() { UpdatedAt: timeNow, }, { - ID: 12, + ID: approvalID2, Name: "approval_2", - AppealID: 1, + AppealID: expectedID, Status: "pending", PolicyID: "policy_1", PolicyVersion: 1, @@ -221,7 +225,7 @@ func (s *AppealRepositoryTestSuite) TestGetByID() { } s.dbmock. ExpectQuery(expectedApproversPreloadQuery). - WithArgs(11, 12). + WithArgs(approvalID1, approvalID2). WillReturnRows(expectedApproverRows) actualRecord, actualError := s.repository.GetByID(tc.expectedID) @@ -273,10 +277,10 @@ func (s *AppealRepositoryTestSuite) TestFind() { }, { filters: &domain.ListAppealsFilter{ - ResourceID: 1, + ResourceID: "1", }, expectedClauseQuery: `"resource_id" = $1 AND "appeals"."deleted_at" IS NULL`, - expectedArgs: []driver.Value{uint(1)}, + expectedArgs: []driver.Value{"1"}, }, { filters: &domain.ListAppealsFilter{ @@ -328,12 +332,14 @@ func (s *AppealRepositoryTestSuite) TestFind() { s.Run("should return records on success", func() { expectedQuery := regexp.QuoteMeta(`SELECT "appeals"."id","appeals"."resource_id","appeals"."policy_id","appeals"."policy_version","appeals"."status","appeals"."account_id","appeals"."account_type","appeals"."created_by","appeals"."creator","appeals"."role","appeals"."options","appeals"."labels","appeals"."details","appeals"."revoked_by","appeals"."revoked_at","appeals"."revoke_reason","appeals"."created_at","appeals"."updated_at","appeals"."deleted_at","Resource"."id" AS "Resource__id","Resource"."provider_type" AS "Resource__provider_type","Resource"."provider_urn" AS "Resource__provider_urn","Resource"."type" AS "Resource__type","Resource"."urn" AS "Resource__urn","Resource"."name" AS "Resource__name","Resource"."details" AS "Resource__details","Resource"."labels" AS "Resource__labels","Resource"."created_at" AS "Resource__created_at","Resource"."updated_at" AS "Resource__updated_at","Resource"."deleted_at" AS "Resource__deleted_at","Resource"."is_deleted" AS "Resource__is_deleted" FROM "appeals" LEFT JOIN "resources" "Resource" ON "appeals"."resource_id" = "Resource"."id" WHERE "appeals"."deleted_at" IS NULL`) + resourceID1 := uuid.New().String() + resourceID2 := uuid.New().String() expectedRecords := []*domain.Appeal{ { - ID: 1, - ResourceID: 1, + ID: uuid.New().String(), + ResourceID: resourceID1, Resource: &domain.Resource{ - ID: 1, + ID: resourceID1, ProviderType: "provider_type", ProviderURN: "provider_urn", Type: "resource_type", @@ -346,10 +352,10 @@ func (s *AppealRepositoryTestSuite) TestFind() { Role: "role_name", }, { - ID: 2, - ResourceID: 2, + ID: uuid.New().String(), + ResourceID: resourceID2, Resource: &domain.Resource{ - ID: 2, + ID: resourceID2, ProviderType: "provider_type", ProviderURN: "provider_urn", Type: "resource_type", @@ -416,12 +422,12 @@ func (s *AppealRepositoryTestSuite) TestBulkUpsert() { { AccountID: "test@email.com", Role: "role_name", - ResourceID: 1, + ResourceID: uuid.New().String(), }, { AccountID: "test2@email.com", Role: "role_name", - ResourceID: 3, + ResourceID: uuid.New().String(), }, } @@ -462,7 +468,10 @@ func (s *AppealRepositoryTestSuite) TestBulkUpsert() { s.EqualError(actualError, expectedError.Error()) }) - expectedIDs := []uint{1, 2} + expectedIDs := []string{ + uuid.New().String(), + uuid.New().String(), + } expectedRows := sqlmock.NewRows([]string{"id"}) for _, id := range expectedIDs { expectedRows.AddRow(id) @@ -492,7 +501,7 @@ func (s *AppealRepositoryTestSuite) TestUpdate() { WillReturnError(expectedError) s.dbmock.ExpectRollback() - actualError := s.repository.Update(&domain.Appeal{ID: 1}) + actualError := s.repository.Update(&domain.Appeal{ID: uuid.New().String()}) s.EqualError(actualError, expectedError.Error()) }) @@ -500,16 +509,16 @@ func (s *AppealRepositoryTestSuite) TestUpdate() { expectedUpdateApprovalsQuery := regexp.QuoteMeta(`INSERT INTO "approvals" ("name","index","appeal_id","status","actor","reason","policy_id","policy_version","created_at","updated_at","deleted_at","id") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12),($13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24) ON CONFLICT ("id") DO UPDATE SET "name"="excluded"."name","index"="excluded"."index","appeal_id"="excluded"."appeal_id","status"="excluded"."status","actor"="excluded"."actor","reason"="excluded"."reason","policy_id"="excluded"."policy_id","policy_version"="excluded"."policy_version","created_at"="excluded"."created_at","updated_at"="excluded"."updated_at","deleted_at"="excluded"."deleted_at" RETURNING "id"`) expectedUpdateAppealQuery := regexp.QuoteMeta(`UPDATE "appeals" SET "resource_id"=$1,"policy_id"=$2,"policy_version"=$3,"status"=$4,"account_id"=$5,"account_type"=$6,"created_by"=$7,"creator"=$8,"role"=$9,"options"=$10,"labels"=$11,"details"=$12,"revoked_by"=$13,"revoked_at"=$14,"revoke_reason"=$15,"created_at"=$16,"updated_at"=$17,"deleted_at"=$18 WHERE "id" = $19`) s.Run("should return nil on success", func() { - expectedID := uint(1) + expectedID := uuid.New().String() appeal := &domain.Appeal{ ID: expectedID, Approvals: []*domain.Approval{ { - ID: 11, + ID: uuid.New().String(), AppealID: expectedID, }, { - ID: 12, + ID: uuid.New().String(), AppealID: expectedID, }, }, @@ -517,7 +526,7 @@ func (s *AppealRepositoryTestSuite) TestUpdate() { s.dbmock.ExpectBegin() s.dbmock.ExpectExec(expectedUpdateAppealQuery). - WillReturnResult(sqlmock.NewResult(int64(expectedID), 1)) + WillReturnResult(sqlmock.NewResult(1, 1)) var expectedApprovalArgs []driver.Value expectedApprovalRows := sqlmock.NewRows([]string{"id"}) for _, approval := range appeal.Approvals { diff --git a/store/postgres/approval_repository.go b/store/postgres/approval_repository.go index f147927f2..1a7b3415e 100644 --- a/store/postgres/approval_repository.go +++ b/store/postgres/approval_repository.go @@ -40,7 +40,7 @@ func (r *approvalRepository) ListApprovals(conditions *domain.ListApprovalsFilte return nil, err } - var approvalIDs []uint + var approvalIDs []string for _, a := range approverModels { approvalIDs = append(approvalIDs, a.ApprovalID) } diff --git a/store/postgres/approval_repository_test.go b/store/postgres/approval_repository_test.go index e001eb8f0..d57687f56 100644 --- a/store/postgres/approval_repository_test.go +++ b/store/postgres/approval_repository_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/DATA-DOG/go-sqlmock" + "github.com/google/uuid" "github.com/odpf/guardian/domain" "github.com/odpf/guardian/mocks" "github.com/odpf/guardian/store" @@ -61,11 +62,12 @@ func (s *ApprovalRepositoryTestSuite) TestBulkInsert() { expectedQuery := regexp.QuoteMeta(`INSERT INTO "approvals" ("name","index","appeal_id","status","actor","reason","policy_id","policy_version","created_at","updated_at","deleted_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11),($12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22) RETURNING "id"`) actor := "user@email.com" + appealID := uuid.New().String() approvals := []*domain.Approval{ { Name: "approval_step_1", Index: 0, - AppealID: 1, + AppealID: appealID, Status: domain.ApprovalStatusPending, Actor: &actor, PolicyID: "policy_1", @@ -74,7 +76,7 @@ func (s *ApprovalRepositoryTestSuite) TestBulkInsert() { { Name: "approval_step_2", Index: 1, - AppealID: 1, + AppealID: appealID, Status: domain.ApprovalStatusPending, Actor: &actor, PolicyID: "policy_1", @@ -112,7 +114,10 @@ func (s *ApprovalRepositoryTestSuite) TestBulkInsert() { s.EqualError(actualError, expectedError.Error()) }) - expectedIDs := []uint{1, 2} + expectedIDs := []string{ + uuid.New().String(), + uuid.New().String(), + } expectedRows := sqlmock.NewRows([]string{"id"}) for _, id := range expectedIDs { expectedRows.AddRow(id) diff --git a/store/postgres/provider_repository.go b/store/postgres/provider_repository.go index 0b7013d3c..dfc595005 100644 --- a/store/postgres/provider_repository.go +++ b/store/postgres/provider_repository.go @@ -63,8 +63,8 @@ func (r *ProviderRepository) Find() ([]*domain.Provider, error) { } // GetByID record by ID -func (r *ProviderRepository) GetByID(id uint) (*domain.Provider, error) { - if id == 0 { +func (r *ProviderRepository) GetByID(id string) (*domain.Provider, error) { + if id == "" { return nil, provider.ErrEmptyIDParam } @@ -114,7 +114,7 @@ func (r *ProviderRepository) GetOne(pType, urn string) (*domain.Provider, error) // Update record by ID func (r *ProviderRepository) Update(p *domain.Provider) error { - if p.ID == 0 { + if p.ID == "" { return provider.ErrEmptyIDParam } @@ -140,6 +140,6 @@ func (r *ProviderRepository) Update(p *domain.Provider) error { } // Delete record by ID -func (r *ProviderRepository) Delete(id uint) error { +func (r *ProviderRepository) Delete(id string) error { return nil } diff --git a/store/postgres/provider_repository_test.go b/store/postgres/provider_repository_test.go index 135128640..af55c9a2e 100644 --- a/store/postgres/provider_repository_test.go +++ b/store/postgres/provider_repository_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/DATA-DOG/go-sqlmock" + "github.com/google/uuid" "github.com/odpf/guardian/core/provider" "github.com/odpf/guardian/domain" "github.com/odpf/guardian/mocks" @@ -54,7 +55,7 @@ func (s *ProviderRepositoryTestSuite) TestCreate() { Config: config, } - expectedID := uint(1) + expectedID := uuid.New().String() expectedRows := sqlmock.NewRows([]string{"id"}). AddRow(expectedID) s.dbmock.ExpectBegin() @@ -87,9 +88,10 @@ func (s *ProviderRepositoryTestSuite) TestFind() { s.Run("should return list of records on success", func() { now := time.Now() + providerID := uuid.New().String() expectedRecords := []*domain.Provider{ { - ID: 1, + ID: providerID, Type: "type_test", URN: "urn_test", Config: &domain.ProviderConfig{}, @@ -99,7 +101,7 @@ func (s *ProviderRepositoryTestSuite) TestFind() { } expectedRows := sqlmock.NewRows(s.rows). AddRow( - 1, + providerID, "type_test", "urn_test", "null", @@ -120,7 +122,7 @@ func (s *ProviderRepositoryTestSuite) TestGetByID() { s.Run("should return error if id is empty", func() { expectedError := provider.ErrEmptyIDParam - actualResult, actualError := s.repository.GetByID(0) + actualResult, actualError := s.repository.GetByID("") s.Nil(actualResult) s.EqualError(actualError, expectedError.Error()) @@ -132,7 +134,7 @@ func (s *ProviderRepositoryTestSuite) TestGetByID() { WillReturnError(expectedDBError) expectedError := provider.ErrRecordNotFound - actualResult, actualError := s.repository.GetByID(1) + actualResult, actualError := s.repository.GetByID("1") s.Nil(actualResult) s.EqualError(actualError, expectedError.Error()) @@ -143,7 +145,7 @@ func (s *ProviderRepositoryTestSuite) TestGetByID() { s.dbmock.ExpectQuery(".*"). WillReturnError(expectedError) - actualResult, actualError := s.repository.GetByID(1) + actualResult, actualError := s.repository.GetByID("1") s.Nil(actualResult) s.EqualError(actualError, expectedError.Error()) @@ -151,7 +153,7 @@ func (s *ProviderRepositoryTestSuite) TestGetByID() { expectedQuery := regexp.QuoteMeta(`SELECT * FROM "providers" WHERE id = $1 AND "providers"."deleted_at" IS NULL ORDER BY "providers"."id" LIMIT 1`) s.Run("should return record and nil error on success", func() { - expectedID := uint(10) + expectedID := uuid.New().String() timeNow := time.Now() expectedRows := sqlmock.NewRows(s.rows). AddRow( @@ -188,15 +190,15 @@ func (s *ProviderRepositoryTestSuite) TestUpdate() { WillReturnError(expectedError) s.dbmock.ExpectRollback() - actualError := s.repository.Update(&domain.Provider{ID: 1, Type: "test-type", URN: "test-urn"}) + actualError := s.repository.Update(&domain.Provider{ID: uuid.New().String(), Type: "test-type", URN: "test-urn"}) s.EqualError(actualError, expectedError.Error()) }) - expectedQuery := regexp.QuoteMeta(`UPDATE "providers" SET "id"=$1,"type"=$2,"urn"=$3,"config"=$4,"updated_at"=$5 WHERE "type" = $6 AND "urn" = $7`) + expectedQuery := regexp.QuoteMeta(`UPDATE "providers" SET "id"=$1,"type"=$2,"urn"=$3,"config"=$4,"updated_at"=$5 WHERE "id" = $6`) s.Run("should return error if got error from transaction", func() { config := &domain.ProviderConfig{} - expectedID := uint(1) + expectedID := uuid.New().String() provider := &domain.Provider{ ID: expectedID, Type: "test-type", @@ -206,7 +208,7 @@ func (s *ProviderRepositoryTestSuite) TestUpdate() { s.dbmock.ExpectBegin() s.dbmock.ExpectExec(expectedQuery). - WillReturnResult(sqlmock.NewResult(int64(expectedID), 1)) + WillReturnResult(sqlmock.NewResult(1, 1)) s.dbmock.ExpectCommit() err := s.repository.Update(provider) diff --git a/store/postgres/resource_repository.go b/store/postgres/resource_repository.go index 97d448aa8..f74e3aeb7 100644 --- a/store/postgres/resource_repository.go +++ b/store/postgres/resource_repository.go @@ -13,7 +13,7 @@ import ( ) type resourceFindFilters struct { - IDs []uint `mapstructure:"ids" validate:"omitempty,min=1"` + IDs []string `mapstructure:"ids" validate:"omitempty,min=1"` IsDeleted bool `mapstructure:"is_deleted" validate:"omitempty"` ProviderType string `mapstructure:"provider_type" validate:"omitempty"` ProviderURN string `mapstructure:"provider_urn" validate:"omitempty"` @@ -89,8 +89,8 @@ func (r *ResourceRepository) Find(filters map[string]interface{}) ([]*domain.Res } // GetOne record by ID -func (r *ResourceRepository) GetOne(id uint) (*domain.Resource, error) { - if id == 0 { +func (r *ResourceRepository) GetOne(id string) (*domain.Resource, error) { + if id == "" { return nil, resource.ErrEmptyIDParam } @@ -150,7 +150,7 @@ func (r *ResourceRepository) BulkUpsert(resources []*domain.Resource) error { // Update record by ID func (r *ResourceRepository) Update(res *domain.Resource) error { - if res.ID == 0 { + if res.ID == "" { return resource.ErrEmptyIDParam } diff --git a/store/postgres/resource_repository_test.go b/store/postgres/resource_repository_test.go index 44e96a833..73caa0b74 100644 --- a/store/postgres/resource_repository_test.go +++ b/store/postgres/resource_repository_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/DATA-DOG/go-sqlmock" + "github.com/google/uuid" "github.com/odpf/guardian/core/resource" "github.com/odpf/guardian/domain" "github.com/odpf/guardian/mocks" @@ -52,6 +53,8 @@ func (s *ResourceRepositoryTestSuite) TearDownTest() { func (s *ResourceRepositoryTestSuite) TestFind() { s.Run("should pass conditions based on filters", func() { + resourceID1 := uuid.New().String() + resourceID2 := uuid.New().String() testCases := []struct { filters map[string]interface{} expectedQuery string @@ -64,10 +67,10 @@ func (s *ResourceRepositoryTestSuite) TestFind() { }, { filters: map[string]interface{}{ - "ids": []uint{1, 2, 3}, + "ids": []string{resourceID1, resourceID2}, }, - expectedQuery: regexp.QuoteMeta(`SELECT * FROM "resources" WHERE "resources"."id" IN ($1,$2,$3) AND "is_deleted" = $4 AND "resources"."deleted_at" IS NULL`), - expectedArgs: []driver.Value{1, 2, 3, false}, + expectedQuery: regexp.QuoteMeta(`SELECT * FROM "resources" WHERE "resources"."id" IN ($1,$2) AND "is_deleted" = $3 AND "resources"."deleted_at" IS NULL`), + expectedArgs: []driver.Value{resourceID1, resourceID2, false}, }, } @@ -97,9 +100,10 @@ func (s *ResourceRepositoryTestSuite) TestFind() { s.Run("should return list of records on success", func() { timeNow := time.Now() + resourceID := uuid.New().String() expectedRecords := []*domain.Resource{ { - ID: 1, + ID: resourceID, ProviderType: "provider_type_test", ProviderURN: "provider_urn_test", Type: "type_test", @@ -110,7 +114,7 @@ func (s *ResourceRepositoryTestSuite) TestFind() { } expectedRows := sqlmock.NewRows(s.columnNames). AddRow( - 1, + resourceID, "provider_type_test", "provider_urn_test", "type_test", @@ -134,7 +138,7 @@ func (s *ResourceRepositoryTestSuite) TestGetOne() { s.Run("should return error if id is empty", func() { expectedError := resource.ErrEmptyIDParam - actualResult, actualError := s.repository.GetOne(0) + actualResult, actualError := s.repository.GetOne("") s.Nil(actualResult) s.EqualError(actualError, expectedError.Error()) @@ -146,7 +150,7 @@ func (s *ResourceRepositoryTestSuite) TestGetOne() { WillReturnError(expectedDBError) expectedError := resource.ErrRecordNotFound - actualResult, actualError := s.repository.GetOne(1) + actualResult, actualError := s.repository.GetOne("1") s.Nil(actualResult) s.EqualError(actualError, expectedError.Error()) @@ -157,7 +161,7 @@ func (s *ResourceRepositoryTestSuite) TestGetOne() { s.dbmock.ExpectQuery(".*"). WillReturnError(expectedError) - actualResult, actualError := s.repository.GetOne(1) + actualResult, actualError := s.repository.GetOne("1") s.Nil(actualResult) s.EqualError(actualError, expectedError.Error()) @@ -165,11 +169,11 @@ func (s *ResourceRepositoryTestSuite) TestGetOne() { expectedQuery := regexp.QuoteMeta(`SELECT * FROM "resources" WHERE id = $1 AND "resources"."deleted_at" IS NULL LIMIT 1`) s.Run("should return record and nil error on success", func() { - expectedID := uint(10) + expectedID := uuid.New().String() timeNow := time.Now() expectedRows := sqlmock.NewRows(s.columnNames). AddRow( - 1, + expectedID, "provider_type_test", "provider_urn_test", "type_test", @@ -226,7 +230,10 @@ func (s *ResourceRepositoryTestSuite) TestBulkUpsert() { false, ) } - expectedIDs := []uint{1, 2} + expectedIDs := []string{ + uuid.New().String(), + uuid.New().String(), + } expectedRows := sqlmock.NewRows([]string{"id"}) for _, id := range expectedIDs { expectedRows.AddRow(id) @@ -262,21 +269,21 @@ func (s *ResourceRepositoryTestSuite) TestUpdate() { WillReturnError(expectedError) s.dbmock.ExpectRollback() - actualError := s.repository.Update(&domain.Resource{ID: 1}) + actualError := s.repository.Update(&domain.Resource{ID: uuid.New().String()}) s.EqualError(actualError, expectedError.Error()) }) expectedQuery := regexp.QuoteMeta(`UPDATE "resources" SET "id"=$1,"details"=$2,"labels"=$3,"updated_at"=$4 WHERE id = $5`) s.Run("should return error if got error from transaction", func() { - expectedID := uint(1) + expectedID := uuid.New().String() resource := &domain.Resource{ ID: expectedID, } s.dbmock.ExpectBegin() s.dbmock.ExpectExec(expectedQuery). - WillReturnResult(sqlmock.NewResult(int64(expectedID), 1)) + WillReturnResult(sqlmock.NewResult(1, 1)) s.dbmock.ExpectCommit() err := s.repository.Update(resource) diff --git a/store/postgres/store.go b/store/postgres/store.go index 7a44869e7..99ef968e1 100644 --- a/store/postgres/store.go +++ b/store/postgres/store.go @@ -38,12 +38,18 @@ func (s *Store) DB() *gorm.DB { } func (s *Store) Migrate() error { - return s.db.AutoMigrate( - &model.Provider{}, - &model.Policy{}, - &model.Resource{}, - &model.Appeal{}, - &model.Approval{}, - &model.Approver{}, - ) + return s.db.Transaction(func(tx *gorm.DB) error { + if err := tx.Exec(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`).Error; err != nil { + return err + } + + return tx.AutoMigrate( + &model.Provider{}, + &model.Policy{}, + &model.Resource{}, + &model.Appeal{}, + &model.Approval{}, + &model.Approver{}, + ) + }) } diff --git a/store/repository.go b/store/repository.go index 050797cbf..eb7d151a9 100644 --- a/store/repository.go +++ b/store/repository.go @@ -5,7 +5,7 @@ import "github.com/odpf/guardian/domain" type AppealRepository interface { BulkUpsert([]*domain.Appeal) error Find(*domain.ListAppealsFilter) ([]*domain.Appeal, error) - GetByID(uint) (*domain.Appeal, error) + GetByID(id string) (*domain.Appeal, error) Update(*domain.Appeal) error } @@ -24,14 +24,14 @@ type ProviderRepository interface { Create(*domain.Provider) error Update(*domain.Provider) error Find() ([]*domain.Provider, error) - GetByID(uint) (*domain.Provider, error) + GetByID(id string) (*domain.Provider, error) GetOne(pType, urn string) (*domain.Provider, error) - Delete(uint) error + Delete(id string) error } type ResourceRepository interface { Find(filters map[string]interface{}) ([]*domain.Resource, error) - GetOne(uint) (*domain.Resource, error) + GetOne(id string) (*domain.Resource, error) BulkUpsert([]*domain.Resource) error Update(*domain.Resource) error }