-
Notifications
You must be signed in to change notification settings - Fork 6
feat(core): kas-grants CRUD #80
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cb13ce5
add kas-grants handlers
alkalescent ca3af38
boilerplate cmd
alkalescent a593fe7
update flags
alkalescent 67df0fa
clean up
alkalescent 753f4c5
update cmd
alkalescent 656b697
clean up
alkalescent 00ed368
delete cmd
alkalescent 933ffb6
Update cmd/kas-grants.go
alkalescent 769ce26
delete check
alkalescent 2a13876
Update cmd/kas-grants.go
alkalescent 3590250
Update cmd/kas-grants.go
alkalescent e7d838a
Update cmd/kas-grants.go
alkalescent 21038ca
flag labels
alkalescent 2747c45
pass response to HandleSuccess
alkalescent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/opentdf/tructl/pkg/cli" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var ( | ||
| kasGrants_crudCommands = []string{ | ||
| kasGrantsUpdateCmd.Use, | ||
| kasGrantsDeleteCmd.Use, | ||
| } | ||
|
|
||
| // KasGrantsCmd is the command for managing KAS grants | ||
| kasGrantsCmd = &cobra.Command{ | ||
| Use: "kas-grants", | ||
| Short: "Manage Key Access Server grants [" + strings.Join(kasGrants_crudCommands, ", ") + "]", | ||
| } | ||
|
|
||
| // Update one KAS registry entry | ||
| kasGrantsUpdateCmd = &cobra.Command{ | ||
| Use: "update", | ||
| Short: "Update a KAS grant", | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| h := cli.NewHandler(cmd) | ||
| defer h.Close() | ||
|
|
||
| flagHelper := cli.NewFlagHelper(cmd) | ||
|
|
||
| attr := flagHelper.GetOptionalString("attribute") | ||
| val := flagHelper.GetOptionalString("value") | ||
| kas := flagHelper.GetRequiredString("kas") | ||
|
|
||
| if attr == "" && val == "" { | ||
| cli.ExitWithError("Must specify and Attribute Definition id or Value id to update.", nil) | ||
| } | ||
| var ( | ||
| id string | ||
| header string | ||
| res interface{} | ||
| err error | ||
| ) | ||
|
|
||
| if attr != "" { | ||
| res, err = h.UpdateKasGrantForAttribute(attr, kas) | ||
| if err != nil { | ||
| cli.ExitWithError("Could not update KAS grant for attribute", err) | ||
| } | ||
| id = attr | ||
| header = "Attribute ID" | ||
| } else { | ||
| res, err = h.UpdateKasGrantForValue(val, kas) | ||
| if err != nil { | ||
| cli.ExitWithError("Could not update KAS grant for attribute value", err) | ||
| } | ||
| id = val | ||
| header = "Value ID" | ||
| } | ||
|
|
||
| t := cli.NewTabular(). | ||
| Rows([][]string{ | ||
| {header, id}, | ||
| {"KAS ID", kas}, | ||
| }...) | ||
| HandleSuccess(cmd, id, t, res) | ||
| }, | ||
| } | ||
|
|
||
| kasGrantsDeleteCmd = &cobra.Command{ | ||
| Use: "delete", | ||
| Short: "Delete a KAS grant", | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| h := cli.NewHandler(cmd) | ||
| defer h.Close() | ||
|
|
||
| flagHelper := cli.NewFlagHelper(cmd) | ||
| attr := flagHelper.GetOptionalString("attribute") | ||
| val := flagHelper.GetOptionalString("value") | ||
| kas := flagHelper.GetRequiredString("kas") | ||
|
|
||
| if attr == "" && val == "" { | ||
| cli.ExitWithError("Must specify and Attribute Definition id or Value id to delete.", nil) | ||
| } | ||
| var ( | ||
| id string | ||
| header string | ||
| res interface{} | ||
| err error | ||
| ) | ||
|
|
||
| cli.ConfirmDelete("KAS ID: ", kas) | ||
|
|
||
| if attr != "" { | ||
| res, err = h.DeleteKasGrantFromAttribute(attr, kas) | ||
| if err != nil { | ||
| cli.ExitWithError("Could not update KAS grant for attribute", err) | ||
| } | ||
| id = attr | ||
| header = "Attribute ID" | ||
| } else { | ||
| _, err := h.DeleteKasGrantFromValue(val, kas) | ||
| if err != nil { | ||
| cli.ExitWithError("Could not update KAS grant for attribute value", err) | ||
| } | ||
| id = val | ||
| header = "Value ID" | ||
| } | ||
|
|
||
| t := cli.NewTabular(). | ||
| Rows([][]string{ | ||
| {header, id}, | ||
| {"KAS ID", kas}, | ||
| }...) | ||
| HandleSuccess(cmd, id, t, res) | ||
| }, | ||
| } | ||
| ) | ||
|
|
||
| func init() { | ||
| policyCmd.AddCommand(kasGrantsCmd) | ||
|
|
||
| kasGrantsCmd.AddCommand(kasGrantsUpdateCmd) | ||
| kasGrantsUpdateCmd.Flags().StringP("attribute", "a", "", "Attribute Definition ID") | ||
| kasGrantsUpdateCmd.Flags().StringP("value", "v", "", "Attribute Value ID") | ||
| kasGrantsUpdateCmd.Flags().StringP("kas", "k", "", "Key Access Server (KAS) ID") | ||
| injectLabelFlags(kasGrantsUpdateCmd, true) | ||
|
|
||
| kasGrantsCmd.AddCommand(kasGrantsDeleteCmd) | ||
| kasGrantsDeleteCmd.Flags().StringP("attribute", "a", "", "Attribute Definition ID") | ||
| kasGrantsDeleteCmd.Flags().StringP("value", "v", "", "Attribute Value ID") | ||
| kasGrantsDeleteCmd.Flags().StringP("kas", "k", "", "Key Access Server (KAS) ID") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package handlers | ||
|
|
||
| import ( | ||
| "github.com/opentdf/platform/protocol/go/policy/attributes" | ||
| ) | ||
|
|
||
| func (h Handler) UpdateKasGrantForAttribute(attr_id string, kas_id string) (*attributes.AttributeKeyAccessServer, error) { | ||
| kas := &attributes.AttributeKeyAccessServer{ | ||
| AttributeId: attr_id, | ||
| KeyAccessServerId: kas_id, | ||
| } | ||
| resp, err := h.sdk.Attributes.AssignKeyAccessServerToAttribute(h.ctx, &attributes.AssignKeyAccessServerToAttributeRequest{ | ||
| AttributeKeyAccessServer: kas, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return resp.AttributeKeyAccessServer, nil | ||
| } | ||
|
|
||
| func (h Handler) DeleteKasGrantFromAttribute(attr_id string, kas_id string) (*attributes.AttributeKeyAccessServer, error) { | ||
| kas := &attributes.AttributeKeyAccessServer{ | ||
| AttributeId: attr_id, | ||
| KeyAccessServerId: kas_id, | ||
| } | ||
| resp, err := h.sdk.Attributes.RemoveKeyAccessServerFromAttribute(h.ctx, &attributes.RemoveKeyAccessServerFromAttributeRequest{ | ||
| AttributeKeyAccessServer: kas, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return resp.AttributeKeyAccessServer, nil | ||
| } | ||
|
|
||
| func (h Handler) UpdateKasGrantForValue(val_id string, kas_id string) (*attributes.ValueKeyAccessServer, error) { | ||
| kas := &attributes.ValueKeyAccessServer{ | ||
| ValueId: val_id, | ||
| KeyAccessServerId: kas_id, | ||
| } | ||
| resp, err := h.sdk.Attributes.AssignKeyAccessServerToValue(h.ctx, &attributes.AssignKeyAccessServerToValueRequest{ | ||
| ValueKeyAccessServer: kas, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return resp.ValueKeyAccessServer, nil | ||
| } | ||
|
|
||
| func (h Handler) DeleteKasGrantFromValue(val_id string, kas_id string) (*attributes.ValueKeyAccessServer, error) { | ||
| kas := &attributes.ValueKeyAccessServer{ | ||
| ValueId: val_id, | ||
| KeyAccessServerId: kas_id, | ||
| } | ||
| resp, err := h.sdk.Attributes.RemoveKeyAccessServerFromValue(h.ctx, &attributes.RemoveKeyAccessServerFromValueRequest{ | ||
| ValueKeyAccessServer: kas, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return resp.ValueKeyAccessServer, nil | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.