diff --git a/cmd/policy/namespaces.go b/cmd/policy/namespaces.go index 6269944b..737c9511 100644 --- a/cmd/policy/namespaces.go +++ b/cmd/policy/namespaces.go @@ -22,11 +22,15 @@ func getAttributeNamespace(cmd *cobra.Command, args []string) { h := common.NewHandler(c) defer h.Close() - id := c.Flags.GetRequiredID("id") + // Load from the mutually exclusive flags + identifier := c.FlagHelper.GetOptionalString("id") + if identifier == "" { + identifier = c.FlagHelper.GetOptionalString("fqn") + } - ns, err := h.GetNamespace(cmd.Context(), id) + ns, err := h.GetNamespace(cmd.Context(), identifier) if err != nil { - errMsg := fmt.Sprintf("Failed to get namespace (%s)", id) + errMsg := fmt.Sprintf("Failed to get namespace (%s)", identifier) cli.ExitWithError(errMsg, err) } @@ -324,12 +328,21 @@ func initNamespacesCommands() { getCmd := man.Docs.GetCommand("policy/attributes/namespaces/get", man.WithRun(getAttributeNamespace), ) + flags := []string{"fqn", "id"} getCmd.Flags().StringP( getCmd.GetDocFlag("id").Name, getCmd.GetDocFlag("id").Shorthand, getCmd.GetDocFlag("id").Default, getCmd.GetDocFlag("id").Description, ) + getCmd.Flags().StringP( + getCmd.GetDocFlag("fqn").Name, + getCmd.GetDocFlag("fqn").Shorthand, + getCmd.GetDocFlag("fqn").Default, + getCmd.GetDocFlag("fqn").Description, + ) + getCmd.MarkFlagsMutuallyExclusive(flags...) + getCmd.MarkFlagsOneRequired(flags...) listCmd := man.Docs.GetCommand("policy/attributes/namespaces/list", man.WithRun(listAttributeNamespaces), diff --git a/docs/man/policy/attributes/namespaces/get.md b/docs/man/policy/attributes/namespaces/get.md index 0e746e01..3ee82307 100644 --- a/docs/man/policy/attributes/namespaces/get.md +++ b/docs/man/policy/attributes/namespaces/get.md @@ -5,6 +5,9 @@ command: aliases: - g flags: + - name: fqn + shorthand: f + description: FQN of the attribute namespace - name: id shorthand: i description: ID of the attribute namespace @@ -16,4 +19,7 @@ For more information, see the `namespaces` subcommand. ```shell otdfctl policy attributes namespaces get --id=7650f02a-be00-4faa-a1d1-37cded5e23dc -``` \ No newline at end of file +``` +```shell +otdfctl policy attributes namespaces get --fqn=https://opentdf.io # OpenTDF currently requires the protocol be included with the FQN +``` diff --git a/e2e/namespaces.bats b/e2e/namespaces.bats index 699acedf..44046e31 100755 --- a/e2e/namespaces.bats +++ b/e2e/namespaces.bats @@ -15,6 +15,7 @@ setup_file() { export NS_NAME_UPDATE="updated-test-ns.net" export NS_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes namespaces create -n "$NS_NAME" --json | jq -r '.id') export NS_ID_FLAG="--id $NS_ID" + export NS_FQN_FLAG="--fqn https://${NS_NAME}" export KAS_URI="https://test-kas-for-namespace.com" export KAS_REG_ID=$(./otdfctl $HOST $WITH_CREDS policy kas-registry create --uri "$KAS_URI" --json | jq -r '.id') @@ -81,16 +82,32 @@ teardown_file() { assert_line --regexp "Id.*$NS_ID" assert_line --regexp "Name.*$NS_NAME" + run_otdfctl_ns get "$NS_FQN_FLAG" + assert_success + assert_line --regexp "Id.*$NS_ID" + assert_line --regexp "Name.*$NS_NAME" + run_otdfctl_ns get "$NS_ID_FLAG" --json assert_success [ "$(echo "$output" | jq -r '.id')" = "$NS_ID" ] [ "$(echo "$output" | jq -r '.name')" = "$NS_NAME" ] + + run_otdfctl_ns get "$NS_FQN_FLAG" --json + assert_success + [ "$(echo "$output" | jq -r '.id')" = "$NS_ID" ] + [ "$(echo "$output" | jq -r '.name')" = "$NS_NAME" ] } @test "Get a namespace - Bad" { run_otdfctl_ns get assert_failure - assert_output --partial "Flag '--id' is required" + assert_output --partial "Error: at least one of the flags in the group" + assert_output --partial "fqn" + assert_output --partial "id" + + run_otdfctl_ns get "$NS_ID_FLAG" "$NS_FQN_FLAG" + assert_failure + assert_output --partial "[fqn id] were all set" run_otdfctl_ns get --id 'example.com' assert_failure