Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/grpc/index.html

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

6 changes: 6 additions & 0 deletions docs/openapi/policy/attributes/attributes.swagger.json

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

2 changes: 1 addition & 1 deletion integration/attribute_values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (s *AttributeValuesSuite) Test_DeactivateAttribute_Cascades_List() {
}

listAttributes := func(state string) bool {
listedAttrs, err := s.db.PolicyClient.ListAllAttributes(s.ctx, state)
listedAttrs, err := s.db.PolicyClient.ListAllAttributes(s.ctx, state, "")
assert.Nil(s.T(), err)
assert.NotNil(s.T(), listedAttrs)
for _, a := range listedAttrs {
Expand Down
22 changes: 20 additions & 2 deletions integration/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (s *AttributesSuite) Test_GetAttribute_Deactivated_Succeeds() {
func (s *AttributesSuite) Test_ListAttribute() {
fixtures := s.getAttributeFixtures()

list, err := s.db.PolicyClient.ListAllAttributes(s.ctx, policydb.StateActive)
list, err := s.db.PolicyClient.ListAllAttributes(s.ctx, policydb.StateActive, "")
assert.Nil(s.T(), err)
assert.NotNil(s.T(), list)

Expand All @@ -246,6 +246,24 @@ func (s *AttributesSuite) Test_ListAttribute() {
}
}

func (s *AttributesSuite) Test_ListAttributesByNamespace() {
// get all unique namespace_ids
nsIds := map[string]bool{}
for _, f := range s.getAttributeFixtures() {
nsIds[f.NamespaceId] = true
}
// get all attributes by namespace
for nsId := range nsIds {
list, err := s.db.PolicyClient.ListAllAttributes(s.ctx, policydb.StateAny, nsId)
assert.Nil(s.T(), err)
assert.NotNil(s.T(), list)
assert.NotEmpty(s.T(), list)
for _, l := range list {
assert.Equal(s.T(), nsId, l.Namespace.Id)
}
}
}

func (s *AttributesSuite) Test_UpdateAttribute() {
fixedLabel := "fixed label"
updateLabel := "update label"
Expand Down Expand Up @@ -452,7 +470,7 @@ func (s *AttributesSuite) Test_DeactivateAttribute_Cascades_List() {
}

listAttributes := func(state string) bool {
listedAttrs, err := s.db.PolicyClient.ListAllAttributes(s.ctx, state)
listedAttrs, err := s.db.PolicyClient.ListAllAttributes(s.ctx, state, "")
assert.Nil(s.T(), err)
assert.NotNil(s.T(), listedAttrs)
for _, a := range listedAttrs {
Expand Down
2 changes: 1 addition & 1 deletion integration/namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (s *NamespacesSuite) Test_DeactivateNamespace_Cascades_List() {
}

listAttributes := func(state string) bool {
listedAttrs, err := s.db.PolicyClient.ListAllAttributes(s.ctx, state)
listedAttrs, err := s.db.PolicyClient.ListAllAttributes(s.ctx, state, "")
assert.Nil(s.T(), err)
assert.NotNil(s.T(), listedAttrs)
for _, a := range listedAttrs {
Expand Down
742 changes: 376 additions & 366 deletions protocol/go/policy/attributes/attributes.pb.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion services/policy/attributes/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ func (s *AttributesService) ListAttributes(ctx context.Context,
req *attributes.ListAttributesRequest,
) (*attributes.ListAttributesResponse, error) {
state := services.GetDbStateTypeTransformedEnum(req.State)
namespace_id := req.NamespaceId
slog.Debug("listing attribute definitions", slog.String("state", state))
rsp := &attributes.ListAttributesResponse{}

list, err := s.dbClient.ListAllAttributes(ctx, state)
list, err := s.dbClient.ListAllAttributes(ctx, state, namespace_id)
if err != nil {
return nil, services.HandleError(err, services.ErrListRetrievalFailed)
}
Expand Down
1 change: 1 addition & 0 deletions services/policy/attributes/attributes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ message ValueKeyAccessServer {
message ListAttributesRequest {
// ACTIVE by default when not specified
common.ActiveStateEnum state = 1;
string namespace_id = 2;
}
message ListAttributesResponse {
repeated policy.Attribute attributes = 1;
Expand Down
8 changes: 7 additions & 1 deletion services/policy/db/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type attributesSelectOptions struct {
withFqn bool
withOneValueByFqn string
state string
namespace_id string
}

func attributesSelect(opts attributesSelectOptions) sq.SelectBuilder {
Expand Down Expand Up @@ -274,15 +275,20 @@ func listAllAttributesSql(opts attributesSelectOptions) (string, []interface{},
if opts.state != "" && opts.state != StateAny {
sb = sb.Where(sq.Eq{t.Field("active"): opts.state == StateActive})
}

if opts.namespace_id != "" {
sb = sb.Where(sq.Eq{t.Field("namespace_id"): opts.namespace_id})
}
return sb.ToSql()
}

func (c PolicyDbClient) ListAllAttributes(ctx context.Context, state string) ([]*policy.Attribute, error) {
func (c PolicyDbClient) ListAllAttributes(ctx context.Context, state string, namespace_id string) ([]*policy.Attribute, error) {
opts := attributesSelectOptions{
withAttributeValues: true,
withKeyAccessGrants: false,
withFqn: true,
state: state,
namespace_id: namespace_id,
}

sql, args, err := listAllAttributesSql(opts)
Expand Down