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

Method patchPrimaryWorkspaceProxy

enterprise/coderd/workspaceproxy.go:178–237  ·  view source on GitHub ↗

patchPrimaryWorkspaceProxy handles the special case of updating the default

(req codersdk.PatchWorkspaceProxy, rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

176
177// patchPrimaryWorkspaceProxy handles the special case of updating the default
178func (api *API) patchPrimaryWorkspaceProxy(req codersdk.PatchWorkspaceProxy, rw http.ResponseWriter, r *http.Request) (database.WorkspaceProxy, bool) {
179 var (
180 ctx = r.Context()
181 proxy = httpmw.WorkspaceProxyParam(r)
182 )
183
184 // User is editing the default primary proxy.
185 if req.Name != "" && req.Name != proxy.Name {
186 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
187 Message: "Cannot update name of default primary proxy, did you mean to update the 'display name'?",
188 Validations: []codersdk.ValidationError{
189 {Field: "name", Detail: "Cannot update name of default primary proxy"},
190 },
191 })
192 return database.WorkspaceProxy{}, false
193 }
194 if req.DisplayName == "" && req.Icon == "" {
195 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
196 Message: "No update arguments provided. Nothing to do.",
197 Validations: []codersdk.ValidationError{
198 {Field: "display_name", Detail: "No value provided."},
199 {Field: "icon", Detail: "No value provided."},
200 },
201 })
202 return database.WorkspaceProxy{}, false
203 }
204
205 args := database.UpsertDefaultProxyParams{
206 DisplayName: req.DisplayName,
207 IconURL: req.Icon,
208 }
209 if req.DisplayName == "" || req.Icon == "" {
210 // If the user has not specified an update value, use the existing value.
211 existing, err := api.Database.GetDefaultProxyConfig(ctx)
212 if err != nil {
213 httpapi.InternalServerError(rw, err)
214 return database.WorkspaceProxy{}, false
215 }
216 if req.DisplayName == "" {
217 args.DisplayName = existing.DisplayName
218 }
219 if req.Icon == "" {
220 args.IconURL = existing.IconURL
221 }
222 }
223
224 err := api.Database.UpsertDefaultProxy(ctx, args)
225 if err != nil {
226 httpapi.InternalServerError(rw, err)
227 return database.WorkspaceProxy{}, false
228 }
229
230 // Use the primary region to fetch the default proxy values.
231 updatedProxy, err := api.AGPL.PrimaryWorkspaceProxy(ctx)
232 if err != nil {
233 httpapi.InternalServerError(rw, err)
234 return database.WorkspaceProxy{}, false
235 }

Callers 1

patchWorkspaceProxyMethod · 0.95

Calls 7

WorkspaceProxyParamFunction · 0.92
WriteFunction · 0.92
InternalServerErrorFunction · 0.92
PrimaryWorkspaceProxyMethod · 0.80
ContextMethod · 0.65
GetDefaultProxyConfigMethod · 0.65
UpsertDefaultProxyMethod · 0.65

Tested by

no test coverage detected