@Summary Get workspace metadata by ID @ID get-workspace-metadata-by-id @Security CoderSessionToken @Produce json @Tags Workspaces @Param workspace path string true "Workspace ID" format(uuid) @Param include_deleted query bool false "Return data instead of HTTP 404 if the workspace is deleted" @Succe
(rw http.ResponseWriter, r *http.Request)
| 68 | // @Success 200 {object} codersdk.Workspace |
| 69 | // @Router /api/v2/workspaces/{workspace} [get] |
| 70 | func (api *API) workspace(rw http.ResponseWriter, r *http.Request) { |
| 71 | ctx := r.Context() |
| 72 | workspace := httpmw.WorkspaceParam(r) |
| 73 | apiKey := httpmw.APIKey(r) |
| 74 | |
| 75 | var ( |
| 76 | deletedStr = r.URL.Query().Get("include_deleted") |
| 77 | showDeleted = false |
| 78 | ) |
| 79 | if deletedStr != "" { |
| 80 | var err error |
| 81 | showDeleted, err = strconv.ParseBool(deletedStr) |
| 82 | if err != nil { |
| 83 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 84 | Message: fmt.Sprintf("Invalid boolean value %q for \"include_deleted\" query param.", deletedStr), |
| 85 | Validations: []codersdk.ValidationError{ |
| 86 | {Field: "deleted", Detail: "Must be a valid boolean"}, |
| 87 | }, |
| 88 | }) |
| 89 | return |
| 90 | } |
| 91 | } |
| 92 | if workspace.Deleted && !showDeleted { |
| 93 | httpapi.Write(ctx, rw, http.StatusGone, codersdk.Response{ |
| 94 | Message: fmt.Sprintf("Workspace %q was deleted, you can view this workspace by specifying '?deleted=true' and trying again.", workspace.ID.String()), |
| 95 | }) |
| 96 | return |
| 97 | } |
| 98 | |
| 99 | data, err := api.workspaceData(ctx, []database.Workspace{workspace}) |
| 100 | if err != nil { |
| 101 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 102 | Message: "Internal error fetching workspace resources.", |
| 103 | Detail: err.Error(), |
| 104 | }) |
| 105 | return |
| 106 | } |
| 107 | |
| 108 | if len(data.templates) == 0 { |
| 109 | httpapi.Forbidden(rw) |
| 110 | return |
| 111 | } |
| 112 | |
| 113 | appStatus := codersdk.WorkspaceAppStatus{} |
| 114 | if len(data.appStatuses) > 0 { |
| 115 | appStatus = data.appStatuses[0] |
| 116 | } |
| 117 | |
| 118 | w, err := convertWorkspace( |
| 119 | ctx, |
| 120 | api.Logger, |
| 121 | apiKey.UserID, |
| 122 | workspace, |
| 123 | data.builds[0], |
| 124 | data.templates[0], |
| 125 | api.Options.AllowWorkspaceRenames, |
| 126 | appStatus, |
| 127 | ) |
nothing calls this directly
no test coverage detected