@Summary Recreate devcontainer for workspace agent @ID recreate-devcontainer-for-workspace-agent @Security CoderSessionToken @Tags Agents @Produce json @Param workspaceagent path string true "Workspace agent ID" format(uuid) @Param devcontainer path string true "Devcontainer ID" @Success 202 {object
(rw http.ResponseWriter, r *http.Request)
| 1094 | // @Success 202 {object} codersdk.Response |
| 1095 | // @Router /api/v2/workspaceagents/{workspaceagent}/containers/devcontainers/{devcontainer}/recreate [post] |
| 1096 | func (api *API) workspaceAgentRecreateDevcontainer(rw http.ResponseWriter, r *http.Request) { |
| 1097 | ctx := r.Context() |
| 1098 | waws := httpmw.WorkspaceAgentAndWorkspaceParam(r) |
| 1099 | |
| 1100 | if !api.Authorize(r, policy.ActionUpdate, waws.WorkspaceTable) { |
| 1101 | httpapi.Forbidden(rw) |
| 1102 | return |
| 1103 | } |
| 1104 | |
| 1105 | devcontainer := chi.URLParam(r, "devcontainer") |
| 1106 | if devcontainer == "" { |
| 1107 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 1108 | Message: "Devcontainer ID is required.", |
| 1109 | Validations: []codersdk.ValidationError{ |
| 1110 | {Field: "devcontainer", Detail: "Devcontainer ID is required."}, |
| 1111 | }, |
| 1112 | }) |
| 1113 | return |
| 1114 | } |
| 1115 | |
| 1116 | apiAgent, err := db2sdk.WorkspaceAgent( |
| 1117 | api.DERPMap(), |
| 1118 | *api.TailnetCoordinator.Load(), |
| 1119 | waws.WorkspaceAgent, |
| 1120 | nil, |
| 1121 | nil, |
| 1122 | nil, |
| 1123 | api.AgentInactiveDisconnectTimeout, |
| 1124 | api.DeploymentValues.AgentFallbackTroubleshootingURL.String(), |
| 1125 | ) |
| 1126 | if err != nil { |
| 1127 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 1128 | Message: "Internal error reading workspace agent.", |
| 1129 | Detail: err.Error(), |
| 1130 | }) |
| 1131 | return |
| 1132 | } |
| 1133 | if apiAgent.Status != codersdk.WorkspaceAgentConnected { |
| 1134 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 1135 | Message: fmt.Sprintf("Agent state is %q, it must be in the %q state.", apiAgent.Status, codersdk.WorkspaceAgentConnected), |
| 1136 | }) |
| 1137 | return |
| 1138 | } |
| 1139 | |
| 1140 | // If the agent is unreachable, the request will hang. Assume that if we |
| 1141 | // don't get a response after 30s that the agent is unreachable. |
| 1142 | dialCtx, dialCancel := context.WithTimeout(ctx, 30*time.Second) |
| 1143 | defer dialCancel() |
| 1144 | agentConn, release, err := api.agentProvider.AgentConn(dialCtx, waws.WorkspaceAgent.ID) |
| 1145 | if err != nil { |
| 1146 | httpapi.Write(dialCtx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 1147 | Message: "Internal error dialing workspace agent.", |
| 1148 | Detail: err.Error(), |
| 1149 | }) |
| 1150 | return |
| 1151 | } |
| 1152 | defer release() |
| 1153 |
nothing calls this directly
no test coverage detected