Files
opencloud/tests/ocwrapper/README.md
T
Viktor Scharf 0d42e7228f test: get the audit records from the ocwrapper (#4174)
The audit log tests read the audit records from a copy of the server
output, which the CI wrote with "| tee" to a file given to the tests in
AUDIT_RECORDS_FILE. The ocwrapper reads the server output anyway: it now
keeps the audit records, and returns them on GET /audit (DELETE /audit
clears them). The tests clear them when a scenario starts and fetch them
from there, so they need no extra setup in the CI or locally.

Assisted-by: Claude Code:claude-opus-5-5
2026-12-01 14:46:25 +01:00

143 lines
3.4 KiB
Markdown

## OpenCloud Wrapper
A tool that wraps the OpenCloud binary and provides a way to re-configure the running OpenCloud instance.
When run, **ocwrapper** starts an API server that exposes some endpoints to re-configure the OpenCloud server.
### Usage
1. Build
```bash
make build
```
2. Run
```bash
./bin/ocwrapper serve --bin=<path-to-opencloud-binary>
```
To check other available options:
```bash
./bin/ocwrapper serve --help
```
```bash
--url string OpenCloud server url (default "https://localhost:9200")
--retry string Number of retries to start OpenCloud server (default "5")
-p, --port string Wrapper API server port (default "5200")
--admin-username string admin username for OpenCloud server
--admin-password string admin password for OpenCloud server
```
Access the API server at `http://localhost:5200`.
Also, see `./bin/ocwrapper help` for more information.
### API
**ocwrapper** exposes two endpoints:
1. `PUT /config`
Updates the configuration of the running OpenCloud instance.
Body of the request should be a JSON object with the following structure:
```json
{
"ENV_KEY1": "value1",
"ENV_KEY2": "value2"
}
```
Returns:
- `200 OK` - OpenCloud is successfully reconfigured
- `400 Bad Request` - request body is not a valid JSON object
- `500 Internal Server Error` - OpenCloud server is not running
2. `DELETE /rollback`
Rolls back the configuration to the starting point.
Returns:
- `200 OK` - rollback is successful
- `500 Internal Server Error` - OpenCloud server is not running
3. `POST /command`
Executes the provided command on the OpenCloud server. The body of the request should be a JSON object with the following structure:
```yml
{
"command": "<opencloud-command>", # without the OpenCloud binary. e.g. "list"
}
```
If the command requires user input, the body of the request should be a JSON object with the following structure:
```json
{
"command": "<opencloud-command>",
"inputs": ["value1"]
}
```
Returns:
```json
{
"status": "OK",
"exitCode": 0,
"message": "<command output>"
}
OR
{
"status": "ERROR",
"exitCode": <error-exit-code>,
"message": "<command output>"
}
```
- `200 OK` - command is successfully executed
- `400 Bad Request` - request body is not a valid JSON object
- `500 Internal Server Error`
4. `POST /start`
Starts the OpenCloud server.
Returns:
- `200 OK` - OpenCloud server is started
- `409 Conflict` - OpenCloud server is already running
- `500 Internal Server Error` - Unable to start OpenCloud server
5. `POST /stop`
Stops the OpenCloud server.
Returns:
- `200 OK` - OpenCloud server is stopped
- `500 Internal Server Error` - Unable to stop OpenCloud server
6. `GET /audit`
Returns the audit records the OpenCloud server wrote to its output (the lines of JSON with an `event.name`), as a JSON array, since the start of the wrapper or the last `DELETE /audit`.
Returns:
- `200 OK` - the records, e.g. `[{"event.name": "opencloud.file.upload", ...}]`
7. `DELETE /audit`
Forgets the audit records kept so far, e.g. at the start of a scenario.
Returns:
- `200 OK` - the records are cleared