Skip to content

Commit

Permalink
fix(kumactl): mark valid-for as required for command kumactl generate…
Browse files Browse the repository at this point in the history
… dataplane-token (#11849)

## Motivation

fixes #11848
<!-- Why are we doing this change -->

## Implementation information

Mark the option as required.

Includes a small fixes that resolves
#11107 (comment)

## Supporting documentation

<!-- Is there a MADR? An Issue? A related PR? -->

fixes #11848

<!--
> Changelog: skip
-->
<!--
Uncomment the above section to explicitly set a [`> Changelog:` entry
here](https://github.com/kumahq/kuma/blob/master/CONTRIBUTING.md#submitting-a-patch)?
-->

---------

Signed-off-by: Jay Chen <[email protected]>
  • Loading branch information
jijiechen authored Oct 29, 2024
1 parent 83f82ff commit 68497aa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/kumactl/cmd/completion/testdata/bash.golden
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ _kumactl_generate_dataplane-token()
flags+=("--no-config")

must_have_one_flag=()
must_have_one_flag+=("--valid-for=")
must_have_one_noun=()
noun_aliases=()
}
Expand Down
2 changes: 2 additions & 0 deletions app/kumactl/cmd/generate/generate_dataplane_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,7 @@ $ kumactl generate dataplane-token --mesh demo --tag kuma.io/service=web,web-api
cmd.Flags().DurationVar(&ctx.args.validFor, "valid-for", 0, `how long the token will be valid (for example "24h")`)
cmd.Flags().StringVar(&ctx.args.signingKeyPath, "signing-key-path", "", "path to a file that contains private signing key. When specified, control plane won't be used to issue the token.")
cmd.Flags().StringVar(&ctx.args.kid, "kid", "", "ID of the key that is used to issue a token. Required when --signing-key-path is used.")

_ = cmd.MarkFlagRequired("valid-for")
return cmd
}
6 changes: 3 additions & 3 deletions app/kumactl/cmd/generate/generate_dataplane_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ var _ = Describe("kumactl generate dataplane-token", func() {
Expect(buf.String()).To(Equal(given.result))
},
Entry("for default mesh when it is not specified", testCase{
args: []string{"generate", "dataplane-token", "--name=example"},
args: []string{"generate", "dataplane-token", "--name=example", "--valid-for", "30s"},
result: "token-for-example-default--",
}),
Entry("for all arguments", testCase{
args: []string{"generate", "dataplane-token", "--mesh=demo", "--name=example", "--proxy-type=dataplane", "--tag", "kuma.io/service=web"},
args: []string{"generate", "dataplane-token", "--mesh=demo", "--name=example", "--proxy-type=dataplane", "--tag", "kuma.io/service=web", "--valid-for", "30s"},
result: "token-for-example-demo-kuma.io/service=web-dataplane",
}),
)
Expand Down Expand Up @@ -111,7 +111,7 @@ var _ = Describe("kumactl generate dataplane-token", func() {
generator.err = errors.New("could not connect to API")

// when
rootCmd.SetArgs([]string{"generate", "dataplane-token", "--name=example"})
rootCmd.SetArgs([]string{"generate", "dataplane-token", "--name=example", "--valid-for", "30s"})
err := rootCmd.Execute()

// then
Expand Down
3 changes: 2 additions & 1 deletion app/kumactl/cmd/generate/generate_user_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ $ kumactl generate user-token --name [email protected] --group users --valid-
},
}
cmd.Flags().StringVar(&args.name, "name", "", "name of the user")
_ = cmd.MarkFlagRequired("name")
cmd.Flags().StringSliceVar(&args.groups, "group", nil, "group of the user")
cmd.Flags().DurationVar(&args.validFor, "valid-for", 0, `how long the token will be valid (for example "24h")`)
cmd.Flags().StringVar(&args.signingKeyPath, "signing-key-path", "", "path to a file that contains private signing key. When specified, control plane won't be used to issue the token.")
cmd.Flags().StringVar(&args.kid, "kid", "", "ID of the key that is used to issue a token. Required when --signing-key-path is used.")

_ = cmd.MarkFlagRequired("name")
_ = cmd.MarkFlagRequired("valid-for")
return cmd
}

0 comments on commit 68497aa

Please sign in to comment.