feat: add tags to provisioner keys api (#13989)

This commit is contained in:
Garrett Delfosse
2024-07-25 15:20:45 +00:00
committed by GitHub
parent ca83017dc1
commit 6161d173d3
21 changed files with 120 additions and 49 deletions
+19 -2
View File
@@ -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{
@@ -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)
@@ -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
+3 -1
View File
@@ -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)
@@ -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,