Skip to content

Commit

Permalink
Update configuration docs
Browse files Browse the repository at this point in the history
  • Loading branch information
criccomini committed Oct 10, 2023
1 parent 758ad08 commit 182e60a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
42 changes: 21 additions & 21 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,37 @@ Recap uses [pydantic-settings](https://docs.pydantic.dev/latest/usage/pydantic_s
| :-- | :-- | :-- | :-: | :-: |
| RECAP_CONFIG | TEXT | Path to the config file. | ~/.recap/config | YES |
| RECAP_SECRETS | TEXT | Path to the secrets directory. | | NO |
| RECAP_SYSTEMS__[SYSTEM] | TEXT | A system name/URL pair that tells Recap how to connect to a system. | | NO |
| RECAP_URLS | TEXT| List of URLs in JSON format containing authorization credentials. | | NO |
| RECAP_REGISTRY_STORAGE_URL | TEXT | Location to store registry schemas in an [`fsspec`-compatible URL format](https://filesystem-spec.readthedocs.io/en/latest/api.html#other-known-implementations). | | NO |
| RECAP_REGISTRY_STORAGE_ARGS | TEXT | Additional attributes to supply when creating the registry's `fsspec` filesystem object. | | NO |

{: .note }
The `RECAP_SYSTEMS__` environment variable is a special case. It's used to configure systems. The `SYSTEM` part of the variable name is the name of the system. The value is the URL to connect to the system. For example, `RECAP_SYSTEMS__MY_PG=postgresql://user:pass@host:port/dbname` will configure a system called `my_pg` to connect to a PostgreSQL database.
#### RECAP_URLS

The `RECAP_URLS` environment variable is important. It allows you to define connection strings for URLs that contain login credentials like usernames and passwords or authentication tokens.

## CLI
For example, if you have a URL like `postgresql://user:pass@localhost:5432/testdb`, you can set the `RECAP_URLS` environment variable like so:

```bash
export RECAP_URLS='["postgresql://some_user:some_pass@localhost:5432/testdb"]'
```

Recap's CLI has [`add`](/docs/cli#add) and [`remove`](/docs/cli#remove) commands to add and remove systems from Recap's config file (`RECAP_CONFIG`). These commands are just shortcuts for editing the config file directly.
All `ls` or `schema` calls for the URL will use the credentials defined in the environment variable.

### Add a System
You don't need to specify a full path for URL credentials. Recap will substitute in any username, password, or query parameters that are defined in the environment variable, so this command:

```bash
recap add my_pg postgresql://user:pass@host:port/dbname
curl http://localhost:8000/gateway/ls/postgresql://localhost:5432/testdb/public
```

### Remove a System
Would be translated to:

```bash
recap remove my_pg
curl http://localhost:8000/gateway/ls/postgresql://some_user:some_pass@localhost:5432/testdb/public
```

{: .note }
The URL matching is done on the scheme ("postgresql" in our example) and netloc ("localhost:5432" in our example) for a URL.

## Dotenv

Recap supports [`.env`](https://github.com/motdotla/dotenv) files as well. Recap will look for a `.env` file in the current working directory and load it if it exists. If not, it'll recurse upwards until it finds one.
Expand All @@ -71,20 +81,10 @@ See [pydantic-settings](https://docs.pydantic.dev/latest/usage/pydantic_settings

Recap supports a secrets directory (`RECAP_SECRETS`) that contains files with secrets. Each file's name corrseponds to its environment variable name, and each file's contents are the environment variable's value.

For example, if Recap is configured to use `/path/to/secrets` as its secrets directory, and `/path/to/secrets/recap_systems__my_pg` contains `postgresql://localhost:5432/testdb`, then Recap will see `RECAP_SYSTEMS__MY_PG`'s value as `postgresql://localhost:5432/testdb`.

{: .warning }
> If you want to set more than one system, you'll need to use the secret filename `recap_systems`. The contents should be a JSON-encoded map from system name to system URL. For example:
>
> ```json
> {
> "my_bq": "bigquery://",
> "my_pg": "postgresql://localhost:5432/testdb"
> }
> ```
For example, if Recap is configured to use `/path/to/secrets` as its secrets directory, and `/path/to/secrets/recap_urls` contains `["postgresql://user:passlocalhost:5432/testdb"]`, then Recap will use the credentials defined in the file for any `ls` or `schema` calls for the URL.

See [pydantic-settings](https://docs.pydantic.dev/latest/usage/pydantic_settings#secrets)'s secrets section for more information.

### Docker

If you're deploying Recap's [gateway](/docs/gateway) in Docker, see the [Gateway Docker](/docs/gateway#docker) documentation and [pydantic-settings](https://docs.pydantic.dev/latest/usage/pydantic_settings/#use-case-docker-secrets) for Docker secrets instructions.
If you're deploying Recap's server in Docker, see the [gateway](/docs/gateway#docker) and [registry](/docs/registry#docker) documentation and [pydantic-settings](https://docs.pydantic.dev/latest/usage/pydantic_settings/#use-case-docker-secrets) for Docker secrets instructions.
30 changes: 14 additions & 16 deletions docs/gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Running Recap's stateless HTTP/JSON gateway server.

## Overview

Recap comes with a stateless HTTP/JSON server that you can use to query systems and schemas. The server doesn't require any database or storage. It's a simple gateway that connects to systems and returns Recap schemas.
Recap's HTTP/JSON server comes with a gateway API that you can use to query systems and schemas. The server doesn't require any database or storage. It's simply a gateway that connects to systems and returns Recap schemas.

## Usage

Expand All @@ -30,36 +30,34 @@ See the [CLI](/docs/cli#serve) documentation for additional `serve` parameters a
{: .note }
The gateway server is a simple [FastAPI](https://fastapi.tiangolo.com/) application. The `serve` command starts the FastAPI application using [uvicorn](https://www.uvicorn.org/). You may choose any ASGI-compatible server. See [FastAPI's documentation](https://fastapi.tiangolo.com/deployment/manually/) for more information.

## Configuration

You must define Recap "system" connections as environment variables before starting the gateway server. Recap uses these environment variables to connect to systems.

Here's an example for a PostgreSQL system:
You can query a system like so:

```bash
export MY_PG=postgresql://user:pass@host:port/dbname
curl http://localhost:8000/gateway/ls/postgresql://user:pass@localhost:5432/testdb
```

Or you can use Recap's CLI:
And read a schema:

```bash
recap add my_pg postgresql://user:pass@host:port/dbname
curl http://localhost:8000/gateway/schema/postgresql://user:pass@localhost:5432/testdb/public/test_types
```

After running `recap serve`, you can query the system using the `my_pg` name:
## Configuration

The gateway will work out of the box without any configuration. Any URL with a compatible [client integration](/docs/integrations/) will work. However, you can configure Recap to save access credentials in an environment variable using the `RECAP_URLS` environment variable.

```bash
curl http://localhost:8000/ls/my_pg
```
- `RECAP_URLS`: A JSON-encoded list of URLs to connect to.

See the [configuration](/docs/configuration) for more information on the `RECAP_URLS` environment variable.

You can also set environment variables in .env files or secrets files. See Recap's [configuration](/docs/configuration) documentation for more information.

## API

Recap's gateway server exposes a very simple HTTP/JSON API with two endpoints:

* `/ls/[path*]` - List children in a system path.
* `/schema/[path*]` - Get a schema for a system path.
* `/gateway/ls/[url]` - List children of a URL.
* `/gateway/schema/[url]` - Get a schema for a URL.

### OpanAPI

Expand All @@ -86,7 +84,7 @@ You can run the server using the `docker run` command:
```bash
docker run \
-p 8000:8000 \
-e "RECAP_SYSTEMS__PG=postgresql://user:pass@localhost:5432/testdb" \
-e "RECAP_URLS='[\"postgresql://user:pass@pg:5432/testdb\"]'" \
ghcr.io/recap-build/recap:latest
```

Expand Down

0 comments on commit 182e60a

Please sign in to comment.