Skip to content

Commit

Permalink
docs: autogenerate configurations
Browse files Browse the repository at this point in the history
Co-authored-by: tc-imba <[email protected]>
Co-authored-by: Reapor-Yurnero <[email protected]>
  • Loading branch information
tc-imba and Reapor-Yurnero committed Jun 24, 2024
1 parent 7808149 commit 6e0563c
Show file tree
Hide file tree
Showing 23 changed files with 2,880 additions and 2,199 deletions.
49 changes: 37 additions & 12 deletions brick_server/playground/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import click
import uvicorn
from click_default_group import DefaultGroup
from loguru import logger

from brick_server.playground.config.manager import settings

Expand Down Expand Up @@ -33,10 +34,26 @@ def serve() -> None:

@click.command()
def generate_docs():
from brick_server.minimal.config.settings.base import DatabaseMongoDBSettings
from settings_doc.main import generate

docs_classes = [DatabaseMongoDBSettings]
from brick_server.minimal.config.settings import base as minimal_base
from settings_doc.main import app
from typer.testing import CliRunner

from brick_server.playground.config.settings import base as playground_base

runner = CliRunner()
docs_classes = [
minimal_base.DatabaseMongoDBSettings,
minimal_base.DatabaseRedisSettings,
minimal_base.DatabaseTimescaleDBSettings,
minimal_base.DatabaseGraphDBSettings,
minimal_base.DatabaseInfluxDBSettings,
minimal_base.AuthGeneralSettings,
minimal_base.AuthCORSSettings,
minimal_base.AuthGoogleOAuthSettings,
minimal_base.BackendMinimalSettings,
minimal_base.BackendBrickSettings,
playground_base.BackendPlaygroundSettings,
]

