-
Notifications
You must be signed in to change notification settings - Fork 921
feat(coderd): add endpoint to fetch provisioner key details #15505
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
995a046
2ca6c91
c67d322
911a47d
1a019bb
c629f07
54437f2
8eeffb1
960084d
4a38977
c89bcd8
0af9e8e
4680484
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,17 +200,44 @@ func (api *API) deleteProvisionerKey(rw http.ResponseWriter, r *http.Request) { | |
httpapi.Write(ctx, rw, http.StatusNoContent, nil) | ||
} | ||
|
||
// @Summary Fetch provisioner key details | ||
// @ID fetch-provisioner-key-details | ||
// @Security CoderSessionToken | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should actually be updated as a session token here isn't sufficient auth. Sorry I didn't catch this sooner! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked the definition of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed , there's currently some extra logic to change in I can either keep it like that and create the follow-up issue / PR quickly or add this endpoint to the ignore list for now - as you prefer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep it as-is for the moment and create a follow-up PR to address this. |
||
// @Produce json | ||
// @Tags Enterprise | ||
// @Param provisionerkey path string true "Provisioner Key" | ||
// @Success 200 {object} codersdk.ProvisionerKey | ||
// @Router /provisionerkeys/{provisionerkey} [get] | ||
func (*API) fetchProvisionerKey(rw http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
|
||
pk, ok := httpmw.ProvisionerKeyAuthOptional(r) | ||
defelmnq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// extra check but this one should never happen as it is covered by the auth middleware | ||
if !ok { | ||
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{ | ||
Message: fmt.Sprintf("unable to auth: please provide the %s header", codersdk.ProvisionerDaemonKey), | ||
}) | ||
return | ||
} | ||
|
||
httpapi.Write(ctx, rw, http.StatusOK, convertProvisionerKey(pk)) | ||
} | ||
|
||
func convertProvisionerKey(dbKey database.ProvisionerKey) codersdk.ProvisionerKey { | ||
return codersdk.ProvisionerKey{ | ||
ID: dbKey.ID, | ||
CreatedAt: dbKey.CreatedAt, | ||
OrganizationID: dbKey.OrganizationID, | ||
Name: dbKey.Name, | ||
Tags: codersdk.ProvisionerKeyTags(dbKey.Tags), | ||
// HashedSecret - never include the access token in the API response | ||
defelmnq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
func convertProvisionerKeys(dbKeys []database.ProvisionerKey) []codersdk.ProvisionerKey { | ||
keys := make([]codersdk.ProvisionerKey, 0, len(dbKeys)) | ||
for _, dbKey := range dbKeys { | ||
keys = append(keys, codersdk.ProvisionerKey{ | ||
ID: dbKey.ID, | ||
CreatedAt: dbKey.CreatedAt, | ||
OrganizationID: dbKey.OrganizationID, | ||
Name: dbKey.Name, | ||
Tags: codersdk.ProvisionerKeyTags(dbKey.Tags), | ||
// HashedSecret - never include the access token in the API response | ||
}) | ||
keys = append(keys, convertProvisionerKey(dbKey)) | ||
} | ||
|
||
slices.SortFunc(keys, func(key1, key2 codersdk.ProvisionerKey) int { | ||
|
Uh oh!
There was an error while loading. Please reload this page.