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

Commit 77ebbb4

Browse files
authored
fix(core): obligations commands id and fqn flag exclusivity (#731)
Closes #728
1 parent a71d609 commit 77ebbb4

2 files changed

Lines changed: 47 additions & 16 deletions

File tree

cmd/policy/obligations.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ func policyGetObligation(cmd *cobra.Command, args []string) {
6767
id := c.Flags.GetOptionalID("id")
6868
fqn := c.Flags.GetOptionalString("fqn")
6969

70-
cmd.MarkFlagsOneRequired("id", "fqn")
71-
cmd.MarkFlagsMutuallyExclusive("id", "fqn")
72-
7370
obl, err := h.GetObligation(cmd.Context(), id, fqn)
7471
if err != nil {
7572
identifier := fmt.Sprintf("id: %s", id)
@@ -168,9 +165,6 @@ func policyDeleteObligation(cmd *cobra.Command, args []string) {
168165
id := c.Flags.GetOptionalID("id")
169166
fqn := c.Flags.GetOptionalString("fqn")
170167

171-
cmd.MarkFlagsOneRequired("id", "fqn")
172-
cmd.MarkFlagsMutuallyExclusive("id", "fqn")
173-
174168
force := c.Flags.GetRequiredBool("force")
175169
ctx := cmd.Context()
176170

@@ -252,9 +246,6 @@ func policyGetObligationValue(cmd *cobra.Command, args []string) {
252246
id := c.Flags.GetOptionalID("id")
253247
fqn := c.Flags.GetOptionalString("fqn")
254248

255-
cmd.MarkFlagsOneRequired("id", "fqn")
256-
cmd.MarkFlagsMutuallyExclusive("id", "fqn")
257-
258249
value, err := h.GetObligationValue(cmd.Context(), id, fqn)
259250
if err != nil {
260251
identifier := fmt.Sprintf("id: %s", id)
@@ -329,9 +320,6 @@ func policyDeleteObligationValue(cmd *cobra.Command, args []string) {
329320
id := c.Flags.GetOptionalID("id")
330321
fqn := c.Flags.GetOptionalString("fqn")
331322

332-
cmd.MarkFlagsOneRequired("id", "fqn")
333-
cmd.MarkFlagsMutuallyExclusive("id", "fqn")
334-
335323
force := c.Flags.GetOptionalBool("force")
336324
ctx := cmd.Context()
337325

@@ -525,6 +513,8 @@ func initObligationsCommands() {
525513
getDoc.GetDocFlag("fqn").Default,
526514
getDoc.GetDocFlag("fqn").Description,
527515
)
516+
getDoc.MarkFlagsMutuallyExclusive("id", "fqn")
517+
getDoc.MarkFlagsOneRequired("id", "fqn")
528518

529519
listDoc := man.Docs.GetCommand("policy/obligations/list",
530520
man.WithRun(policyListObligations),
@@ -598,6 +588,8 @@ func initObligationsCommands() {
598588
false,
599589
deleteDoc.GetDocFlag("force").Description,
600590
)
591+
deleteDoc.MarkFlagsMutuallyExclusive("id", "fqn")
592+
deleteDoc.MarkFlagsOneRequired("id", "fqn")
601593

602594
// Obligation Values commands
603595

@@ -616,6 +608,8 @@ func initObligationsCommands() {
616608
getValueDoc.GetDocFlag("fqn").Default,
617609
getValueDoc.GetDocFlag("fqn").Description,
618610
)
611+
getValueDoc.MarkFlagsMutuallyExclusive("id", "fqn")
612+
getValueDoc.MarkFlagsOneRequired("id", "fqn")
619613

620614
createValueDoc := man.Docs.GetCommand("policy/obligations/values/create",
621615
man.WithRun(policyCreateObligationValue),
@@ -682,6 +676,8 @@ func initObligationsCommands() {
682676
false,
683677
deleteValueDoc.GetDocFlag("force").Description,
684678
)
679+
deleteValueDoc.MarkFlagsMutuallyExclusive("id", "fqn")
680+
deleteValueDoc.MarkFlagsOneRequired("id", "fqn")
685681

686682
// Obligation Triggers commands
687683
createTriggerDoc := man.Docs.GetCommand("policy/obligations/triggers/create",

e2e/obligations.bats

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,19 @@ teardown_file() {
375375
@test "Get an obligation - Bad" {
376376
run_otdfctl_obl get
377377
assert_failure
378-
assert_output --partial "one of id, fqn must be set [message.oneof]"
378+
assert_output --partial "Error: at least one of the flags in the group"
379+
assert_output --partial "id"
380+
assert_output --partial "fqn"
379381

380382
run_otdfctl_obl get --id 'not_a_uuid'
381383
assert_failure
382384
assert_output --partial "must be a valid UUID"
385+
386+
run_otdfctl_obl get --id '08db7417-bd97-4455-b308-7d9e94e43440' --fqn 'https://example.com/obl/example'
387+
assert_failure
388+
assert_output --partial "Error: if any flags in the group"
389+
assert_output --partial "id"
390+
assert_output --partial "fqn"
383391
}
384392

385393
@test "List obligations" {
@@ -447,12 +455,21 @@ teardown_file() {
447455
# no id
448456
run_otdfctl_obl delete
449457
assert_failure
450-
assert_output --partial "one of id, fqn must be set [message.oneof]"
458+
assert_output --partial "Error: at least one of the flags in the group"
459+
assert_output --partial "id"
460+
assert_output --partial "fqn"
451461

452462
# invalid id
453463
run_otdfctl_obl delete --id 'not_a_uuid'
454464
assert_failure
455465
assert_output --partial "must be a valid UUID"
466+
467+
# id and fqn exclusive
468+
run_otdfctl_obl delete --id '08db7417-bd97-4455-b308-7d9e94e43440' --fqn 'https://example.com/obl/example'
469+
assert_failure
470+
assert_output --partial "Error: if any flags in the group"
471+
assert_output --partial "id"
472+
assert_output --partial "fqn"
456473
}
457474

458475
# Tests for obligation values
@@ -656,7 +673,9 @@ EOF
656673
@test "Get an obligation value - Bad" {
657674
run_otdfctl_obl_values get
658675
assert_failure
659-
assert_output --partial "one of id, fqn must be set [message.oneof]"
676+
assert_output --partial "Error: at least one of the flags in the group"
677+
assert_output --partial "id"
678+
assert_output --partial "fqn"
660679

661680
# invalid id
662681
run_otdfctl_obl_values get --id 'not_a_uuid'
@@ -667,6 +686,13 @@ EOF
667686
run_otdfctl_obl_values get --fqn 'not_a_fqn'
668687
assert_failure
669688
assert_output --partial "must be a valid URI"
689+
690+
# id and fqn exclusive
691+
run_otdfctl_obl_values get --id '08db7417-bd97-4455-b308-7d9e94e43440' --fqn 'https://example.com/obl/example/value/value1'
692+
assert_failure
693+
assert_output --partial "Error: if any flags in the group"
694+
assert_output --partial "id"
695+
assert_output --partial "fqn"
670696
}
671697

672698
@test "Update obligation values" {
@@ -784,12 +810,21 @@ EOF
784810
# no id
785811
run_otdfctl_obl_values delete
786812
assert_failure
787-
assert_output --partial "one of id, fqn must be set [message.oneof]"
813+
assert_output --partial "Error: at least one of the flags in the group"
814+
assert_output --partial "id"
815+
assert_output --partial "fqn"
788816

789817
# invalid id
790818
run_otdfctl_obl_values delete --id 'not_a_uuid'
791819
assert_failure
792820
assert_output --partial "must be a valid UUID"
821+
822+
# id and fqn exclusive
823+
run_otdfctl_obl_values delete --id '08db7417-bd97-4455-b308-7d9e94e43440' --fqn 'https://example.com/obl/example/value/value1'
824+
assert_failure
825+
assert_output --partial "Error: if any flags in the group"
826+
assert_output --partial "id"
827+
assert_output --partial "fqn"
793828
}
794829

795830
# Tests for obligation triggers

0 commit comments

Comments
 (0)