@Summary Update workspace build state @ID update-workspace-build-state @Security CoderSessionToken @Accept json @Tags Builds @Param workspacebuild path string true "Workspace build ID" format(uuid) @Param request body codersdk.UpdateWorkspaceBuildStateRequest true "Request body" @Success 204 @Router
(rw http.ResponseWriter, r *http.Request)
| 901 | // @Success 204 |
| 902 | // @Router /api/v2/workspacebuilds/{workspacebuild}/state [put] |
| 903 | func (api *API) workspaceBuildUpdateState(rw http.ResponseWriter, r *http.Request) { |
| 904 | ctx := r.Context() |
| 905 | workspaceBuild := httpmw.WorkspaceBuildParam(r) |
| 906 | workspace, err := api.Database.GetWorkspaceByID(ctx, workspaceBuild.WorkspaceID) |
| 907 | if err != nil { |
| 908 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 909 | Message: "No workspace exists for this job.", |
| 910 | }) |
| 911 | return |
| 912 | } |
| 913 | template, err := api.Database.GetTemplateByID(ctx, workspace.TemplateID) |
| 914 | if err != nil { |
| 915 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 916 | Message: "Failed to get template", |
| 917 | Detail: err.Error(), |
| 918 | }) |
| 919 | return |
| 920 | } |
| 921 | |
| 922 | // You must have update permissions on the template to update the state. |
| 923 | if !api.Authorize(r, policy.ActionUpdate, template.RBACObject()) { |
| 924 | httpapi.ResourceNotFound(rw) |
| 925 | return |
| 926 | } |
| 927 | |
| 928 | var req codersdk.UpdateWorkspaceBuildStateRequest |
| 929 | if !httpapi.Read(ctx, rw, r, &req) { |
| 930 | return |
| 931 | } |
| 932 | |
| 933 | // Use system context since we've already verified authorization via template permissions. |
| 934 | // nolint:gocritic // System access required for provisioner state update. |
| 935 | err = api.Database.UpdateWorkspaceBuildProvisionerStateByID(dbauthz.AsSystemRestricted(ctx), database.UpdateWorkspaceBuildProvisionerStateByIDParams{ |
| 936 | ID: workspaceBuild.ID, |
| 937 | ProvisionerState: req.State, |
| 938 | UpdatedAt: dbtime.Now(), |
| 939 | }) |
| 940 | if err != nil { |
| 941 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 942 | Message: "Failed to update workspace build state.", |
| 943 | Detail: err.Error(), |
| 944 | }) |
| 945 | return |
| 946 | } |
| 947 | |
| 948 | rw.WriteHeader(http.StatusNoContent) |
| 949 | } |
| 950 | |
| 951 | // @Summary Get workspace build timings by ID |
| 952 | // @ID get-workspace-build-timings-by-id |
nothing calls this directly
no test coverage detected