Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Service for Managing a Greenbone Feed Key
- [JWT](#jwt)
- [CLI](#cli)
- [API](#api)
- [Logging](#logging)
- [Maintainer](#maintainer)
- [Contributing](#contributing)
- [License](#license)
Expand Down Expand Up @@ -90,13 +91,35 @@ The full API specification can be created by running `greenbone-feed-service-cli
or by enabling the Swagger UI via `--enable-api-doc` or `GREENBONE_FEED_KEY_API_DOC=true`
when running the greenbone-feed-key service.

| Path | Method | Description |
| ---------------- | -------- | ---------------------------------------------------------------------------------------------- |
| `/api/v1/health` | `GET` | A JSON response to indicate the health of the service |
| `/api/v1/key` | `GET` | Get the current available key as `application/octet-stream` |
| `/api/v1/key` | `PUT` | Upload a feed key as `application/octet-stream`. Existing key gets overridden. |
| `/api/v1/key` | `POST` | Upload a feed key via `form/multipart` data in the `file` field. Existing key gets overridden. |
| `/api/v1/key` | `DELETE` | Delete the feed key |
| Path | Method | Description |
| -------------------- | -------- | ---------------------------------------------------------------------------------------------- |
| `/api/v1/health` | `GET` | A JSON response to indicate the health of the service |
| `/api/v1/key` | `GET` | Get the current available key as `application/octet-stream` |
| `/api/v1/key` | `PUT` | Upload a feed key as `application/octet-stream`. Existing key gets overridden. |
| `/api/v1/key` | `POST` | Upload a feed key via `form/multipart` data in the `file` field. Existing key gets overridden. |
| `/api/v1/key` | `DELETE` | Delete the feed key |
| `/api/v1/key/status` | `GET` | A JSON response of the current feed key status |

## Logging

The console output of the greenbone-feed-key service can be adjusted via
the `GREENBONE_FEED_KEY_LOG` environment variable or the `-l, --log` CLI
argument. The logging is implemented via the [tracing library](https://docs.rs/tracing/latest/tracing/)
and uses [env filter directives](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives).

To enable debug logs for all logging/tracing targets the following command can
be used:

```shell
export GREENBONE_FEED_KEY_LOG=debug
```

To enable debug log for http requests and the feed service itself the following
command can be used:

```shell
export GREENBONE_FEED_KEY_LOG=greenbone_feed_key=debug,tower_http=debug
```

## Maintainer

Expand Down
24 changes: 24 additions & 0 deletions tests/features/key.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Feature: Enterprise Feed Key
And the response body should be valid JSON
And the JSON message should be "Unauthorized"

Scenario: If the user is unauthenticated, it should not be possible to get the feed key status
When I send a GET request to the key status endpoint
Then the response status code should be 401
And the response body should be valid JSON
And the JSON message should be "Unauthorized"

Rule: Getting the key

Background:
Expand Down Expand Up @@ -166,3 +172,21 @@ Feature: Enterprise Feed Key
Then the response status code should be 400
And the response body should be valid JSON
And the JSON message should be "Bad request: Key upload failed. Failed to validate key. Invalid Key data"

Rule: Getting the key status

Background:
Given the user is authenticated

Scenario: If the user is authenticated and a feed key exists, the key status should reflect that
Given a valid feed key exists in the system
When I send a GET request to the key status endpoint
Then the response status code should be 200
And the response body should be valid JSON
And the response JSON property "hasKey" should be "true"

Scenario: If the user is authenticated and no feed key exists, the key status should reflect that
Given no feed key exists in the system
Then the response status code should be 200
And the response body should be valid JSON
And the response JSON property "hasKey" should be "false"
4 changes: 3 additions & 1 deletion tests/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use tower::ServiceExt;

const HEALTH_API: &str = "/api/v1/health";
const KEY_API: &str = "/api/v1/key";
const KEY_STATUS_API: &str = "/api/v1/key/status";
const OPENAPI_DOCS_API: &str = "/api/v1/openapi.json";
const SWAGGER_UI_URL: &str = "/swagger-ui/";
const SHARED_SECRET: &str = "some-secret";
Expand Down Expand Up @@ -143,12 +144,13 @@ fn given_the_feed_key_file_is_not_writable(world: &mut ServiceWorld) {
}

#[when(
regex = r"^I send a (GET|DELETE|POST|PUT) request to the (key endpoint|health endpoint|API documentation|swagger UI)$"
regex = r"^I send a (GET|DELETE|POST|PUT) request to the (key endpoint|key status endpoint|health endpoint|API documentation|swagger UI)$"
)]
async fn when_i_send_a_request(world: &mut ServiceWorld, method: String, endpoint: String) {
let builder = Request::builder();
let builder = match endpoint.as_str() {
"key endpoint" => builder.uri(KEY_API),
"key status endpoint" => builder.uri(KEY_STATUS_API),
"health endpoint" => builder.uri(HEALTH_API),
"API documentation" => builder.uri(OPENAPI_DOCS_API),
"swagger UI" => builder.uri(SWAGGER_UI_URL),
Expand Down
Loading