UpdateWorkspace updates a registered workspace.
(c *gin.Context)
| 159 | |
| 160 | // UpdateWorkspace updates a registered workspace. |
| 161 | func (h *BaseHandlers) UpdateWorkspace(c *gin.Context) { |
| 162 | workspace, err := h.Workspaces.Get(c.Request.Context(), workspaceRefFromRoute(c)) |
| 163 | if err != nil { |
| 164 | h.respondError(c, StatusForWorkspaceError(err), err) |
| 165 | return |
| 166 | } |
| 167 | |
| 168 | var req contract.UpdateWorkspaceRequest |
| 169 | if err := c.ShouldBindJSON(&req); err != nil { |
| 170 | h.respondError( |
| 171 | c, |
| 172 | http.StatusBadRequest, |
| 173 | fmt.Errorf("%s: decode update workspace request: %w", h.transportName(), err), |
| 174 | ) |
| 175 | return |
| 176 | } |
| 177 | |
| 178 | var opts workspacepkg.UpdateOptions |
| 179 | if req.Name != nil { |
| 180 | name := strings.TrimSpace(*req.Name) |
| 181 | if name == "" { |
| 182 | h.respondError(c, http.StatusBadRequest, fmt.Errorf("%s: name is required", h.transportName())) |
| 183 | return |
| 184 | } |
| 185 | opts.Name = &name |
| 186 | } |
| 187 | if req.AddDirs != nil { |
| 188 | addDirs := trimStringSliceInternal(*req.AddDirs) |
| 189 | if err := validateAbsolutePathsInternal(h.transportName(), "add_dirs", addDirs); err != nil { |
| 190 | h.respondError(c, http.StatusBadRequest, err) |
| 191 | return |
| 192 | } |
| 193 | opts.AdditionalDirs = &addDirs |
| 194 | } |
| 195 | if req.DefaultAgent != nil { |
| 196 | defaultAgent := strings.TrimSpace(*req.DefaultAgent) |
| 197 | opts.DefaultAgent = &defaultAgent |
| 198 | } |
| 199 | if req.SandboxRef != nil { |
| 200 | sandboxRef := strings.TrimSpace(*req.SandboxRef) |
| 201 | opts.SandboxRef = &sandboxRef |
| 202 | } |
| 203 | |
| 204 | if err := h.Workspaces.Update(c.Request.Context(), workspace.ID, opts); err != nil { |
| 205 | h.respondError(c, StatusForWorkspaceError(err), err) |
| 206 | return |
| 207 | } |
| 208 | |
| 209 | updated, err := h.Workspaces.Get(c.Request.Context(), workspace.ID) |
| 210 | if err != nil { |
| 211 | h.respondError(c, StatusForWorkspaceError(err), err) |
| 212 | return |
| 213 | } |
| 214 | |
| 215 | c.JSON(http.StatusOK, contract.WorkspaceResponse{ |
| 216 | Workspace: WorkspacePayloadFromWorkspace(updated), |
| 217 | }) |
| 218 | } |
nothing calls this directly
no test coverage detected