Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
f0ssel merged 7 commits intomainfromf0ssel/pk-tags
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
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
6 changes: 6 additions & 0 deletionscoderd/apidoc/docs.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

6 changes: 6 additions & 0 deletionscoderd/apidoc/swagger.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

1 change: 1 addition & 0 deletionscoderd/database/dbgen/dbgen.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -472,6 +472,7 @@ func ProvisionerKey(t testing.TB, db database.Store, orig database.ProvisionerKe
OrganizationID: takeFirst(orig.OrganizationID, uuid.New()),
Name: takeFirst(orig.Name, namesgenerator.GetRandomName(1)),
HashedSecret: orig.HashedSecret,
Tags: orig.Tags,
})
require.NoError(t, err, "insert provisioner key")
return key
Expand Down
9 changes: 2 additions & 7 deletionscoderd/database/dbmem/dbmem.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6586,6 +6586,7 @@ func (q *FakeQuerier) InsertProvisionerKey(_ context.Context, arg database.Inser
OrganizationID: arg.OrganizationID,
Name: strings.ToLower(arg.Name),
HashedSecret: arg.HashedSecret,
Tags: arg.Tags,
}
q.provisionerKeys = append(q.provisionerKeys, provisionerKey)

Expand DownExpand Up@@ -7276,13 +7277,7 @@ func (q *FakeQuerier) ListProvisionerKeysByOrganization(_ context.Context, organ
keys := make([]database.ProvisionerKey, 0)
for _, key := range q.provisionerKeys {
if key.OrganizationID == organizationID {
keys = append(keys, database.ProvisionerKey{
ID: key.ID,
CreatedAt: key.CreatedAt,
OrganizationID: key.OrganizationID,
Name: key.Name,
HashedSecret: key.HashedSecret,
})
keys = append(keys, key)
}
}

Expand Down
3 changes: 2 additions & 1 deletioncoderd/database/dump.sql
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
ALTER TABLE provisioner_keys DROP COLUMN tags;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
ALTER TABLE provisioner_keys ADD COLUMN tags jsonb DEFAULT '{}'::jsonb NOT NULL;
ALTER TABLE provisioner_keys ALTER COLUMN tags DROP DEFAULT;
1 change: 1 addition & 0 deletionscoderd/database/models.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

25 changes: 16 additions & 9 deletionscoderd/database/queries.sql.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

13 changes: 7 additions & 6 deletionscoderd/database/queries/provisionerkeys.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
-- name: InsertProvisionerKey :one
INSERT INTO
provisioner_keys (
id,
provisioner_keys (
id,
created_at,
organization_id,
name,
hashed_secret
)
name,
hashed_secret,
tags
)
VALUES
($1, $2, $3, lower(@name), $4) RETURNING *;
($1, $2, $3, lower(@name), $4, $5) RETURNING *;

-- name: GetProvisionerKeyByID :one
SELECT
Expand Down
3 changes: 3 additions & 0 deletionscoderd/database/sqlc.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,6 +44,9 @@ sql:
- column: "provisioner_daemons.tags"
go_type:
type: "StringMap"
- column: "provisioner_keys.tags"
go_type:
type: "StringMap"
- column: "provisioner_jobs.tags"
go_type:
type: "StringMap"
Expand Down
7 changes: 6 additions & 1 deletioncoderd/provisionerkey/provisionerkey.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ import (
"github.com/coder/coder/v2/cryptorand"
)

func New(organizationID uuid.UUID, name string) (database.InsertProvisionerKeyParams, string, error) {
func New(organizationID uuid.UUID, name string, tags map[string]string) (database.InsertProvisionerKeyParams, string, error) {
id := uuid.New()
secret, err := cryptorand.HexString(64)
if err != nil {
Expand All@@ -23,12 +23,17 @@ func New(organizationID uuid.UUID, name string) (database.InsertProvisionerKeyPa
hashedSecret := HashSecret(secret)
token := fmt.Sprintf("%s:%s", id, secret)

if tags == nil {
tags = map[string]string{}
}

return database.InsertProvisionerKeyParams{
ID: id,
CreatedAt: dbtime.Now(),
OrganizationID: organizationID,
Name: name,
HashedSecret: hashedSecret,
Tags: tags,
}, token, nil
}

Expand Down
12 changes: 7 additions & 5 deletionscodersdk/provisionerdaemons.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -274,15 +274,17 @@ func (c *Client) ServeProvisionerDaemon(ctx context.Context, req ServeProvisione
}

type ProvisionerKey struct {
ID uuid.UUID `json:"id" table:"-" format:"uuid"`
CreatedAt time.Time `json:"created_at" table:"created_at" format:"date-time"`
OrganizationID uuid.UUID `json:"organization" table:"organization_id" format:"uuid"`
Name string `json:"name" table:"name,default_sort"`
ID uuid.UUID `json:"id" table:"-" format:"uuid"`
CreatedAt time.Time `json:"created_at" table:"created_at" format:"date-time"`
OrganizationID uuid.UUID `json:"organization" table:"organization_id" format:"uuid"`
Name string `json:"name" table:"name,default_sort"`
Tags map[string]string `json:"tags" table:"tags"`
// HashedSecret - never include the access token in the API response
}

type CreateProvisionerKeyRequest struct {
Name string `json:"name"`
Name string `json:"name"`
Tags map[string]string `json:"tags"`
}

type CreateProvisionerKeyResponse struct {
Expand Down
22 changes: 14 additions & 8 deletionsdocs/api/enterprise.md
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

20 changes: 13 additions & 7 deletionsdocs/api/schemas.md
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

21 changes: 19 additions & 2 deletionsenterprise/cli/provisionerkeys.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionenterprise/cli/provisionerkeys_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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
2 changes: 1 addition & 1 deletionenterprise/coderd/provisionerdaemons_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,7 +559,7 @@ func TestProvisionerDaemonServe(t *testing.T) {
t.Run("ProvisionerKeyAuth", func(t *testing.T) {
t.Parallel()

insertParams, token, err := provisionerkey.New(uuid.Nil, "dont-TEST-me")
insertParams, token, err := provisionerkey.New(uuid.Nil, "dont-TEST-me", nil)
require.NoError(t, err)

tcs := []struct {
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp