Merge pull request 'Slate docs: build logs' (#224) from Chewing_Bever/vieter:slate-docs into dev

Reviewed-on: vieter/vieter#224
main
Jef Roosens 2022-06-04 14:49:56 +02:00
commit aea83c38ef
5 changed files with 164 additions and 11 deletions

View File

@ -17,7 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* CLI flags to take advantage of above API improvements
* Added CLI command to generate all man pages
* PKGBUILDs now install man pages
* CLI man pages are now hosted on https://rustybever.be
* Hosted CLI man pages ([vieter(1)](https://rustybever.be/man/vieter/vieter.1.html))
* Proper HTTP API docs ([link](https://rustybever.be/docs/vieter/api/))
### Changed

View File

@ -17,7 +17,7 @@ curl \
https://example.com/api/repos?offset=10&limit=20
```
> JSON Output format
> JSON output format
```json
{
@ -63,7 +63,7 @@ curl \
https://example.com/api/repos/15
```
> JSON Output format
> JSON output format
```json
{
@ -95,7 +95,7 @@ Get info about a specific Git repository.
Parameter | Description
--------- | -----------
repo | ID of requested repo
id | ID of requested repo
## Create a new repo
@ -121,7 +121,13 @@ Modify the data of an existing Git repository.
### HTTP Request
`PATCH /api/repos`
`PATCH /api/repos/:id`
### URL Parameters
Parameter | Description
--------- | -----------
id | ID of requested repo
### Query Parameters
@ -145,4 +151,4 @@ Remove a Git repository from the server.
Parameter | Description
--------- | -----------
repo | ID of repo to remove
id | ID of repo to remove

View File

@ -0,0 +1,140 @@
# Build Logs
<aside class="notice">
All routes in this section require authentication.
</aside>
Endpoints for interacting with stored build logs.
## List logs
```shell
curl \
-H 'X-Api-Key: secret' \
https://example.com/api/logs?offset=10&limit=20
```
> JSON output format
```json
{
"message": "",
"data": [
{
"id": 1,
"repo_id": 3,
"start_time": 1652008554,
"end_time": 1652008559,
"arch": "x86_64",
"exit_code": 0
}
]
}
```
Retrieve a list of build logs.
### HTTP Request
`GET /api/logs`
### Query Parameters
Parameter | Description
--------- | -----------
limit | Maximum amount of results to return.
offset | Offset of results.
repo | Only return builds published to this repository.
before | Only return logs started before this time (UTC epoch)
after | Only return logs started after this time (UTC epoch)
arch | Only return logs built on this architecture
exit_codes | Comma-separated list of exit codes to limit result to; using `!` as a prefix makes it exclude that value. For example, `1,2` only returns logs with status code 1 or 2, while `!1,!2` returns those that don't have 1 or 2 as the result.
## Get build log
```shell
curl \
-H 'X-Api-Key: secret' \
https://example.com/api/logs/15
```
> JSON output format
```json
{
"message": "",
"data": {
"id": 1,
"repo_id": 3,
"start_time": 1652008554,
"end_time": 1652008559,
"arch": "x86_64",
"exit_code": 0
}
}
```
Retrieve info about a specific build log.
### HTTP Request
`GET /api/logs/:id`
### URL Parameters
Parameter | Description
--------- | -----------
id | ID of requested log
## Get log contents
```shell
curl \
-H 'X-Api-Key: secret' \
https://example.com/api/logs/15/content
```
Retrieve the contents of a build log. The response is the build log in
plaintext.
### HTTP Request
`GET /api/logs/:id/content`
### URL Parameters
Parameter | Description
--------- | -----------
id | ID of requested log
## Publish build log
<aside class="warning">
You should probably not use this endpoint, as it's used by the build system to
publish its logs.
</aside>
Publish a new build log to the server.
### HTTP Request
`POST /api/logs`
### Query parameters
Parameter | Description
--------- | -----------
id | ID of requested log
startTime | Start time of the build (UTC epoch)
endTime | End time of the build (UTC epoch)
arch | Architecture on which the build was done
exitCode | Exit code of the build container
### Request body
Plaintext contents of the build log.

View File

@ -42,8 +42,8 @@ pub fn (c &Client) get_build_log_content(id int) ?string {
pub fn (c &Client) add_build_log(repo_id int, start_time time.Time, end_time time.Time, arch string, exit_code int, content string) ?Response<string> {
params := {
'repo': repo_id.str()
'startTime': start_time.str()
'endTime': end_time.str()
'startTime': start_time.unix_time().str()
'endTime': end_time.unix_time().str()
'arch': arch
'exitCode': exit_code.str()
}

View File

@ -70,13 +70,19 @@ fn (mut app App) post_log() web.Result {
}
// Parse query params
start_time := parse_query_time(app.query['startTime']) or {
start_time_int := app.query['startTime'].int()
if start_time_int == 0 {
return app.json(http.Status.bad_request, new_response('Invalid or missing start time.'))
}
start_time := time.unix(start_time_int)
end_time := parse_query_time(app.query['endTime']) or {
end_time_int := app.query['endTime'].int()
if end_time_int == 0 {
return app.json(http.Status.bad_request, new_response('Invalid or missing end time.'))
}
end_time := time.unix(end_time_int)
if 'exitCode' !in app.query {
return app.json(http.Status.bad_request, new_response('Missing exit code.'))