Skip to content
This repository was archived by the owner on Apr 28, 2026. It is now read-only.

Commit 972e3bd

Browse files
committed
feat(core): Add namespace get/query by FQN
Signed-off-by: Aaron Covrig <aaron.covrig.us@ieee.org>
1 parent 77ebbb4 commit 972e3bd

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

cmd/policy/namespaces.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ func getAttributeNamespace(cmd *cobra.Command, args []string) {
2222
h := common.NewHandler(c)
2323
defer h.Close()
2424

25-
id := c.Flags.GetRequiredID("id")
25+
// Load from the mutually exclusive flags
26+
identifier := c.FlagHelper.GetOptionalString("id")
27+
if identifier == "" {
28+
identifier = c.FlagHelper.GetOptionalString("fqn")
29+
}
2630

27-
ns, err := h.GetNamespace(cmd.Context(), id)
31+
ns, err := h.GetNamespace(cmd.Context(), identifier)
2832
if err != nil {
29-
errMsg := fmt.Sprintf("Failed to get namespace (%s)", id)
33+
errMsg := fmt.Sprintf("Failed to get namespace (%s)", identifier)
3034
cli.ExitWithError(errMsg, err)
3135
}
3236

@@ -324,12 +328,21 @@ func initNamespacesCommands() {
324328
getCmd := man.Docs.GetCommand("policy/attributes/namespaces/get",
325329
man.WithRun(getAttributeNamespace),
326330
)
331+
flags := []string{"fqn", "id"}
327332
getCmd.Flags().StringP(
328333
getCmd.GetDocFlag("id").Name,
329334
getCmd.GetDocFlag("id").Shorthand,
330335
getCmd.GetDocFlag("id").Default,
331336
getCmd.GetDocFlag("id").Description,
332337
)
338+
getCmd.Flags().StringP(
339+
getCmd.GetDocFlag("fqn").Name,
340+
getCmd.GetDocFlag("fqn").Shorthand,
341+
getCmd.GetDocFlag("fqn").Default,
342+
getCmd.GetDocFlag("fqn").Description,
343+
)
344+
getCmd.MarkFlagsMutuallyExclusive(flags...)
345+
getCmd.MarkFlagsOneRequired(flags...)
333346

334347
listCmd := man.Docs.GetCommand("policy/attributes/namespaces/list",
335348
man.WithRun(listAttributeNamespaces),

docs/man/policy/attributes/namespaces/get.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ command:
55
aliases:
66
- g
77
flags:
8+
- name: fqn
9+
shorthand: f
10+
description: FQN of the attribute namespace
811
- name: id
912
shorthand: i
1013
description: ID of the attribute namespace
@@ -16,4 +19,7 @@ For more information, see the `namespaces` subcommand.
1619

1720
```shell
1821
otdfctl policy attributes namespaces get --id=7650f02a-be00-4faa-a1d1-37cded5e23dc
19-
```
22+
```
23+
```shell
24+
otdfctl policy attributes namespaces get --fqn=https://opentdf.io # OpenTDF currently requires the protocol be included with the FQN
25+
```

e2e/namespaces.bats

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ setup_file() {
1515
export NS_NAME_UPDATE="updated-test-ns.net"
1616
export NS_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes namespaces create -n "$NS_NAME" --json | jq -r '.id')
1717
export NS_ID_FLAG="--id $NS_ID"
18+
export NS_FQN_FLAG="--fqn $NS_NAME"
1819

1920
export KAS_URI="https://test-kas-for-namespace.com"
2021
export KAS_REG_ID=$(./otdfctl $HOST $WITH_CREDS policy kas-registry create --uri "$KAS_URI" --json | jq -r '.id')
@@ -81,17 +82,31 @@ teardown_file() {
8182
assert_line --regexp "Id.*$NS_ID"
8283
assert_line --regexp "Name.*$NS_NAME"
8384

85+
run_otdfctl_ns get "$NS_FQN_FLAG"
86+
assert_success
87+
assert_line --regexp "Id.*$NS_ID"
88+
assert_line --regexp "Name.*$NS_NAME"
89+
8490
run_otdfctl_ns get "$NS_ID_FLAG" --json
8591
assert_success
8692
[ "$(echo "$output" | jq -r '.id')" = "$NS_ID" ]
8793
[ "$(echo "$output" | jq -r '.name')" = "$NS_NAME" ]
94+
95+
run_otdfctl_ns get "$NS_FQN_FLAG" --json
96+
assert_success
97+
[ "$(echo "$output" | jq -r '.id')" = "$NS_ID" ]
98+
[ "$(echo "$output" | jq -r '.name')" = "$NS_NAME" ]
8899
}
89100

90101
@test "Get a namespace - Bad" {
91102
run_otdfctl_ns get
92103
assert_failure
93104
assert_output --partial "Flag '--id' is required"
94105

106+
run_otdfctl_ns get "$NS_ID_FLAG" "$NS_FQN_FLAG"
107+
assert_failure
108+
assert_output --partial "Flags '--id' and '--fqn' cannot be used together"
109+
95110
run_otdfctl_ns get --id 'example.com'
96111
assert_failure
97112
assert_output --partial "Flag '--id' received value 'example.com' must be a valid UUID"

0 commit comments

Comments
 (0)