-
Notifications
You must be signed in to change notification settings - Fork 9
feat(core): Make namespacing subject mappings and condition sets optional #776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package handlers | |
| import ( | ||
| "context" | ||
|
|
||
| "github.com/google/uuid" | ||
| "github.com/opentdf/platform/protocol/go/common" | ||
| "github.com/opentdf/platform/protocol/go/policy" | ||
| "github.com/opentdf/platform/protocol/go/policy/subjectmapping" | ||
|
|
@@ -15,6 +16,13 @@ const ( | |
| SubjectMappingOperatorUnspecified = "UNSPECIFIED" | ||
| ) | ||
|
|
||
| func parseNamespaceIDOrFQN(namespace string) (string, string) { | ||
| if _, err := uuid.Parse(namespace); err != nil { | ||
| return "", namespace | ||
| } | ||
| return namespace, "" | ||
| } | ||
|
|
||
| var SubjectMappingOperatorEnumChoices = []string{SubjectMappingOperatorIn, SubjectMappingOperatorNotIn, SubjectMappingOperatorUnspecified} | ||
|
|
||
| func (h Handler) GetSubjectMapping(ctx context.Context, id string) (*policy.SubjectMapping, error) { | ||
|
|
@@ -34,14 +42,23 @@ func (h Handler) ListSubjectMappings(ctx context.Context, limit, offset int32) ( | |
| } | ||
|
|
||
| // Creates and returns the created subject mapping | ||
| func (h Handler) CreateNewSubjectMapping(ctx context.Context, attrValID string, actions []*policy.Action, existingSCSId string, newScs *subjectmapping.SubjectConditionSetCreate, m *common.MetadataMutable) (*policy.SubjectMapping, error) { | ||
| resp, err := h.sdk.SubjectMapping.CreateSubjectMapping(ctx, &subjectmapping.CreateSubjectMappingRequest{ | ||
| func (h Handler) CreateNewSubjectMapping(ctx context.Context, namespace string, attrValID string, actions []*policy.Action, existingSCSId string, newScs *subjectmapping.SubjectConditionSetCreate, m *common.MetadataMutable) (*policy.SubjectMapping, error) { | ||
| req := &subjectmapping.CreateSubjectMappingRequest{ | ||
| AttributeValueId: attrValID, | ||
| Actions: actions, | ||
| ExistingSubjectConditionSetId: existingSCSId, | ||
| NewSubjectConditionSet: newScs, | ||
| Metadata: m, | ||
| }) | ||
| } | ||
| if namespace != "" { | ||
| namespaceID, namespaceFQN := parseNamespaceIDOrFQN(namespace) | ||
| if namespaceID != "" { | ||
| req.NamespaceId = namespaceID | ||
| } else { | ||
| req.NamespaceFqn = namespaceFQN | ||
| } | ||
| } | ||
|
Comment on lines
+53
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic for setting the namespace on the request is duplicated in |
||
| resp, err := h.sdk.SubjectMapping.CreateSubjectMapping(ctx, req) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with other flag definitions (like in
docs/man/policy/subject-condition-sets/create.md), it's best to explicitly adddefault: ''for the optionalnamespaceflag. While the behavior might be correct without it due to zero-value defaults, explicitly defining it improves the clarity and robustness of the command definition parsing.