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

Method patchWorkspaceAgentAppStatus

coderd/workspaceagents.go:301–366  ·  view source on GitHub ↗

@Summary Patch workspace agent app status @ID patch-workspace-agent-app-status @Security CoderSessionToken @Accept json @Produce json @Tags Agents @Param request body agentsdk.PatchAppStatus true "app status" @Success 200 {object} codersdk.Response @Router /api/v2/workspaceagents/me/app-status [patc

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

Source from the content-addressed store, hash-verified

299// @Router /api/v2/workspaceagents/me/app-status [patch]
300// @Deprecated Use UpdateAppStatus on the Agent API instead.
301func (api *API) patchWorkspaceAgentAppStatus(rw http.ResponseWriter, r *http.Request) {
302 ctx := r.Context()
303 workspaceAgent := httpmw.WorkspaceAgent(r)
304
305 var req agentsdk.PatchAppStatus
306 if !httpapi.Read(ctx, rw, r, &req) {
307 return
308 }
309
310 workspace, err := api.Database.GetWorkspaceByAgentID(ctx, workspaceAgent.ID)
311 if err != nil {
312 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
313 Message: "Failed to get workspace.",
314 Detail: err.Error(),
315 })
316 return
317 }
318
319 // This functionality has been moved to the AppsAPI in the agentapi. We keep this HTTP handler around for back
320 // compatibility with older agents. We'll translate the request into the protobuf so there is only one primary
321 // implementation.
322 cachedWs := &agentapi.CachedWorkspaceFields{}
323 cachedWs.UpdateValues(workspace)
324
325 appAPI := &agentapi.AppsAPI{
326 AgentID: workspaceAgent.ID,
327 Database: api.Database,
328 Log: api.Logger,
329 Workspace: cachedWs,
330 AgentFn: func(ctx context.Context) (database.WorkspaceAgent, error) {
331 return api.Database.GetWorkspaceAgentByID(ctx, workspaceAgent.ID)
332 },
333 PublishWorkspaceUpdateFn: func(ctx context.Context, agentID uuid.UUID, kind wspubsub.WorkspaceEventKind) error {
334 api.publishWorkspaceUpdate(ctx, workspace.OwnerID, wspubsub.WorkspaceEvent{
335 Kind: kind,
336 WorkspaceID: workspace.ID,
337 AgentID: &agentID,
338 })
339 return nil
340 },
341 NotificationsEnqueuer: api.NotificationsEnqueuer,
342 Clock: api.Clock,
343 }
344 protoReq, err := agentsdk.ProtoFromPatchAppStatus(req)
345 if err != nil {
346 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
347 Message: "Failed to parse request.",
348 Detail: err.Error(),
349 })
350 return
351 }
352 _, err = appAPI.UpdateAppStatus(r.Context(), protoReq)
353 if err != nil {
354 sdkErr := new(codersdk.Error)
355 if xerrors.As(err, &sdkErr) {
356 httpapi.Write(ctx, rw, sdkErr.StatusCode(), sdkErr.Response)
357 return
358 }

Callers

nothing calls this directly

Calls 13

UpdateValuesMethod · 0.95
UpdateAppStatusMethod · 0.95
WorkspaceAgentFunction · 0.92
ReadFunction · 0.92
WriteFunction · 0.92
ProtoFromPatchAppStatusFunction · 0.92
AsMethod · 0.80
ContextMethod · 0.65
GetWorkspaceByAgentIDMethod · 0.65
GetWorkspaceAgentByIDMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected