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

Commit995a046

Browse files
committed
feat(provisioners) - add endpoint to fetch tags associated to a key using its id
fix: change from database.StringMap to codersdk.ProvisionerKeyTags in endpoint responseimprove annotations for endpointmove logic to enterprise partgenerate new docmove logic to enterprise partgenerate doc
1 parente55e8ee commit995a046

File tree

7 files changed

+177
-0
lines changed

7 files changed

+177
-0
lines changed

‎coderd/apidoc/docs.go

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎codersdk/provisionerdaemons.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,24 @@ func (c *Client) ListProvisionerKeys(ctx context.Context, organizationID uuid.UU
368368
returnresp,json.NewDecoder(res.Body).Decode(&resp)
369369
}
370370

371+
// GetProvisionTagsByKey returns the provisioner tags associated with the provisioner key.
372+
func (c*Client)GetProvisionTagsByKey(ctx context.Context,organizationID uuid.UUID,provisionerKeystring) (ProvisionerKeyTags,error) {
373+
res,err:=c.Request(ctx,http.MethodGet,
374+
fmt.Sprintf("/api/v2/organizations/%s/provisionerkeys/%s/tags",organizationID.String(),provisionerKey),
375+
nil,
376+
)
377+
iferr!=nil {
378+
returnnil,xerrors.Errorf("make request: %w",err)
379+
}
380+
deferres.Body.Close()
381+
382+
ifres.StatusCode!=http.StatusOK {
383+
returnnil,ReadBodyAsError(res)
384+
}
385+
varrespProvisionerKeyTags
386+
returnresp,json.NewDecoder(res.Body).Decode(&resp)
387+
}
388+
371389
// ListProvisionerKeyDaemons lists all provisioner keys with their associated daemons for an organization.
372390
func (c*Client)ListProvisionerKeyDaemons(ctx context.Context,organizationID uuid.UUID) ([]ProvisionerKeyDaemons,error) {
373391
res,err:=c.Request(ctx,http.MethodGet,

‎docs/reference/api/enterprise.md

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎enterprise/coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
352352
r.Use(
353353
httpmw.ExtractProvisionerKeyParam(options.Database),
354354
)
355+
r.Get("/tags",api.fetchProvisionerKeyTags)
355356
r.Delete("/",api.deleteProvisionerKey)
356357
})
357358
})

‎enterprise/coderd/provisionerkeys.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,23 @@ func (api *API) deleteProvisionerKey(rw http.ResponseWriter, r *http.Request) {
200200
httpapi.Write(ctx,rw,http.StatusNoContent,nil)
201201
}
202202

203+
// @Summary Get provisioner key tags by ID
204+
// @ID get-provisioner-key-tags-by-id
205+
// @Produce json
206+
// @Tags Enterprise
207+
// @Param organization path string true "Organization ID"
208+
// @Param provisionerkeyid path string true "Provisioner Key ID" format(uuid)
209+
// @Success 200 {object} codersdk.ProvisionerKeyTags
210+
// @Router /organizations/{organization}/provisionerkeys/{provisionerkeyid}/tags [get]
211+
func (api*API)fetchProvisionerKeyTags(rw http.ResponseWriter,r*http.Request) {
212+
var (
213+
ctx=r.Context()
214+
pk=httpmw.ProvisionerKeyParam(r)
215+
)
216+
217+
httpapi.Write(ctx,rw,http.StatusOK,codersdk.ProvisionerKeyTags(pk.Tags))
218+
}
219+
203220
funcconvertProvisionerKeys(dbKeys []database.ProvisionerKey) []codersdk.ProvisionerKey {
204221
keys:=make([]codersdk.ProvisionerKey,0,len(dbKeys))
205222
for_,dbKey:=rangedbKeys {

‎enterprise/coderd/provisionerkeys_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,38 @@ func TestProvisionerKeys(t *testing.T) {
133133
err=orgAdmin.DeleteProvisionerKey(ctx,owner.OrganizationID,codersdk.ProvisionerKeyNamePSK)
134134
require.ErrorContains(t,err,"reserved")
135135
}
136+
137+
funcTestProvisionerKeyTags(t*testing.T) {
138+
t.Parallel()
139+
t.Run("GetTags",func(t*testing.T) {
140+
t.Parallel()
141+
142+
ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitLong*10)
143+
t.Cleanup(cancel)
144+
dv:=coderdtest.DeploymentValues(t)
145+
client,owner:=coderdenttest.New(t,&coderdenttest.Options{
146+
Options:&coderdtest.Options{
147+
DeploymentValues:dv,
148+
},
149+
LicenseOptions:&coderdenttest.LicenseOptions{
150+
Features: license.Features{
151+
codersdk.FeatureMultipleOrganizations:1,
152+
},
153+
},
154+
})
155+
156+
//nolint:gocritic // Not the purpose of this test
157+
_,err:=client.CreateProvisionerKey(ctx,owner.OrganizationID, codersdk.CreateProvisionerKeyRequest{
158+
Name:"key",
159+
Tags:map[string]string{"key1":"value1","key2":"value2"},
160+
})
161+
require.NoError(t,err)
162+
163+
tags,err:=client.GetProvisionTagsByKeyID(ctx,owner.OrganizationID,"key")
164+
require.NoError(t,err)
165+
require.Equal(t,tags, codersdk.ProvisionerKeyTags{"key1":"value1","key2":"value2"})
166+
167+
err=client.DeleteProvisionerKey(ctx,owner.OrganizationID,"invalid_key")
168+
require.ErrorContains(t,err,"Resource not found")
169+
})
170+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp