Skip to content

feat: add tags to provisioner keys api #13989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tags to cli
  • Loading branch information
f0ssel committed Jul 25, 2024
commit 5633489ef5adbf80ff3b2e33c5f27bdbd52238eb
21 changes: 19 additions & 2 deletions enterprise/cli/provisionerkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ func (r *RootCmd) provisionerKeys() *serpent.Command {
}

func (r *RootCmd) provisionerKeysCreate() *serpent.Command {
orgContext := agpl.NewOrganizationContext()
var (
orgContext = agpl.NewOrganizationContext()
rawTags []string
)

client := new(codersdk.Client)
cmd := &serpent.Command{
Expand All @@ -51,8 +54,14 @@ func (r *RootCmd) provisionerKeysCreate() *serpent.Command {
return xerrors.Errorf("current organization: %w", err)
}

tags, err := agpl.ParseProvisionerTags(rawTags)
if err != nil {
return err
}

res, err := client.CreateProvisionerKey(ctx, org.ID, codersdk.CreateProvisionerKeyRequest{
Name: inv.Args[0],
Tags: tags,
})
if err != nil {
return xerrors.Errorf("create provisioner key: %w", err)
Expand All @@ -69,7 +78,15 @@ func (r *RootCmd) provisionerKeysCreate() *serpent.Command {
},
}

cmd.Options = serpent.OptionSet{}
cmd.Options = serpent.OptionSet{
{
Flag: "tag",
FlagShorthand: "t",
Env: "CODER_PROVISIONERD_TAGS",
Description: "Tags to filter provisioner jobs by.",
Value: serpent.StringArrayOf(&rawTags),
},
}
orgContext.AttachOptions(cmd)

return cmd
Expand Down
4 changes: 3 additions & 1 deletion enterprise/cli/provisionerkeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestProvisionerKeys(t *testing.T) {
ctx := testutil.Context(t, testutil.WaitMedium)
inv, conf := newCLI(
t,
"provisioner", "keys", "create", name,
"provisioner", "keys", "create", name, "--tag", "foo=bar",
)

pty := ptytest.New(t)
Expand Down Expand Up @@ -77,8 +77,10 @@ func TestProvisionerKeys(t *testing.T) {
require.Contains(t, line, "NAME")
require.Contains(t, line, "CREATED AT")
require.Contains(t, line, "ORGANIZATION ID")
require.Contains(t, line, "TAGS")
line = pty.ReadLine(ctx)
require.Contains(t, line, strings.ToLower(name))
require.Contains(t, line, "map[foo:bar]")

inv, conf = newCLI(
t,
Expand Down