Skip to content

Commit

Permalink
Configure Material for MkDocs code block copy
Browse files Browse the repository at this point in the history
- Enable the new setting `content.code.copy` by default
- Disable code block copying where code is not intended to be copied
- Make REPL code blocks easier to copy by removing `>>>`
  • Loading branch information
br3ndonland committed Nov 11, 2023
1 parent ab692a3 commit 90f75b0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
8 changes: 6 additions & 2 deletions docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ FastAPI is built on Starlette, so a FastAPI app can be configured with middlewar

As described in the [environment variable reference](environment.md) and [contribution guide](contributing.md), when starting the inboard server, the environment variables `BASIC_AUTH_USERNAME` and `BASIC_AUTH_PASSWORD` can be set. The values of these variables can then be passed in with client requests to authenticate.

Server:

```sh
# server
docker pull ghcr.io/br3ndonland/inboard
docker run -d -p 80:80 \
-e "BASIC_AUTH_USERNAME=test_user" \
-e "BASIC_AUTH_PASSWORD=r4ndom_bUt_memorable" \
ghcr.io/br3ndonland/inboard
```

# client: https://httpie.io/
Client (using [HTTPie](https://httpie.io/)):

```sh
http :80/health -a "test_user":"r4ndom_bUt_memorable"
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Please see [inboard Git tags](https://github.com/br3ndonland/inboard/tags), [inb

!!! example "Example Docker tags"

```sh
```{ .sh .no-copy }
# Pull latest FastAPI image (Docker automatically appends the `latest` tag)
docker pull ghcr.io/br3ndonland/inboard

Expand Down
28 changes: 14 additions & 14 deletions docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ The idea here is to allow a catch-all Uvicorn config variable in the spirit of `
!!! example "Example of how to format `UVICORN_CONFIG_OPTIONS` as valid JSON"
```py
>>> import json
>>> import os
>>> uvicorn_config_dict = dict(host="0.0.0.0", port=80, log_config=None, log_level="info", reload=False)
>>> json.dumps(uvicorn_config_dict)
'{"host": "0.0.0.0", "port": 80, "log_config": null, "log_level": "info", "reload": false}'
>>> os.environ["UVICORN_CONFIG_OPTIONS"] = json.dumps(uvicorn_config_dict)
>>> json.loads(os.environ["UVICORN_CONFIG_OPTIONS"]) == uvicorn_config_dict
True
import json
import os
uvicorn_config_dict = dict(host="0.0.0.0", port=80, log_config=None, log_level="info", reload=False)
json.dumps(uvicorn_config_dict)
# '{"host": "0.0.0.0", "port": 80, "log_config": null, "log_level": "info", "reload": false}'
os.environ["UVICORN_CONFIG_OPTIONS"] = json.dumps(uvicorn_config_dict)
json.loads(os.environ["UVICORN_CONFIG_OPTIONS"]) == uvicorn_config_dict
# True
```
!!! warning
Expand All @@ -279,11 +279,11 @@ The idea here is to allow a catch-all Uvicorn config variable in the spirit of `
In the example below, `reload` will be passed through with the correct type (because it was formatted with the correct JSON type initially), but `access_log` will have an incorrect type (because it was formatted as a string instead of as a Boolean).
```py
>>> import json
>>> import os
>>> os.environ["UVICORN_CONFIG_OPTIONS_INCORRECT"] = '{"access_log": "false", "reload": true}'
>>> json.loads(os.environ["UVICORN_CONFIG_OPTIONS_INCORRECT"])
{'access_log': "false", 'reload': True}
import json
import os
os.environ["UVICORN_CONFIG_OPTIONS_INCORRECT"] = '{"access_log": "false", "reload": true}'
json.loads(os.environ["UVICORN_CONFIG_OPTIONS_INCORRECT"])
# {'access_log': "false", 'reload': True}
```
## Logging
Expand Down Expand Up @@ -329,7 +329,7 @@ The idea here is to allow a catch-all Uvicorn config variable in the spirit of `
!!!example "Example log message in different formats"
```log
```{ .log .no-copy }
# simple
INFO Started server process [19012]
Expand Down
19 changes: 11 additions & 8 deletions docs/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ One of the primary use cases for log message filters is health checks. When appl

The `LOG_FILTERS` environment variable can be used to specify filters as a comma-separated string, like `LOG_FILTERS="/health, /heartbeat"`. To then add the filters to a class instance, the `LogFilter.set_filters()` method can produce the set of filters from the environment variable value.

```py
```{ .sh .no-copy }
# start a REPL session in a venv in which inboard is installed
.venv ❯ python
>>> import os
>>> import inboard
>>> os.environ["LOG_FILTERS"] = "/health, /heartbeat"
>>> inboard.LogFilter.set_filters()
{'/heartbeat', '/health'}
```

```py
import os
import inboard
os.environ["LOG_FILTERS"] = "/health, /heartbeat"
inboard.LogFilter.set_filters()
# {'/heartbeat', '/health'}
```

inboard will do this automatically by reading the `LOG_FILTERS` environment variable.
Expand All @@ -49,7 +52,7 @@ docker run \
docker logs -f $(docker ps -q -n 1)
```

```log
```{ .log .no-copy }
DEBUG Logging dict config loaded from inboard.logging_conf.
DEBUG Checking for pre-start script.
DEBUG No pre-start script specified.
Expand All @@ -73,7 +76,7 @@ Make a request to an endpoint that should be logged, using an HTTP client like [

The request will be logged through `uvicorn.access`:

```log
```{ .log .no-copy }
INFO 172.17.0.1:65026 - "GET / HTTP/1.1" 200
```

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ site_url: ""
theme:
favicon: assets/images/favicon.png
features:
- content.code.copy
- header.autohide
- navigation.instant
- navigation.top
Expand Down

0 comments on commit 90f75b0

Please sign in to comment.