diff --git a/cmd/policy/registeredResources.go b/cmd/policy/registeredResources.go index 5a882f4a..011b7ca9 100644 --- a/cmd/policy/registeredResources.go +++ b/cmd/policy/registeredResources.go @@ -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}) @@ -44,6 +44,7 @@ func policyCreateRegisteredResource(cmd *cobra.Command, args []string) { rows := [][]string{ {"Id", resource.GetId()}, {"Name", resource.GetName()}, + {"Namespace", resource.GetNamespace().GetFqn()}, {"Values", cli.CommaSeparated(simpleRegResValues)}, } @@ -83,6 +84,7 @@ func policyGetRegisteredResource(cmd *cobra.Command, args []string) { rows := [][]string{ {"Id", resource.GetId()}, {"Name", resource.GetName()}, + {"Namespace", resource.GetNamespace().GetFqn()}, {"Values", cli.CommaSeparated(simpleRegResValues)}, } if mdRows := getMetadataRows(resource.GetMetadata()); mdRows != nil { @@ -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(), + "values": cli.CommaSeparated(simpleRegResValues), })) } t = t.WithRows(rows) @@ -151,6 +153,7 @@ func policyUpdateRegisteredResource(cmd *cobra.Command, args []string) { rows := [][]string{ {"Id", id}, {"Name", updated.GetName()}, + {"Namespace", updated.GetNamespace().GetFqn()}, } if mdRows := getMetadataRows(updated.GetMetadata()); mdRows != nil { rows = append(rows, mdRows...) @@ -186,6 +189,7 @@ func policyDeleteRegisteredResource(cmd *cobra.Command, args []string) { rows := [][]string{ {"Id", id}, {"Name", resource.GetName()}, + {"Namespace", resource.GetNamespace().GetFqn()}, } if mdRows := getMetadataRows(resource.GetMetadata()); mdRows != nil { rows = append(rows, mdRows...) diff --git a/docs/man/policy/registered-resources/create.md b/docs/man/policy/registered-resources/create.md index 374bc58d..cb9d085c 100644 --- a/docs/man/policy/registered-resources/create.md +++ b/docs/man/policy/registered-resources/create.md @@ -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) diff --git a/e2e/registered-resources.bats b/e2e/registered-resources.bats index 20c009da..4a39609f 100644 --- a/e2e/registered-resources.bats +++ b/e2e/registered-resources.bats @@ -67,9 +67,11 @@ 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" @@ -77,6 +79,16 @@ teardown_file() { # 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 } @test "Create a registered resource - Bad" { @@ -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" @@ -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 diff --git a/go.mod b/go.mod index 6585ae67..c56621ad 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index b6ce451a..cb4b04cd 100644 --- a/go.sum +++ b/go.sum @@ -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=