mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add tags to provisioner keys api (#13989)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user