Skip to content
This repository was archived by the owner on Apr 28, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2884e49
require namespace in otdfctl actions commands and re-enable actions/R…
elizabethhealy Mar 12, 2026
5e96d4d
updates based on comments
elizabethhealy Mar 12, 2026
3cb5c69
add helper
elizabethhealy Mar 12, 2026
7bafdd0
Merge branch 'main' into dspx-2540-add-namespaced-actions-support
elizabethhealy Mar 12, 2026
46ba054
linting
elizabethhealy Mar 12, 2026
8265070
Merge branch 'dspx-2540-add-namespaced-actions-support' of https://gi…
elizabethhealy Mar 12, 2026
59cfa49
update protocol version, add bats
elizabethhealy Mar 12, 2026
ed6ca5f
unskip bats
elizabethhealy Mar 12, 2026
0b8f199
fix bats
elizabethhealy Mar 12, 2026
408ca4a
undo change to update action
elizabethhealy Mar 12, 2026
609dbeb
test against branch
elizabethhealy Mar 12, 2026
55db843
update bats with standard action create error
elizabethhealy Mar 12, 2026
203c1e8
move back to main
elizabethhealy Mar 13, 2026
ecc6f29
dont require namespace, test against branch
elizabethhealy Mar 13, 2026
e55aa94
add namespace to output
elizabethhealy Mar 13, 2026
5c10bd7
handle possibly null namespace
elizabethhealy Mar 13, 2026
2b2f598
change ref back
elizabethhealy Mar 24, 2026
155eaf1
Merge branch 'main' into dspx-2540-add-namespaced-actions-support
elizabethhealy Mar 24, 2026
4730127
optional on create
elizabethhealy Mar 24, 2026
e8ae5f1
suggestions
elizabethhealy Mar 24, 2026
1a1be87
coderabbit suggestions
elizabethhealy Mar 24, 2026
970e905
some bats fixes
elizabethhealy Mar 24, 2026
2c9caa6
coderabbit suggestion
elizabethhealy Mar 24, 2026
1020eee
debugging
elizabethhealy Mar 24, 2026
94feb41
fix test
elizabethhealy Mar 24, 2026
19f8881
review suggestions
elizabethhealy Mar 25, 2026
7eb3876
better list test
elizabethhealy Mar 25, 2026
8c13444
update comment
elizabethhealy Mar 25, 2026
43daf53
fix namespace chaining
elizabethhealy Mar 25, 2026
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
42 changes: 36 additions & 6 deletions cmd/policy/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ func policyGetAction(cmd *cobra.Command, args []string) {

id := c.Flags.GetOptionalID("id")
name := c.Flags.GetOptionalString("name")
// TODO: switch to required namespace if id not provided once namespacing is required by policy
namespace := c.Flags.GetOptionalString("namespace")

if id == "" && name == "" {
cli.ExitWithError("Either 'id' or 'name' must be provided", nil)
}

action, err := h.GetAction(cmd.Context(), id, name)
action, err := h.GetAction(cmd.Context(), id, name, namespace)
if err != nil {
identifier := fmt.Sprintf("id: %s", id)
if id == "" {
Expand All @@ -35,6 +37,7 @@ func policyGetAction(cmd *cobra.Command, args []string) {
rows := [][]string{
{"Id", action.GetId()},
{"Name", action.GetName()},
{"Namespace", action.GetNamespace().GetFqn()},
}
if mdRows := getMetadataRows(action.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
Expand All @@ -51,29 +54,34 @@ func policyListActions(cmd *cobra.Command, args []string) {

limit := c.Flags.GetRequiredInt32("limit")
offset := c.Flags.GetRequiredInt32("offset")
namespace := c.Flags.GetOptionalString("namespace")

resp, err := h.ListActions(cmd.Context(), limit, offset)
resp, err := h.ListActions(cmd.Context(), limit, offset, namespace)
if err != nil {
cli.ExitWithError("Failed to list actions", err)
}
t := cli.NewTable(
cli.NewUUIDColumn(),
table.NewFlexColumn("name", "Name", cli.FlexColumnWidthFour),
table.NewFlexColumn("action_type", "Action Type", cli.FlexColumnWidthFour),
table.NewFlexColumn("namespace", "Namespace", cli.FlexColumnWidthFour),
)
rows := []table.Row{}
for _, a := range resp.GetActionsStandard() {
rows = append(rows, table.NewRow(table.RowData{
"id": a.GetId(),
"action_type": "standard",
"name": a.GetName(),
"namespace": a.GetNamespace().GetFqn(),
}))
}

for _, a := range resp.GetActionsCustom() {
rows = append(rows, table.NewRow(table.RowData{
"id": a.GetId(),
"action_type": "custom",
"name": a.GetName(),
"namespace": a.GetNamespace().GetFqn(),
}))
}

Expand All @@ -88,16 +96,18 @@ func policyCreateAction(cmd *cobra.Command, args []string) {
defer h.Close()

name := c.Flags.GetRequiredString("name")
namespace := c.Flags.GetOptionalString("namespace")
metadataLabels = c.Flags.GetStringSlice("label", metadataLabels, cli.FlagsStringSliceOptions{Min: 0})

action, err := h.CreateAction(cmd.Context(), name, getMetadataMutable(metadataLabels))
action, err := h.CreateAction(cmd.Context(), name, namespace, getMetadataMutable(metadataLabels))
Comment thread
elizabethhealy marked this conversation as resolved.
if err != nil {
cli.ExitWithError("Failed to create action", err)
}

rows := [][]string{
{"Id", action.GetId()},
{"Name", action.GetName()},
{"Namespace", action.GetNamespace().GetFqn()},
}

if mdRows := getMetadataRows(action.GetMetadata()); mdRows != nil {
Expand All @@ -117,7 +127,7 @@ func policyDeleteAction(cmd *cobra.Command, args []string) {
force := c.Flags.GetOptionalBool("force")
ctx := cmd.Context()

action, err := h.GetAction(ctx, id, "")
action, err := h.GetAction(ctx, id, "", "")
if err != nil {
errMsg := fmt.Sprintf("Failed to find action (%s)", id)
cli.ExitWithError(errMsg, err)
Expand All @@ -130,7 +140,11 @@ func policyDeleteAction(cmd *cobra.Command, args []string) {
errMsg := fmt.Sprintf("Failed to delete action (%s)", id)
cli.ExitWithError(errMsg, err)
}
rows := [][]string{{"Id", id}, {"Name", action.GetName()}}
rows := [][]string{
{"Id", id},
{"Name", action.GetName()},
{"Namespace", action.GetNamespace().GetFqn()},
}
if mdRows := getMetadataRows(action.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
Expand All @@ -157,7 +171,11 @@ func policyUpdateAction(cmd *cobra.Command, args []string) {
if err != nil {
cli.ExitWithError("Failed to update action", err)
}
rows := [][]string{{"Id", id}, {"Name", updated.GetName()}}
rows := [][]string{
{"Id", id},
{"Name", updated.GetName()},
{"Namespace", updated.GetNamespace().GetFqn()},
}
if mdRows := getMetadataRows(updated.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
Expand All @@ -166,6 +184,15 @@ func policyUpdateAction(cmd *cobra.Command, args []string) {
common.HandleSuccess(cmd, id, t, updated)
}

func injectNamespaceFlag(doc *man.Doc) {
doc.Flags().StringP(
doc.GetDocFlag("namespace").Name,
doc.GetDocFlag("namespace").Shorthand,
doc.GetDocFlag("namespace").Default,
doc.GetDocFlag("namespace").Description,
)
}

func initActionsCommands() {
getDoc := man.Docs.GetCommand("policy/actions/get",
man.WithRun(policyGetAction),
Expand All @@ -182,10 +209,12 @@ func initActionsCommands() {
getDoc.GetDocFlag("name").Default,
getDoc.GetDocFlag("name").Description,
)
injectNamespaceFlag(getDoc)

listDoc := man.Docs.GetCommand("policy/actions/list",
man.WithRun(policyListActions),
)
injectNamespaceFlag(listDoc)
injectListPaginationFlags(listDoc)

createDoc := man.Docs.GetCommand("policy/actions/create",
Expand All @@ -197,6 +226,7 @@ func initActionsCommands() {
createDoc.GetDocFlag("name").Default,
createDoc.GetDocFlag("name").Description,
)
injectNamespaceFlag(createDoc)
injectLabelFlags(&createDoc.Command, false)

updateDoc := man.Docs.GetCommand("policy/actions/update",
Expand Down
4 changes: 2 additions & 2 deletions docs/man/policy/actions/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Standard Actions in Policy are comprised of the below, and only their metadata l
- update
- delete

Custom Actions known to Policy are admin-defined, globally unique (not namespaced), and will be lower
Custom Actions known to Policy are admin-defined, unique within a namespace, and will be lower
cased when stored. They may contain underscores (`_`) or hyphens (`-`) if preceded or followed
by an alphanumeric character. For example:
- download
- queue-to-print
- send_email

For more information about entitlement and Subject Mappings, see the `subject-mappings` command.
For more information about entitlement and Subject Mappings, see the `subject-mappings` command.
11 changes: 6 additions & 5 deletions docs/man/policy/actions/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ command:
flags:
- name: name
shorthand: n
description: Name of the custom action (must be unique within Policy)
description: Name of the custom action (must be unique within a namespace)
required: true
- name: namespace
shorthand: s
description: Namespace ID or FQN
- name: label
description: "Optional metadata 'labels' in the format: key=value"
shorthand: l
Expand All @@ -20,8 +23,7 @@ command:
Add a custom `action` to the platform Policy.

An Action `name` is normalized to lower case and may contain underscores (`_`) or hyphens (`-`)
between other alphanumeric characters. Each name must be globally unique as actions are not
namespaced.
between other alphanumeric characters. Each name must be unique within a namespace.

For more information, see the `actions` subcommand.

Expand All @@ -30,6 +32,5 @@ For more information, see the `actions` subcommand.
Create a custom action named 'install_package':

```shell
otdfctl policy actions create --name install_package
otdfctl policy actions create --name install_package --namespace https://example.com
```

7 changes: 6 additions & 1 deletion docs/man/policy/actions/get.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ command:
- name: name
shorthand: n
description: Name of the action
- name: namespace
shorthand: s
description: Namespace ID or FQN
---

If both `id` and `name` flag values are provided, `id` is preferred.

When using `--name`, `--namespace` is required.

For more information about Actions, see the manual for the `actions` subcommand.

## Example
Expand All @@ -28,5 +33,5 @@ otdfctl policy actions get --id e1402c63-eeaa-45e2-85d2-b939d135941f
Get by Name:

```shell
otdfctl policy actions get --name read
otdfctl policy actions get --name read --namespace https://example.com
```
5 changes: 4 additions & 1 deletion docs/man/policy/actions/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ command:
aliases:
- l
flags:
- name: namespace
shorthand: s
description: Namespace ID or FQN
- name: limit
shorthand: l
description: Limit retrieved count
Expand All @@ -18,5 +21,5 @@ For more information about Actions, see the manual for the `actions` subcommand.
## Example

```shell
otdfctl policy actions list
otdfctl policy actions list --namespace https://example.com
```
2 changes: 1 addition & 1 deletion docs/man/policy/actions/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ command:
required: true
- name: name
shorthand: n
description: Optional updated name of the custom action (must be unique within Policy)
description: Optional updated name of the custom action (must be unique within a namespace)
- name: label
description: "Optional metadata 'labels' in the format: key=value"
shorthand: l
Expand Down
Loading
Loading