@Summary Delete devcontainer for workspace agent @ID delete-devcontainer-for-workspace-agent @Security CoderSessionToken @Tags Agents @Param workspaceagent path string true "Workspace agent ID" format(uuid) @Param devcontainer path string true "Devcontainer ID" @Success 204 @Router /api/v2/workspace
(rw http.ResponseWriter, r *http.Request)
| 1004 | // @Success 204 |
| 1005 | // @Router /api/v2/workspaceagents/{workspaceagent}/containers/devcontainers/{devcontainer} [delete] |
| 1006 | func (api *API) workspaceAgentDeleteDevcontainer(rw http.ResponseWriter, r *http.Request) { |
| 1007 | ctx := r.Context() |
| 1008 | waws := httpmw.WorkspaceAgentAndWorkspaceParam(r) |
| 1009 | |
| 1010 | if !api.Authorize(r, policy.ActionUpdate, waws.WorkspaceTable) { |
| 1011 | httpapi.Forbidden(rw) |
| 1012 | return |
| 1013 | } |
| 1014 | |
| 1015 | devcontainer := chi.URLParam(r, "devcontainer") |
| 1016 | if devcontainer == "" { |
| 1017 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 1018 | Message: "Devcontainer ID is required.", |
| 1019 | Validations: []codersdk.ValidationError{ |
| 1020 | {Field: "devcontainer", Detail: "Devcontainer ID is required."}, |
| 1021 | }, |
| 1022 | }) |
| 1023 | return |
| 1024 | } |
| 1025 | |
| 1026 | apiAgent, err := db2sdk.WorkspaceAgent( |
| 1027 | api.DERPMap(), |
| 1028 | *api.TailnetCoordinator.Load(), |
| 1029 | waws.WorkspaceAgent, |
| 1030 | nil, |
| 1031 | nil, |
| 1032 | nil, |
| 1033 | api.AgentInactiveDisconnectTimeout, |
| 1034 | api.DeploymentValues.AgentFallbackTroubleshootingURL.String(), |
| 1035 | ) |
| 1036 | if err != nil { |
| 1037 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 1038 | Message: "Internal error reading workspace agent.", |
| 1039 | Detail: err.Error(), |
| 1040 | }) |
| 1041 | return |
| 1042 | } |
| 1043 | if apiAgent.Status != codersdk.WorkspaceAgentConnected { |
| 1044 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 1045 | Message: fmt.Sprintf("Agent state is %q, it must be in the %q state.", apiAgent.Status, codersdk.WorkspaceAgentConnected), |
| 1046 | }) |
| 1047 | return |
| 1048 | } |
| 1049 | |
| 1050 | // If the agent is unreachable, the request will hang. Assume that if we |
| 1051 | // don't get a response after 30s that the agent is unreachable. |
| 1052 | dialCtx, dialCancel := context.WithTimeout(ctx, 30*time.Second) |
| 1053 | defer dialCancel() |
| 1054 | agentConn, release, err := api.agentProvider.AgentConn(dialCtx, waws.WorkspaceAgent.ID) |
| 1055 | if err != nil { |
| 1056 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 1057 | Message: "Internal error dialing workspace agent.", |
| 1058 | Detail: err.Error(), |
| 1059 | }) |
| 1060 | return |
| 1061 | } |
| 1062 | defer release() |
| 1063 |
nothing calls this directly
no test coverage detected