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

Method patchWorkspaceProxy

enterprise/coderd/workspaceproxy.go:98–175  ·  view source on GitHub ↗

@Summary Update workspace proxy @ID update-workspace-proxy @Security CoderSessionToken @Accept json @Produce json @Tags Enterprise @Param workspaceproxy path string true "Proxy ID or name" format(uuid) @Param request body codersdk.PatchWorkspaceProxy true "Update workspace proxy request" @Success 20

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

Source from the content-addressed store, hash-verified

96// @Success 200 {object} codersdk.WorkspaceProxy
97// @Router /api/v2/workspaceproxies/{workspaceproxy} [patch]
98func (api *API) patchWorkspaceProxy(rw http.ResponseWriter, r *http.Request) {
99 var (
100 ctx = r.Context()
101 proxy = httpmw.WorkspaceProxyParam(r)
102 auditor = api.AGPL.Auditor.Load()
103 aReq, commitAudit = audit.InitRequest[database.WorkspaceProxy](rw, &audit.RequestParams{
104 Audit: *auditor,
105 Log: api.Logger,
106 Request: r,
107 Action: database.AuditActionWrite,
108 })
109 )
110 aReq.Old = proxy
111 defer commitAudit()
112
113 var req codersdk.PatchWorkspaceProxy
114 if !httpapi.Read(ctx, rw, r, &req) {
115 return
116 }
117
118 var hashedSecret []byte
119 var fullToken string
120 if req.RegenerateToken {
121 var err error
122 fullToken, hashedSecret, err = generateWorkspaceProxyToken(proxy.ID)
123 if err != nil {
124 httpapi.InternalServerError(rw, err)
125 return
126 }
127 }
128
129 deploymentIDStr, err := api.Database.GetDeploymentID(ctx)
130 if err != nil {
131 httpapi.InternalServerError(rw, err)
132 return
133 }
134
135 var updatedProxy database.WorkspaceProxy
136 if proxy.ID.String() == deploymentIDStr {
137 // User is editing the default primary proxy.
138 var ok bool
139 updatedProxy, ok = api.patchPrimaryWorkspaceProxy(req, rw, r)
140 if !ok {
141 return
142 }
143 } else {
144 updatedProxy, err = api.Database.UpdateWorkspaceProxy(ctx, database.UpdateWorkspaceProxyParams{
145 Name: req.Name,
146 DisplayName: req.DisplayName,
147 Icon: req.Icon,
148 ID: proxy.ID,
149 // If hashedSecret is nil or empty, this will not update the secret.
150 TokenHashedSecret: hashedSecret,
151 })
152 if httpapi.Is404Error(err) {
153 httpapi.ResourceNotFound(rw)
154 return
155 }

Callers

nothing calls this directly

Calls 15

WorkspaceProxyParamFunction · 0.92
InitRequestFunction · 0.92
ReadFunction · 0.92
InternalServerErrorFunction · 0.92
Is404ErrorFunction · 0.92
ResourceNotFoundFunction · 0.92
WriteFunction · 0.92
convertProxyFunction · 0.85
HealthStatusMethod · 0.80

Tested by

no test coverage detected