Skip to content

Commit cd3cdcf

Browse files
committed
move logic to enterprise part
1 parent 0796e9c commit cd3cdcf

File tree

7 files changed

+56
-104
lines changed

7 files changed

+56
-104
lines changed

coderd/coderd.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,11 +1135,6 @@ func New(options *Options) *API {
11351135
})
11361136
})
11371137
})
1138-
r.Route("/provisionerkeys", func(r chi.Router) {
1139-
r.Route("/{provisionerkeyid}", func(r chi.Router) {
1140-
r.Get("/tags", api.getProvisionKeyTags)
1141-
})
1142-
})
11431138
r.Route("/workspaceagents", func(r chi.Router) {
11441139
r.Post("/azure-instance-identity", api.postWorkspaceAuthAzureInstanceIdentity)
11451140
r.Post("/aws-instance-identity", api.postWorkspaceAuthAWSInstanceIdentity)

coderd/provisionerkeys.go

Lines changed: 0 additions & 48 deletions
This file was deleted.

coderd/provisionerkeys_test.go

Lines changed: 0 additions & 48 deletions
This file was deleted.

codersdk/provisionerdaemons.go

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

371-
// GetProvisionTagsByKeyID returns the provisioner tags associated with the provisioner key ID.
372-
func (c *Client) GetProvisionTagsByKeyID(ctx context.Context, provisionerKeyID uuid.UUID) (ProvisionerKeyTags, error) {
371+
// GetProvisionTagsByKey returns the provisioner tags associated with the provisioner key.
372+
func (c *Client) GetProvisionTagsByKey(ctx context.Context, organizationID uuid.UUID, provisionerKey string) (ProvisionerKeyTags, error) {
373373
res, err := c.Request(ctx, http.MethodGet,
374-
fmt.Sprintf("/api/v2/provisionerkeys/%s/tags", provisionerKeyID.String()),
374+
fmt.Sprintf("/api/v2/organizations/%s/provisionerkeys/%s/tags", organizationID.String(), provisionerKey),
375375
nil,
376376
)
377377
if err != nil {

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
func convertProvisionerKeys(dbKeys []database.ProvisionerKey) []codersdk.ProvisionerKey {
204221
keys := make([]codersdk.ProvisionerKey, 0, len(dbKeys))
205222
for _, dbKey := range dbKeys {

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+
func TestProvisionerKeyTags(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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy