Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kip/refactor with resource api #5

Merged
merged 11 commits into from
Feb 20, 2024
Merged
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
28 changes: 28 additions & 0 deletions .github/templates/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: test
description: Run python tests
inputs:
folder:
description: 'The folder to run tests in'
required: true

runs:
using: "composite"
steps:
- name: Install ${{ inputs.folder }} dependencies
shell: bash
run: |
cd ${{ inputs.folder }}
pip install pipenv
pipenv install --dev
- name: Lint with ruff
shell: bash
run: |
# stop the build if there are Python syntax errors or undefined names
cd ${{ inputs.folder }}
pipenv run ruff .
- name: Run ${{ inputs.folder }} tests
shell: bash
run: |
# stop the build if there are Python syntax errors or undefined names
cd ${{ inputs.folder }}
pipenv run pytest .
28 changes: 0 additions & 28 deletions .github/workflows/test.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/test_authentication.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Python tests authentication

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Run tests
uses: ./.github/templates/test/
with:
folder: authentication
17 changes: 17 additions & 0 deletions .github/workflows/test_resource.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Python tests resource

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Run tests
uses: ./.github/templates/test/
with:
folder: resource
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
# Perseus demo authentication api
# Perseus demo energy provider

Emulates authentication endpoints for the Perseus demo. These endpoints in production will be provided by an energy provider's authentication platform. Api documentation is available at https://perseus-demo-authentication.ib1.org/api-docs.
Emulates authentication and resource api endpoints for the Perseus demo.

The authentication api is responsible for authenticating and identifying its own users, and for handling and passing on requests from the client API to the FAPI API.
## Authentication API

## Run the dev server
The authentication app is in the [authentication](authentication) directory. It provides endpoints for authenticating and identifying users, and for handling and passing on requests from the client API to the FAPI API.

Authentication API documentation is available at https://perseus-demo-authentication.ib1.org/api-docs.

## Resource API

The resource api is in the [resource](resource) directory. It demonstrates how to protect an API endpoint using a certificate bound token obtained from the authentication API's interaction with the FAPI provider.

Resource API documentation is available at https://perseus-demo-energy.ib1.org/api-docs.

## Running a dev server

```bash
cd authentication|resource
pipenv install --dev
pipenv run uvicorn api.main:app --reload
```

## Running the local docker environment

The included docker compose file will bring up both APIs. It uses nginx to proxy requests to uvicorn, with nginx configuration to pass through client certificates to the backend, using the same header as used by AWS ALB (`x-amzn-mtls-clientcert`). It requires a set of certificates as generated by [scripts/certmaker.sh], which should be available in the `certs` directory

```bash
docker-compose up
```

The docker environment uses nginx to proxy requests to uvicorn, with nginx configuration to pass through client certificates to the backend, using the same header as used by AWS ALB (`x-amzn-mtls-clientcert`). It requires a set of certificates as generated by [scripts/certmaker.sh], which should be available in the `certs` directory.
The environment variables in the docker compose file point to the FAPI api running on localhost port 8020 (http://host.docker.internal:8020). As the FAPI api is not running in the docker environment, you may need to change these environment variables to match your local environment. It will also work with the live FAPI api by changing these values to "https://perseus-demo-fapi.ib1.org".

## Testing the API with client.py

Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions backend/Pipfile → authentication/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ pyjwt = "*"
uvicorn = "*"
requests = "*"
python-jose = {extras = ["cryptography"] }
passlib = {extras = ["bcrypt"] }
python-multipart = "*"
httpx = "*"
bcrypt = "*"

[dev-packages]
black = "*"
mypy = "*"
ruff = "*"
types-python-jose = "*"
types-passlib = "*"
types-requests = "*"
pytest = "*"
responses = "*"
pytest-mock = "*"

[requires]
python_version = "3.12"
Loading
Loading