docs_generated_path = (
pathlib.Path(__file__).parent.parent.parent.absolute() / "docs" / "generated"
Expand All @@ -48,15 +65,23 @@ def generate_docs():
output_path = docs_generated_path / f"{doc_class.__qualname__}.md"
output_path.touch(exist_ok=True)

generate(
class_path=class_path,
output_format="md",
logger.info("Generate docs for class {} in {}", class_path, output_path)
result = runner.invoke(
app,
[
"generate",
"--class",
class_path,
"--output-format",
"markdown",
"--heading-offset",
"2",
"--update",
str(output_path),
],
)

print(class_path)
print(output_path)

pass
if result.exit_code != 0:
logger.error("Failed! Error message: {}", result.stdout)


# @click.command()
Expand Down
15 changes: 0 additions & 15 deletions docs/config.md

This file was deleted.

13 changes: 13 additions & 0 deletions docs/config/auth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Authorization

## General

{% include-markdown "generated/AuthGeneralSettings.md" %}

## CORS

{% include-markdown "generated/AuthCORSSettings.md" %}

## Google OAuth2

{% include-markdown "generated/AuthGoogleOAuthSettings.md" %}
13 changes: 13 additions & 0 deletions docs/config/backend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Backend

## Minimal

{% include-markdown "generated/BackendMinimalSettings.md" %}

## Brick

{% include-markdown "generated/BackendBrickSettings.md" %}

## Playground

{% include-markdown "generated/BackendPlaygroundSettings.md" %}
21 changes: 21 additions & 0 deletions docs/config/db.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Database

## MongoDB

{% include-markdown "generated/DatabaseMongoDBSettings.md" %}

## GraphDB

{% include-markdown "generated/DatabaseGraphDBSettings.md" %}

## Redis

{% include-markdown "generated/DatabaseRedisSettings.md" %}

## TimescaleDB

{% include-markdown "generated/DatabaseTimescaleDBSettings.md" %}

## InfluxDB

{% include-markdown "generated/DatabaseInfluxDBSettings.md" %}
1 change: 1 addition & 0 deletions docs/config/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Configuration
14 changes: 7 additions & 7 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ First, we need to clone `brick-server-minimal`, `brick-server-playground`, `bric
mkdir brick
git clone https://github.com/BrickSchema/brick-example-server
git clone https://github.com/BrickSchema/playground
git clone
git clone
```

## Configuration

Create a `.env` file in the playground directory. The file can be used to configure the playground server.
The detailed configurable items can be found [here](config.md).
Create a `.env` file in the playground directory. The file can be used to configure the playground server.
The detailed configurable items can be found [here](config/index.md).

```bash
cd playground
Expand All @@ -27,17 +27,17 @@ touch .env
=== "Docker (recommended)"

In the playground directory, run

```bash
docker-compose up --build -d # (1)!
```
1. make sure the context is correct if not using `docker-compose` but `docker build`

1. make sure the context is correct if not using `docker-compose` but `docker build`
and make sure the `docker-compose` version is at least `v2`

=== "Direct"

(Not yet completed)

Then, open `http://localhost:9000/brickapi/v1/docs`. If the swagger API page is shown, congratulations!
Then, open `http://localhost:9000/brickapi/v1/docs`. If the swagger API page is shown, congratulations!
Now you can move to the [next step](init.md) in initialize playground.
17 changes: 17 additions & 0 deletions docs/generated/AuthCORSSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### `IS_ALLOWED_CREDENTIALS`

*Optional*, default value: `True`

CORS allowed credentials

### `ALLOWED_ORIGINS`

*Optional*, default value: `['http://localhost:3000', 'http://0.0.0.0:3000', 'http://127.0.0.1:3000', 'http://127.0.0.1:3001', 'http://localhost:5173', 'http://0.0.0.0:5173', 'http://127.0.0.1:5173', 'http://127.0.0.1:5174']`

### `ALLOWED_METHODS`

*Optional*, default value: `['*']`

### `ALLOWED_HEADERS`

*Optional*, default value: `['*']`
53 changes: 53 additions & 0 deletions docs/generated/AuthGeneralSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
### `API_TOKEN`

*Optional*, default value: `YOUR-API-TOKEN`

API token

### `AUTH_TOKEN`

*Optional*, default value: `YOUR-AUTHENTICATION-TOKEN`

Authentication token

### `JWT_SECRET_KEY`

*Optional*, default value: `YOUR-JWT-SECRET-KEY`

JWT secret key

### `JWT_SUBJECT`

*Optional*, default value: `brick`

JWT subject

### `JWT_TOKEN_PREFIX`

*Optional*, default value: `brick`

JWT token prefix

### `JWT_ALGORITHM`

*Optional*, default value: `HS256`

JWT algorithm

### `JWT_MIN`

*Optional*, default value: `0`

JWT expiration minute

### `JWT_HOUR`

*Optional*, default value: `0`

JWT expiration hour

### `JWT_DAY`

*Optional*, default value: `14`

JWT expiration day
11 changes: 11 additions & 0 deletions docs/generated/AuthGoogleOAuthSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### `OAUTH_GOOGLE_CLIENT_ID`

*Optional*, default value: ``

Google OAuth client id

### `OAUTH_GOOGLE_CLIENT_SECRET`

*Optional*, default value: ``

Google OAuth client secret
17 changes: 17 additions & 0 deletions docs/generated/BackendBrickSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### `BRICK_VERSION`

*Optional*, default value: `1.3`

Brick version used.

### `DEFAULT_BRICK_URL`

*Optional*, default value: `https://brickschema.org/schema/Brick`

Brick schema URL.

### `DEFAULT_REF_SCHEMA_URL`

*Optional*, default value: `https://gist.githubusercontent.com/tc-imba/714c2043e893b1538406a9113140a4fe/raw/2fa8df840f3e4f1deb647b14fe524976f004e321/ref-schema.ttl`

Ref schema URL.
49 changes: 49 additions & 0 deletions docs/generated/BackendMinimalSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
### `API_PREFIX`

*Optional*, default value: `/brickapi/v1`

### `DOCS_URL`

*Optional*, default value: `/brickapi/v1/docs`

### `OPENAPI_URL`

*Optional*, default value: `/brickapi/v1/openapi.json`

### `REDOC_URL`

*Optional*, default value: `/brickapi/v1/redoc`

### `OPENAPI_PREFIX`

*Optional*, default value: ``

### `SERVER_HOST`

*Optional*, default value: `0.0.0.0`

Bind socket to this host.

### `SERVER_PORT`

*Optional*, default value: `9000`

Bind socket to this port. If 0, an available port will be picked

### `SERVER_WORKERS`

*Optional*, default value: `1`

Number of worker processes.

### `FRONTEND_URL`

*Optional*, default value: `/brickapi/v1/docs`

URL to frontend. Usually used for auth redirection.

### `CACHE`

*Optional*, default value: `True`

Enable caching.
23 changes: 23 additions & 0 deletions docs/generated/BackendPlaygroundSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
### `DEFAULT_ADMIN`

*Optional*, default value: `[email protected]`

The email of default admin user. (deprecated, we should remove it in future version)

### `ISOLATED_NETWORK_NAME`

*Optional*, default value: `isolated_nw`

The name of the isolated network in docker.

### `DOCKER_PREFIX`

*Optional*, default value: `brick-server-playground`

The docker prefix to use in app containers.

### `APP_STATIC_DIR`

*Optional*, default value: `app_static`

The directory to save app static files.
17 changes: 17 additions & 0 deletions docs/generated/DatabaseGraphDBSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### `GRAPHDB_HOST`

*Optional*, default value: `localhost`

GraphDB host

### `GRAPHDB_PORT`

*Optional*, default value: `7200`

GraphDB port

### `GRAPHDB_REPOSITORY`

*Optional*, default value: `brickserver`

GraphDB repository
23 changes: 23 additions & 0 deletions docs/generated/DatabaseInfluxDBSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
### `INFLUXDB_URL`

*Optional*, default value: `https://us-east-1-1.aws.cloud2.influxdata.com`

InfluxDB URL

### `INFLUXDB_TOKEN`

*Optional*, default value: ``

InfluxDB access token

### `INFLUXDB_ORG`

*Optional*, default value: `9d4d3af8fd50fcbb`

InfluxDB org name

### `INFLUXDB_BUCKET`

*Optional*, default value: `CO2-Exp`

InfluxDB bucket
Loading

0 comments on commit 6e0563c

Please sign in to comment.