Skip to content

Commit

Permalink
feat(policy): apply dynamic policy (#188)
Browse files Browse the repository at this point in the history
* feat(policy): apply dynamic policy

* test: try adding parallel

* chore: update get policy flow as additional layer, removing default policy

* chore: remove default policy

* chore: update provider policies config json yaml tag

* test: update test

* chore: handle latest version
  • Loading branch information
idilhaq authored Dec 11, 2024
1 parent 6d09d2b commit 1d73c05
Show file tree
Hide file tree
Showing 8 changed files with 2,012 additions and 1,314 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ COMMIT := $(shell git rev-parse --short HEAD)
TAG := "$(shell git rev-list --tags --max-count=1)"
VERSION := "$(shell git describe --tags ${TAG})-next"
BUILD_DIR=dist
PROTON_COMMIT := "526e657b03d243a4c9f880e6c4ffbe15b116afd5"
PROTON_COMMIT := "629e2f8d4b3b0634238e8b99663ccf8fa409bb39"

.PHONY: all build clean test tidy vet proto setup format generate

Expand Down
22 changes: 22 additions & 0 deletions api/handler/v1beta1/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ func (a *adapter) FromProviderConfigProto(pc *guardianv1beta1.ProviderConfig) *d
providerConfig.AllowedAccountTypes = pc.GetAllowedAccountTypes()
}

if pc.GetPolicies() != nil {
policies := []*domain.ProviderPolicy{}
for _, p := range pc.GetPolicies() {
policies = append(policies, &domain.ProviderPolicy{
When: p.GetWhen(),
Policy: p.GetPolicy(),
})
}
providerConfig.Policies = policies
}

return providerConfig
}

Expand Down Expand Up @@ -189,6 +200,17 @@ func (a *adapter) ToProviderConfigProto(pc *domain.ProviderConfig) (*guardianv1b
providerConfigProto.AllowedAccountTypes = pc.AllowedAccountTypes
}

if pc.Policies != nil {
policies := []*guardianv1beta1.ProviderPolicy{}
for _, p := range pc.Policies {
policies = append(policies, &guardianv1beta1.ProviderPolicy{
Policy: p.Policy,
When: p.When,
})
}
providerConfigProto.Policies = policies
}

return providerConfigProto, nil
}

Expand Down
60 changes: 60 additions & 0 deletions api/handler/v1beta1/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ func (s *GrpcHandlersSuite) TestListProvider() {
},
},
},
Policies: []*domain.ProviderPolicy{
{
When: "test-when",
Policy: "test-policy",
},
},
},
CreatedAt: timeNow,
UpdatedAt: timeNow,
Expand Down Expand Up @@ -82,6 +88,12 @@ func (s *GrpcHandlersSuite) TestListProvider() {
},
},
},
Policies: []*guardianv1beta1.ProviderPolicy{
{
When: "test-when",
Policy: "test-policy",
},
},
},
CreatedAt: timestamppb.New(timeNow),
UpdatedAt: timestamppb.New(timeNow),
Expand Down Expand Up @@ -172,6 +184,12 @@ func (s *GrpcHandlersSuite) TestGetProvider() {
},
},
},
Policies: []*domain.ProviderPolicy{
{
When: "test-when",
Policy: "test-policy",
},
},
},
CreatedAt: timeNow,
UpdatedAt: timeNow,
Expand Down Expand Up @@ -200,6 +218,12 @@ func (s *GrpcHandlersSuite) TestGetProvider() {
},
},
},
Policies: []*guardianv1beta1.ProviderPolicy{
{
When: "test-when",
Policy: "test-policy",
},
},
},
CreatedAt: timestamppb.New(timeNow),
UpdatedAt: timestamppb.New(timeNow),
Expand Down Expand Up @@ -352,6 +376,12 @@ func (s *GrpcHandlersSuite) TestCreateProvider() {
Description: "Please enter your username",
},
},
Policies: []*domain.ProviderPolicy{
{
When: "test-when",
Policy: "test-policy",
},
},
},
}
expectedResponse := &guardianv1beta1.CreateProviderResponse{
Expand Down Expand Up @@ -390,6 +420,12 @@ func (s *GrpcHandlersSuite) TestCreateProvider() {
Description: "Please enter your username",
},
},
Policies: []*guardianv1beta1.ProviderPolicy{
{
When: "test-when",
Policy: "test-policy",
},
},
},
CreatedAt: timestamppb.New(timeNow),
UpdatedAt: timestamppb.New(timeNow),
Expand Down Expand Up @@ -434,6 +470,12 @@ func (s *GrpcHandlersSuite) TestCreateProvider() {
Description: "Please enter your username",
},
},
Policies: []*guardianv1beta1.ProviderPolicy{
{
When: "test-when",
Policy: "test-policy",
},
},
},
}
res, err := s.grpcServer.CreateProvider(context.Background(), req)
Expand Down Expand Up @@ -508,6 +550,12 @@ func (s *GrpcHandlersSuite) TestUpdatedProvider() {
},
},
},
Policies: []*domain.ProviderPolicy{
{
When: "test-when",
Policy: "test-policy",
},
},
},
}
expectedResponse := &guardianv1beta1.UpdateProviderResponse{
Expand All @@ -534,6 +582,12 @@ func (s *GrpcHandlersSuite) TestUpdatedProvider() {
},
},
},
Policies: []*guardianv1beta1.ProviderPolicy{
{
When: "test-when",
Policy: "test-policy",
},
},
},
CreatedAt: timestamppb.New(timeNow),
UpdatedAt: timestamppb.New(timeNow),
Expand Down Expand Up @@ -566,6 +620,12 @@ func (s *GrpcHandlersSuite) TestUpdatedProvider() {
},
},
},
Policies: []*guardianv1beta1.ProviderPolicy{
{
When: "test-when",
Policy: "test-policy",
},
},
},
}
res, err := s.grpcServer.UpdateProvider(context.Background(), req)
Expand Down
Loading

0 comments on commit 1d73c05

Please sign in to comment.