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
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
16 changes: 10 additions & 6 deletions cmd/policy/registeredResources.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func policyCreateRegisteredResource(cmd *cobra.Command, args []string) {
defer h.Close()

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

Expand All @@ -44,6 +44,7 @@ func policyCreateRegisteredResource(cmd *cobra.Command, args []string) {
rows := [][]string{
{"Id", resource.GetId()},
{"Name", resource.GetName()},
{"Namespace", resource.GetNamespace().GetFqn()},
Comment thread
alkalescent marked this conversation as resolved.
{"Values", cli.CommaSeparated(simpleRegResValues)},
}

Expand Down Expand Up @@ -83,6 +84,7 @@ func policyGetRegisteredResource(cmd *cobra.Command, args []string) {
rows := [][]string{
{"Id", resource.GetId()},
{"Name", resource.GetName()},
{"Namespace", resource.GetNamespace().GetFqn()},
Comment thread
alkalescent marked this conversation as resolved.
{"Values", cli.CommaSeparated(simpleRegResValues)},
}
if mdRows := getMetadataRows(resource.GetMetadata()); mdRows != nil {
Expand Down Expand Up @@ -110,17 +112,17 @@ func policyListRegisteredResources(cmd *cobra.Command, args []string) {
t := cli.NewTable(
cli.NewUUIDColumn(),
table.NewFlexColumn("name", "Name", cli.FlexColumnWidthFour),
table.NewFlexColumn("namespace", "Namespace", cli.FlexColumnWidthFour),
table.NewFlexColumn("values", "Values", cli.FlexColumnWidthTwo),
// todo: do we need to show metadata labels and created/updated at?
)
rows := []table.Row{}
for _, r := range resp.GetResources() {
simpleRegResValues := cli.GetSimpleRegisteredResourceValues(r.GetValues())
rows = append(rows, table.NewRow(table.RowData{
"id": r.GetId(),
"name": r.GetName(),
"values": cli.CommaSeparated(simpleRegResValues),
// todo: do we need to show metadata labels and created/updated at?
"id": r.GetId(),
"name": r.GetName(),
"namespace": r.GetNamespace().GetFqn(),
Comment thread
alkalescent marked this conversation as resolved.
"values": cli.CommaSeparated(simpleRegResValues),
}))
}
t = t.WithRows(rows)
Expand Down Expand Up @@ -151,6 +153,7 @@ func policyUpdateRegisteredResource(cmd *cobra.Command, args []string) {
rows := [][]string{
{"Id", id},
{"Name", updated.GetName()},
{"Namespace", updated.GetNamespace().GetFqn()},
Comment thread
alkalescent marked this conversation as resolved.
}
if mdRows := getMetadataRows(updated.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
Expand Down Expand Up @@ -186,6 +189,7 @@ func policyDeleteRegisteredResource(cmd *cobra.Command, args []string) {
rows := [][]string{
{"Id", id},
{"Name", resource.GetName()},
{"Namespace", resource.GetNamespace().GetFqn()},
Comment thread
alkalescent marked this conversation as resolved.
}
if mdRows := getMetadataRows(resource.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
Expand Down
1 change: 0 additions & 1 deletion docs/man/policy/registered-resources/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ command:
- name: namespace
shorthand: s
description: Namespace ID or FQN
required: true
- name: value
shorthand: v
description: Value of the registered resource (i.e. 'value1', must be unique within the Registered Resource)
Expand Down
16 changes: 13 additions & 3 deletions e2e/registered-resources.bats
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,28 @@ teardown_file() {
}

@test "Create a registered resource - Good" {
# with a namespace
run_otdfctl_reg_res create --name test_create_rr --namespace "$NS_ID"
assert_output --partial "SUCCESS"
assert_line --regexp "Name.*test_create_rr"
assert_line --regexp "Namespace.*https://$NS_NAME"
assert_output --partial "Id"
assert_output --partial "Created At"
assert_line --partial "Updated At"

# cleanup
created_id=$(echo "$output" | grep Id | awk -F'│' '{print $3}' | xargs)
run_otdfctl_reg_res delete --id $created_id --force

# without a namespace (should default to un-namespaced)
run_otdfctl_reg_res create --name test_create_rr_no_ns --json
assert_success
[ "$(echo "$output" | jq -r '.name')" = "test_create_rr_no_ns" ]
# ensure namespace is empty for un-namespaced resources
[ "$(echo "$output" | jq -r '.namespace.fqn // empty')" = "" ]

created_id=$(echo "$output" | jq -r '.id')
run_otdfctl_reg_res delete --id $created_id --force
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

@test "Create a registered resource - Bad" {
Expand All @@ -92,9 +104,6 @@ teardown_file() {
run_otdfctl_reg_res create
assert_failure
assert_output --partial "Flag '--name' is required"
run_otdfctl_reg_res create --name test_no_namespace
assert_failure
assert_output --partial "Flag '--namespace' is required"

# conflict
run_otdfctl_reg_res create --name test_create_rr_conflict --namespace "$NS_ID"
Expand Down Expand Up @@ -131,6 +140,7 @@ teardown_file() {
assert_success
[ "$(echo "$output" | jq -r '.id')" = "$created_id" ]
[ "$(echo "$output" | jq -r '.name')" = "test_get_rr" ]
[ "$(echo "$output" | jq -r '.namespace.fqn')" = "https://$NS_NAME" ]

# get by name + namespace FQN
run_otdfctl_reg_res get --name test_get_rr --namespace "https://$NS_NAME" --json
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/opentdf/platform/lib/flattening v0.1.3
github.com/opentdf/platform/lib/identifier v0.3.0
github.com/opentdf/platform/lib/ocrypto v0.10.0
github.com/opentdf/platform/protocol/go v0.20.0
github.com/opentdf/platform/protocol/go v0.21.0
github.com/opentdf/platform/sdk v0.15.0
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ github.com/opentdf/platform/lib/identifier v0.3.0 h1:kLVRVC8wE0kmuEIdodEhqIRym5O
github.com/opentdf/platform/lib/identifier v0.3.0/go.mod h1:3RlXYY9sxH/VnMkgm/M6zryUrtBL0lnsOVyqb0hYYvs=
github.com/opentdf/platform/lib/ocrypto v0.10.0 h1:7dn/z/1qH3p+gWCrfOoU7hj9XF/p5N+b2JBJuWF9aK0=
github.com/opentdf/platform/lib/ocrypto v0.10.0/go.mod h1:WASkoHreqgTFImB/gJW42VTdpi9AkgkmaW19y/fU+Ew=
github.com/opentdf/platform/protocol/go v0.20.0 h1:ZmKTkCyYl/pvylIiih2krKtuEUMEPXtsscmmqXFQaZg=
github.com/opentdf/platform/protocol/go v0.20.0/go.mod h1:jeDa0o2jce1yELNxZ92hscz0mxxqq7GtqC9EoYCpNW0=
github.com/opentdf/platform/protocol/go v0.21.0 h1:OZo/GqdIDQMbICx0tVdFHaFjl8CpILTIt8dS9bLYSRI=
github.com/opentdf/platform/protocol/go v0.21.0/go.mod h1:ufSzLVpcGv368L++kni7fzbN4ugtxmstcifmwI/o4T0=
github.com/opentdf/platform/sdk v0.15.0 h1:TAZJzC4RDlHLuMN562OhoVGykKxyEp+C1c5o9F31080=
github.com/opentdf/platform/sdk v0.15.0/go.mod h1:0u/1tDFkt2eL9W/2DzbHIF0ziel5F7Sn/OJp5EkbeRg=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
Loading