-
Notifications
You must be signed in to change notification settings - Fork 6
feat(core): Resource mapping groups #567
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 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d51c6d6
add resource mapping groups
elizabethhealy dd9ea75
gemeni suggestions, some tests
elizabethhealy b8ddd15
linting
elizabethhealy 6a406d1
other tests, some fixes
elizabethhealy 2cb4d32
update cleanup
elizabethhealy 6c5c41e
Merge branch 'main' into dspx-1075-add-resource-mapping-groups
elizabethhealy 18a400d
fix tests
elizabethhealy 3953848
Merge branch 'dspx-1075-add-resource-mapping-groups' of https://githu…
elizabethhealy 217d78b
debugging update
elizabethhealy 05dba5c
fix tests
elizabethhealy 6dbef6f
fix
elizabethhealy 26b11de
remove unnecessary package
elizabethhealy 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,226 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| _ "embed" | ||
| "fmt" | ||
|
|
||
| "github.com/evertras/bubble-table/table" | ||
| "github.com/opentdf/otdfctl/pkg/cli" | ||
| "github.com/opentdf/otdfctl/pkg/man" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var ( | ||
| policyResourceMappingGroupsCmd *cobra.Command | ||
| ) | ||
|
|
||
| func policyCreateResourceMappingGroup(cmd *cobra.Command, args []string) { | ||
| c := cli.New(cmd, args) | ||
| h := NewHandler(c) | ||
| defer h.Close() | ||
|
|
||
| nsID := c.Flags.GetRequiredID("namespace-id") | ||
| name := c.Flags.GetRequiredString("name") | ||
| metadataLabels = c.Flags.GetStringSlice("label", metadataLabels, cli.FlagsStringSliceOptions{Min: 0}) | ||
|
|
||
| resourceMappingGroup, err := h.CreateResourceMappingGroup(nsID, name, getMetadataMutable(metadataLabels)) | ||
| if err != nil { | ||
| cli.ExitWithError("Failed to create resource mapping group", err) | ||
| } | ||
| rows := [][]string{ | ||
| {"Id", resourceMappingGroup.GetId()}, | ||
| {"Namespace Id", resourceMappingGroup.GetNamespaceId()}, | ||
| {"Group Name", resourceMappingGroup.GetName()}, | ||
| } | ||
| if mdRows := getMetadataRows(resourceMappingGroup.GetMetadata()); mdRows != nil { | ||
| rows = append(rows, mdRows...) | ||
| } | ||
| t := cli.NewTabular(rows...) | ||
| HandleSuccess(cmd, resourceMappingGroup.GetId(), t, resourceMappingGroup) | ||
| } | ||
|
|
||
| func policyGetResourceMappingGroup(cmd *cobra.Command, args []string) { | ||
| c := cli.New(cmd, args) | ||
| h := NewHandler(c) | ||
| defer h.Close() | ||
|
|
||
| id := c.Flags.GetRequiredID("id") | ||
|
|
||
| resourceMappingGroup, err := h.GetResourceMappingGroup(id) | ||
| if err != nil { | ||
| cli.ExitWithError(fmt.Sprintf("Failed to get resource mapping group (%s)", id), err) | ||
| } | ||
| rows := [][]string{ | ||
| {"Id", resourceMappingGroup.GetId()}, | ||
| {"Namespace Id", resourceMappingGroup.GetNamespaceId()}, | ||
| {"Group Name", resourceMappingGroup.GetName()}, | ||
| } | ||
| if mdRows := getMetadataRows(resourceMappingGroup.GetMetadata()); mdRows != nil { | ||
| rows = append(rows, mdRows...) | ||
| } | ||
| t := cli.NewTabular(rows...) | ||
| HandleSuccess(cmd, resourceMappingGroup.GetId(), t, resourceMappingGroup) | ||
| } | ||
|
|
||
| func policyListResourceMappingGroups(cmd *cobra.Command, args []string) { | ||
| c := cli.New(cmd, args) | ||
| h := NewHandler(c) | ||
| defer h.Close() | ||
|
|
||
| limit := c.Flags.GetRequiredInt32("limit") | ||
| offset := c.Flags.GetRequiredInt32("offset") | ||
|
|
||
| rmgList, page, err := h.ListResourceMappingGroups(cmd.Context(), limit, offset) | ||
| if err != nil { | ||
| cli.ExitWithError("Failed to list resource mapping groups", err) | ||
| } | ||
|
|
||
| t := cli.NewTable( | ||
| cli.NewUUIDColumn(), | ||
| table.NewFlexColumn("ns_id", "Namespace ID", cli.FlexColumnWidthFour), | ||
| table.NewFlexColumn("name", "Name", cli.FlexColumnWidthFour), | ||
| table.NewFlexColumn("labels", "Labels", cli.FlexColumnWidthOne), | ||
| table.NewFlexColumn("created_at", "Created At", cli.FlexColumnWidthOne), | ||
| table.NewFlexColumn("updated_at", "Updated At", cli.FlexColumnWidthOne), | ||
| ) | ||
| rows := []table.Row{} | ||
| for _, rmg := range rmgList { | ||
| metadata := cli.ConstructMetadata(rmg.GetMetadata()) | ||
| rows = append(rows, table.NewRow(table.RowData{ | ||
| "id": rmg.GetId(), | ||
| "ns_id": rmg.GetNamespaceId(), | ||
| "name": rmg.GetName(), | ||
| "labels": metadata["Labels"], | ||
| "created_at": metadata["Created At"], | ||
| "updated_at": metadata["Updated At"], | ||
| })) | ||
| } | ||
| t = t.WithRows(rows) | ||
| t = cli.WithListPaginationFooter(t, page) | ||
| HandleSuccess(cmd, "", t, rmgList) | ||
| } | ||
|
|
||
| func policyUpdateResourceMappingGroup(cmd *cobra.Command, args []string) { | ||
| c := cli.New(cmd, args) | ||
| h := NewHandler(c) | ||
| defer h.Close() | ||
|
|
||
| id := c.Flags.GetRequiredID("id") | ||
| nsID := c.Flags.GetOptionalID("namespace-id") | ||
| name := c.Flags.GetOptionalString("name") | ||
| metadataLabels = c.Flags.GetStringSlice("label", metadataLabels, cli.FlagsStringSliceOptions{Min: 0}) | ||
|
|
||
| resourceMappingGroup, err := h.UpdateResourceMappingGroup(id, nsID, name, getMetadataMutable(metadataLabels), getMetadataUpdateBehavior()) | ||
| if err != nil { | ||
| cli.ExitWithError(fmt.Sprintf("Failed to update resource mapping group (%s)", id), err) | ||
| } | ||
| rows := [][]string{ | ||
| {"Id", resourceMappingGroup.GetId()}, | ||
| {"Namespace Id", resourceMappingGroup.GetNamespaceId()}, | ||
| {"Group Name", resourceMappingGroup.GetName()}, | ||
| } | ||
| if mdRows := getMetadataRows(resourceMappingGroup.GetMetadata()); mdRows != nil { | ||
| rows = append(rows, mdRows...) | ||
| } | ||
| t := cli.NewTabular(rows...) | ||
| HandleSuccess(cmd, resourceMappingGroup.GetId(), t, resourceMappingGroup) | ||
| } | ||
|
|
||
| func policyDeleteResourceMappingGroup(cmd *cobra.Command, args []string) { | ||
| c := cli.New(cmd, args) | ||
| h := NewHandler(c) | ||
| defer h.Close() | ||
|
|
||
| id := c.Flags.GetRequiredID("id") | ||
| force := c.Flags.GetOptionalBool("force") | ||
|
|
||
| cli.ConfirmAction(cli.ActionDelete, "resource-mapping-group", id, force) | ||
|
|
||
| resourceMappingGroup, err := h.GetResourceMappingGroup(id) | ||
| if err != nil { | ||
| cli.ExitWithError(fmt.Sprintf("Failed to get resource mapping group for delete (%s)", id), err) | ||
| } | ||
|
|
||
| _, err = h.DeleteResourceMappingGroup(id) | ||
| if err != nil { | ||
| cli.ExitWithError(fmt.Sprintf("Failed to delete resource mapping group (%s)", id), err) | ||
| } | ||
| rows := [][]string{ | ||
| {"Id", resourceMappingGroup.GetId()}, | ||
| {"Namespace Id", resourceMappingGroup.GetNamespaceId()}, | ||
| {"Group Name", resourceMappingGroup.GetName()}, | ||
| } | ||
| t := cli.NewTabular(rows...) | ||
| HandleSuccess(cmd, resourceMappingGroup.GetId(), t, resourceMappingGroup) | ||
| } | ||
|
|
||
| func init() { | ||
| createDoc := man.Docs.GetCommand("policy/resource-mapping-groups/create", | ||
| man.WithRun(policyCreateResourceMappingGroup), | ||
| ) | ||
| createDoc.Flags().String( | ||
| createDoc.GetDocFlag("namespace-id").Name, | ||
| createDoc.GetDocFlag("namespace-id").Default, | ||
| createDoc.GetDocFlag("namespace-id").Description, | ||
| ) | ||
| createDoc.Flags().String( | ||
| createDoc.GetDocFlag("name").Name, | ||
| createDoc.GetDocFlag("name").Default, | ||
| createDoc.GetDocFlag("name").Description, | ||
| ) | ||
| injectLabelFlags(&createDoc.Command, false) | ||
|
|
||
| getDoc := man.Docs.GetCommand("policy/resource-mapping-groups/get", | ||
| man.WithRun(policyGetResourceMappingGroup), | ||
| ) | ||
| getDoc.Flags().String( | ||
| getDoc.GetDocFlag("id").Name, | ||
| getDoc.GetDocFlag("id").Default, | ||
| getDoc.GetDocFlag("id").Description, | ||
| ) | ||
|
|
||
| listDoc := man.Docs.GetCommand("policy/resource-mapping-groups/list", | ||
| man.WithRun(policyListResourceMappingGroups), | ||
| ) | ||
| injectListPaginationFlags(listDoc) | ||
|
|
||
| updateDoc := man.Docs.GetCommand("policy/resource-mapping-groups/update", | ||
| man.WithRun(policyUpdateResourceMappingGroup), | ||
| ) | ||
| updateDoc.Flags().String( | ||
| updateDoc.GetDocFlag("id").Name, | ||
| updateDoc.GetDocFlag("id").Default, | ||
| updateDoc.GetDocFlag("id").Description, | ||
| ) | ||
| updateDoc.Flags().String( | ||
| updateDoc.GetDocFlag("namespace-id").Name, | ||
| updateDoc.GetDocFlag("namespace-id").Default, | ||
| updateDoc.GetDocFlag("namespace-id").Description, | ||
| ) | ||
| updateDoc.Flags().String( | ||
| updateDoc.GetDocFlag("name").Name, | ||
| updateDoc.GetDocFlag("name").Default, | ||
| updateDoc.GetDocFlag("name").Description, | ||
| ) | ||
| injectLabelFlags(&updateDoc.Command, true) | ||
|
|
||
| deleteDoc := man.Docs.GetCommand("policy/resource-mapping-groups/delete", | ||
| man.WithRun(policyDeleteResourceMappingGroup), | ||
| ) | ||
| deleteDoc.Flags().String( | ||
| deleteDoc.GetDocFlag("id").Name, | ||
| deleteDoc.GetDocFlag("id").Default, | ||
| deleteDoc.GetDocFlag("id").Description, | ||
| ) | ||
| deleteDoc.Flags().Bool( | ||
| deleteDoc.GetDocFlag("force").Name, | ||
| false, | ||
| deleteDoc.GetDocFlag("force").Description, | ||
| ) | ||
|
|
||
| doc := man.Docs.GetCommand("policy/resource-mapping-groups", | ||
| man.WithSubcommands(createDoc, getDoc, listDoc, updateDoc, deleteDoc), | ||
| ) | ||
| policyResourceMappingGroupsCmd = &doc.Command | ||
| policyCmd.AddCommand(policyResourceMappingGroupsCmd) | ||
| } | ||
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
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,11 @@ | ||
| --- | ||
| title: Manage resource mapping groups | ||
| command: | ||
| name: resource-mapping-groups | ||
| aliases: | ||
| - resmg | ||
elizabethhealy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - remapgrp | ||
elizabethhealy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - resource-mapping-group | ||
| --- | ||
|
|
||
| Resource mapping groups allow you to organize multiple resource mappings into logical collections. By grouping related resource mappings, you can manage sets of resources more efficiently. This is useful for scenarios where resources share common access controls or need to be managed together as a unit. | ||
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,30 @@ | ||
| --- | ||
| title: Create a resource mapping group | ||
| command: | ||
| name: create | ||
| aliases: | ||
| - add | ||
| - new | ||
| - c | ||
| flags: | ||
| - name: namespace-id | ||
| description: The ID of the namespace of the group | ||
| default: '' | ||
| - name: name | ||
| description: The name of the group | ||
| default: '' | ||
| - name: label | ||
| description: "Optional metadata 'labels' in the format: key=value" | ||
| shorthand: l | ||
| default: '' | ||
| --- | ||
|
|
||
| Create a new group to organize resource mappings. Resource mapping groups belong to a namespace and are identified by a name. | ||
|
|
||
| For more information about resource mapping groups, see the `resource-mapping-groups` subcommand. | ||
elizabethhealy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Examples | ||
|
|
||
| ```shell | ||
elizabethhealy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| otdfctl policy resource-mapping-groups create --namespace-id 891cfe85-b381-4f85-9699-5f7dbfe2a9ab --name my-group | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
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.