notebooks/workspaces/backend/api
Andy Stoneberg 843e5c3c48
feat(ws): add workspace pause actions backend API (#340)
related: #298

- Added PauseActionWorkspaceHandler to handle pausing or unpausing a given workspace
- Introduced single new route for starting and pausing workspaces in the API.
    - `api/v1/workspaces/{namespace}/{name}/actions/pause`
			- pausing or unpausing operation is specified in the request payload
- Created a new WorkspaceActionPauseEnvelope type for successful responses.
- Leveraging JSONPatch / client.RawPatch to ensure Workspace in "valid state" before attempting action
    - for `start`: `spec.paused` must be `true`, and `status.state` must be `Paused`
    - for `pause`: `spec.paused` must be `false`
        - note: I would love to have a `status.state` check here of `status.state != Paused`, but that type of comparison is not supported in [JSONPatch](https://datatracker.ietf.org/doc/html/rfc6902#section-4.6)
- Added tests for the new API, including success and error cases.
- Updated README/OpenAPI documentation to include the new endpoints.

---

As an interesting "edge case" worth calling out, the following payload is currently honored by the API:
```
{
  "data": {}
}
```

Given the `WorkspaceActionPause` struct is simply `{"paused": true|false}`, the "empty" Envelope presented above deserializes the JSON using the zero value of `bool` (which is `false`).

Our validation today is always performed against the **deserialized** object, and as such impossible to distinguish the following cases:
```
{
  "data": {}
}
```

vs

```
{
  "data": {
    "paused": false
  }
}
```

The effort and (relative) complexity to prevent this and return a `422` in this scenario was not deemed "worth it" for the time being.  As a result, a test case has been added for this specific scenario to at minimum document this "strange" behavior.
- Clients, however, should **NOT** rely on this behavior and always provide a fully defined `WorkspaceActionPause` JSON object to ensure future compatibility.

Signed-off-by: Andy Stoneberg <astonebe@redhat.com>
2025-07-24 20:05:02 +00:00
..
app.go feat(ws): add workspace pause actions backend API (#340) 2025-07-24 20:05:02 +00:00
auth.go feat(ws): add auth to backend (#202) 2025-02-11 20:21:28 +00:00
healthcheck_handler.go feat(ws): add swagger api docs to backend (#206) 2025-03-03 02:28:36 +00:00
healthcheck_handler_test.go feat(ws): add WorkspaceCreate model to backend (#205) 2025-02-14 22:25:37 +00:00
helpers.go feat(ws): backend api to create wsk with YAML (#434) 2025-07-06 06:57:21 +00:00
logging.go feat(ws): add WorkspaceCreate model to backend (#205) 2025-02-14 22:25:37 +00:00
middleware.go feat(ws): introduce limits on HTTP body/header size (#195) 2025-02-05 20:54:38 +00:00
namespaces_handler.go feat(ws): complete api swagger documentation across workspaces, namespaces, and workspacekinds (#235) 2025-05-15 16:33:23 +00:00
namespaces_handler_test.go feat(ws): add WorkspaceCreate model to backend (#205) 2025-02-14 22:25:37 +00:00
response_errors.go feat(ws): backend api to create wsk with YAML (#434) 2025-07-06 06:57:21 +00:00
response_success.go feat(ws): add WorkspaceCreate model to backend (#205) 2025-02-14 22:25:37 +00:00
suite_test.go feat(ws): add ws counts to backend wsk model (#368) 2025-07-24 19:36:01 +00:00
swagger_handler.go feat(ws): add swagger api docs to backend (#206) 2025-03-03 02:28:36 +00:00
workspace_actions_handler.go feat(ws): add workspace pause actions backend API (#340) 2025-07-24 20:05:02 +00:00
workspace_actions_handler_test.go feat(ws): add workspace pause actions backend API (#340) 2025-07-24 20:05:02 +00:00
workspacekinds_handler.go feat(ws): backend api to create wsk with YAML (#434) 2025-07-06 06:57:21 +00:00
workspacekinds_handler_test.go feat(ws): backend api to create wsk with YAML (#434) 2025-07-06 06:57:21 +00:00
workspaces_handler.go feat(ws): backend api to create wsk with YAML (#434) 2025-07-06 06:57:21 +00:00
workspaces_handler_test.go feat(ws): backend api to create wsk with YAML (#434) 2025-07-06 06:57:21 +00:00