MCPcopy Index your code
hub / github.com/coder/coder / getUserSecret

Method getUserSecret

coderd/usersecrets.go:133–155  ·  view source on GitHub ↗

@Summary Get a user secret by name @ID get-a-user-secret-by-name @Security CoderSessionToken @Produce json @Tags Secrets @Param user path string true "User ID, username, or me" @Param name path string true "Secret name" @Success 200 {object} codersdk.UserSecret @Router /api/v2/users/{user}/secrets/{

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

131// @Success 200 {object} codersdk.UserSecret
132// @Router /api/v2/users/{user}/secrets/{name} [get]
133func (api *API) getUserSecret(rw http.ResponseWriter, r *http.Request) { //nolint:revive // Method name matches route.
134 ctx := r.Context()
135 user := httpmw.UserParam(r)
136 name := chi.URLParam(r, userSecretNameField)
137
138 secret, err := api.Database.GetUserSecretByUserIDAndName(ctx, database.GetUserSecretByUserIDAndNameParams{
139 UserID: user.ID,
140 Name: name,
141 })
142 if err != nil {
143 if errors.Is(err, sql.ErrNoRows) {
144 httpapi.ResourceNotFound(rw)
145 return
146 }
147 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
148 Message: "Internal error fetching secret.",
149 Detail: err.Error(),
150 })
151 return
152 }
153
154 httpapi.Write(ctx, rw, http.StatusOK, db2sdk.UserSecretFromFull(secret))
155}
156
157// @Summary Update a user secret
158// @ID update-a-user-secret

Callers 1

api.test.tsFile · 0.80

Calls 8

UserParamFunction · 0.92
ResourceNotFoundFunction · 0.92
WriteFunction · 0.92
UserSecretFromFullFunction · 0.92
ContextMethod · 0.65
IsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected