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
4 changes: 2 additions & 2 deletions docs/grpc/index.html

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

3 changes: 2 additions & 1 deletion docs/openapi/policy/attributes/attributes.swagger.json

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

20 changes: 16 additions & 4 deletions integration/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,31 @@ func (s *AttributesSuite) Test_ListAttribute() {

func (s *AttributesSuite) Test_ListAttributesByNamespace() {
// get all unique namespace_ids
nsIds := map[string]bool{}
namespaces := map[string]string{}
for _, f := range s.getAttributeFixtures() {
nsIds[f.NamespaceId] = true
namespaces[f.NamespaceId] = ""
}
// get all attributes by namespace
for nsId := range nsIds {
// list attributes by namespace id
for nsId := range namespaces {
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)
}
namespaces[nsId] = list[0].Namespace.Name
}

// list attributes by namespace name
for _, nsName := range namespaces {
list, err := s.db.PolicyClient.ListAllAttributes(s.ctx, policydb.StateAny, nsName)
assert.Nil(s.T(), err)
assert.NotNil(s.T(), list)
assert.NotEmpty(s.T(), list)
for _, l := range list {
assert.Equal(s.T(), nsName, l.Namespace.Name)
}
}
}

Expand Down
751 changes: 376 additions & 375 deletions protocol/go/policy/attributes/attributes.pb.go

Large diffs are not rendered by default.

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

list, err := s.dbClient.ListAllAttributes(ctx, state, namespace_id)
list, err := s.dbClient.ListAllAttributes(ctx, state, namespace)
if err != nil {
return nil, services.HandleError(err, services.ErrListRetrievalFailed)
}
Expand Down
3 changes: 2 additions & 1 deletion services/policy/attributes/attributes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ message ValueKeyAccessServer {
message ListAttributesRequest {
// ACTIVE by default when not specified
common.ActiveStateEnum state = 1;
string namespace_id = 2;
// can be id or name
string namespace = 2;
}
message ListAttributesResponse {
repeated policy.Attribute attributes = 1;
Expand Down
16 changes: 11 additions & 5 deletions services/policy/db/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

sq "github.com/Masterminds/squirrel"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/opentdf/platform/internal/db"
"github.com/opentdf/platform/protocol/go/common"
Expand Down Expand Up @@ -59,7 +60,7 @@ type attributesSelectOptions struct {
withFqn bool
withOneValueByFqn string
state string
namespace_id string
namespace string
}

func attributesSelect(opts attributesSelectOptions) sq.SelectBuilder {
Expand Down Expand Up @@ -276,19 +277,24 @@ func listAllAttributesSql(opts attributesSelectOptions) (string, []interface{},
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})
if opts.namespace != "" {
_, err := uuid.Parse(opts.namespace)
if err == nil {
sb = sb.Where(sq.Eq{t.Field("namespace_id"): opts.namespace})
} else {
sb = sb.Where(sq.Eq{Tables.Namespaces.Field("name"): opts.namespace})
}
}
return sb.ToSql()
}

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

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