Skip to content

Commit

Permalink
Merge pull request #5 from icebreakerone/kip/refactor-with-resource-api
Browse files Browse the repository at this point in the history
Kip/refactor with resource api
  • Loading branch information
kipparker authored Feb 20, 2024
2 parents 4600d82 + f2f2008 commit aa19a37
Show file tree
Hide file tree
Showing 50 changed files with 5,659 additions and 805 deletions.
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

0 comments on commit aa19a37

Please sign in to comment.