Skip to content

Commit

Permalink
enhancement: Add includeDisabled to Admin API and schema deletion to …
Browse files Browse the repository at this point in the history
…cerbosctl (#1463)

* enhancement: Add includeDisabled to Admin API and schema deletion to cerbosctl

Signed-off-by: Oğuzhan Durgun <oguzhandurgun95@gmail.com>

* Address reviews

Signed-off-by: Oğuzhan Durgun <oguzhandurgun95@gmail.com>

* Address reviews

Signed-off-by: Oğuzhan Durgun <oguzhandurgun95@gmail.com>

---------

Signed-off-by: Oğuzhan Durgun <oguzhandurgun95@gmail.com>
  • Loading branch information
oguzhand95 committed Feb 17, 2023
1 parent 936b2e3 commit 138a1cd
Show file tree
Hide file tree
Showing 42 changed files with 614 additions and 74 deletions.
4 changes: 4 additions & 0 deletions api/genpb/cerbos/request/v1/hashpb_helpers.pb.go

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

18 changes: 16 additions & 2 deletions api/genpb/cerbos/request/v1/request.pb.go

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

2 changes: 2 additions & 0 deletions api/genpb/cerbos/request/v1/request.pb.validate.go

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

8 changes: 8 additions & 0 deletions api/genpb/cerbos/request/v1/request_hashpb.pb.go

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

33 changes: 33 additions & 0 deletions api/genpb/cerbos/request/v1/request_vtproto.pb.go

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

18 changes: 18 additions & 0 deletions api/genpb/cerbos/svc/v1/svc.pb.gw.go

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

4 changes: 4 additions & 0 deletions api/public/cerbos/request/v1/request.proto
Expand Up @@ -517,6 +517,10 @@ message ListPoliciesRequest {
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_schema) = {
json_schema: {description: "List policies request"}
};
bool include_disabled = 1 [
(google.api.field_behavior) = OPTIONAL,
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {description: "Include disabled policies"}
];
}

message GetPolicyRequest {
Expand Down
11 changes: 8 additions & 3 deletions client/admin.go
Expand Up @@ -28,7 +28,7 @@ const (
type AdminClient interface {
AddOrUpdatePolicy(ctx context.Context, policies *PolicySet) error
AuditLogs(ctx context.Context, opts AuditLogOptions) (<-chan *AuditLogEntry, error)
ListPolicies(ctx context.Context) ([]string, error)
ListPolicies(ctx context.Context, opts ...ListPoliciesOption) ([]string, error)
GetPolicy(ctx context.Context, ids ...string) ([]*policyv1.Policy, error)
DisablePolicy(ctx context.Context, ids ...string) (uint32, error)
AddOrUpdateSchema(ctx context.Context, schemas *SchemaSet) error
Expand Down Expand Up @@ -175,8 +175,13 @@ func (c *GrpcAdminClient) auditLogs(ctx context.Context, opts AuditLogOptions) (
return resp, nil
}

func (c *GrpcAdminClient) ListPolicies(ctx context.Context) ([]string, error) {
req := &requestv1.ListPoliciesRequest{}
func (c *GrpcAdminClient) ListPolicies(ctx context.Context, opts ...ListPoliciesOption) ([]string, error) {
req := &requestv1.ListPoliciesRequest{
IncludeDisabled: false,
}
for _, opt := range opts {
opt(req)
}
if err := req.Validate(); err != nil {
return nil, fmt.Errorf("could not validate list policies request: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion client/admin_test.go
Expand Up @@ -118,7 +118,7 @@ func TestListPolicies(t *testing.T) {
require.NoError(t, ac.AddOrUpdatePolicy(context.Background(), ps))

t.Run("should get the list of policies", func(t *testing.T) {
have, err := ac.ListPolicies(context.Background())
have, err := ac.ListPolicies(context.Background(), WithIncludeDisabled())
require.NoError(t, err)
require.NotEmpty(t, have)

Expand Down
10 changes: 10 additions & 0 deletions client/model.go
Expand Up @@ -1225,3 +1225,13 @@ func (e *AuditLogEntry) DecisionLog() (*auditv1.DecisionLogEntry, error) {
type PlanResourcesResponse struct {
*responsev1.PlanResourcesResponse
}

type (
ListPoliciesOption func(*requestv1.ListPoliciesRequest)
)

func WithIncludeDisabled() ListPoliciesOption {
return func(request *requestv1.ListPoliciesRequest) {
request.IncludeDisabled = true
}
}
8 changes: 8 additions & 0 deletions cmd/cerbosctl/del/delete.go
@@ -0,0 +1,8 @@
// Copyright 2021-2023 Zenauth Ltd.
// SPDX-License-Identifier: Apache-2.0

package del

type Cmd struct {
Schema SchemaCmd `cmd:"" aliases:"schemas,s"`
}

0 comments on commit 138a1cd

Please sign in to comment.