This project is an OpenAPI REST Proxy that allows you to easily create a RESTful API based on an OpenAPI specification, filtering through a selection of allowed endpoints.
The proxy service passes request headers to the origin it is configured to proxy, and similarly passes through response headers from the origin (right now without particular smarts).
Make sure you have uv installed.
-
Clone the repository:
git clone https://github.com/canonical/openapi-rest-proxy.git cd openapi-rest-proxy
-
Start the server:
ENDPOINT_ALLOW_LIST='GET:/api/v2/certified-configurations' \ OPENAPI_SCHEMA_URL='https://certification.canonical.com/api/v2/openapi' \ ORIGIN_BASE_URL='https://certification.canonical.com' \ HOST='0.0.0.0' \ PORT=8000 \ uv run uvicorn proxy.app:app --reload
The server will be running at http://localhost:8000
by default.
The following environment variables can be set to configure the server:
ENDPOINT_ALLOW_LIST
: A|
-separated list of allowed endpoints in the formatMETHOD:PATH
(e.g.,GET:/api/v2/certified-configurations
).|
is used as a delimiter since it is not itself a valid character in a path.OPENAPI_SCHEMA_URL
: The URL of the OpenAPI schema to use (e.g.,https://certification.canonical.com/api/v2/openapi
).ORIGIN_BASE_URL
: The base URL of the origin server (e.g.,https://certification.canonical.com
).PORT
: The port on which the server will run (default is8000
).HOST
: The host on which the server will run (default is0.0.0.0
).FIXED_REQUEST_HEADERS
: A|
-separated list of fixed request headers in the formatHEADER:VALUE
(e.g.,Authorization:Bearer token|X-Custom-Header:Value
) which are included in all requests to the origin.AUTH_ENDPOINT_URL
: The URL of the OAuth2 token endpoint (e.g.,https://auth.example.com/o/token/
).CLIENT_ID
: The client ID for OAuth2 authentication.CLIENT_SECRET
: The client secret for OAuth2 authentication.AUTH_SCOPE
: The scope for OAuth2 authentication (optional).
uv run pytest tests/unit
To run the integration tests, you need to have a server up serving the test fixtures (example toy OpenAPI schema and a toy API response). Easiest accomplished for local development with the help of docker-compose. In the root of the project, issue the following:
docker-compose up schema -d
Once you have the test fixture server running, run integration tests from the root of the project:
uv run pytest tests/integration
This project is licensed under the Affero GPL 3.0 License.