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

Port API to FastAPI #133 #134

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
9a5d86b
Drop support for Python versions below 3.11 #93 #94 #95
VKTB Oct 28, 2024
f7cc27a
Replace Flask-RESTful dependencies with FastAPI #133
VKTB Oct 28, 2024
03c59c7
Update dependencies to latest versions #133
VKTB Oct 28, 2024
e9ce95c
Delete wsgi.py module #133
VKTB Nov 4, 2024
b4ee440
Set black's and flake's max line length to 120 #133
VKTB Nov 4, 2024
cf5ffb0
Add severity value to scheduled_maintenance.json file #133
VKTB Nov 4, 2024
286c554
Define custom exception classes #133
VKTB Nov 4, 2024
5450937
Refactor logger logic to use configuration from .ini file #133
VKTB Nov 4, 2024
f7e5768
Add a logging.ini example file #133
VKTB Nov 4, 2024
3aa29ee
Define API schema models #133
VKTB Nov 4, 2024
e03840e
Refactor ICATAuthenticator and AuthenticationHandler classes #133
VKTB Nov 4, 2024
c98de7b
Refactor MaintenanceMode and ScheduledMaintenanceMode classes #133
VKTB Nov 4, 2024
2dfbbdc
Implement authentication API router #133
VKTB Nov 4, 2024
69583f0
Implement maintenance API router #133
VKTB Nov 4, 2024
45ac714
Remove unnecessary config values #133
VKTB Nov 4, 2024
248dff5
Update config.json example file #133
VKTB Nov 4, 2024
8009cc0
Update constants.py module #133
VKTB Nov 4, 2024
bd480b3
Update .gitignore #133
VKTB Nov 4, 2024
da03c8f
Update main module #133
VKTB Nov 4, 2024
6db30b2
Update noxfile.py #133
VKTB Nov 4, 2024
a86f3f9
Update CI workflow file #133
VKTB Nov 4, 2024
af54b65
Fix syntax error in CI workflow file #133
VKTB Nov 4, 2024
88dae1c
Remove openapi.yaml file #133
VKTB Nov 5, 2024
11a5460
Use .env file and pydantic BaseSettings for configuration #133
VKTB Nov 5, 2024
fd56c1a
Add pytest-env as dev dependency #133
VKTB Nov 7, 2024
fb6894c
Refactor logic #133
VKTB Nov 8, 2024
c80ac0c
Check usernames in tokens match before refreshing access token #129
VKTB Nov 8, 2024
840d253
Redo tests #133
VKTB Nov 8, 2024
aea6b5d
Configure nox tests session to use pytest config file #133
VKTB Nov 8, 2024
04d05f1
Fix failing test CI job #133
VKTB Nov 8, 2024
b093a52
Set timeout for ICAT requests #133
VKTB Nov 12, 2024
9eab439
Fix failing tests #133
VKTB Nov 12, 2024
f5ef933
Define a Docker stage for local development #133
VKTB Nov 12, 2024
ef559d8
Define a Docker stage for running tests #133
VKTB Nov 12, 2024
1a229ee
Define a Docker stage for production #133
VKTB Nov 12, 2024
4d506ee
Set target stage in Docker CI job #133
VKTB Nov 12, 2024
445d618
Change responses for PUT maintenance endpoints #133
VKTB Nov 12, 2024
b923526
Configure tests CI job to run tests in Docker container #133
VKTB Nov 12, 2024
a470be7
Only push Docker images to Harbor on workflow_dispatch #133
VKTB Nov 12, 2024
92a7311
Fix failing docker CI job #133
VKTB Nov 12, 2024
0fb5fa1
Get coverage.xml report from container #133
VKTB Nov 12, 2024
5d49497
Createa docker compose file #133
VKTB Nov 14, 2024
9d1192d
Update README #133
VKTB Nov 14, 2024
dde7ad0
Update README #133
VKTB Dec 5, 2024
3bf7609
Update README #133
VKTB Dec 5, 2024
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
6 changes: 4 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
select = A,B,B9,BLK,C,E,F,I,N,S,W
ignore = E501,W503
max-complexity = 17
max-line-length = 80
max-line-length = 120
application-import-names = scigateway_auth,test
import-order-style = google
per-file-ignores = test/testutils.py:S105,B950,test/test_authenticationHandler.py:S105,scigateway_auth/wsgi.py:E402,F401
per-file-ignores =
test/**.py:S101
test/mock_data.py:S105
enable-extensions=G
118 changes: 45 additions & 73 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
@@ -1,128 +1,99 @@
name: CI
on:
workflow_dispatch:
inputs:
push-docker-image-to-harbor:
description: 'Push Docker Image to Harbor'
type: boolean
default: false

pull_request:
push:
branches:
- main
jobs:
tests:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9']
name: Python ${{ matrix.python-version }} Build & Tests
runs-on: ubuntu-latest
name: Unit Tests
steps:
- name: Add apt repo
run: sudo add-apt-repository universe
- name: Checkout repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

# Setup Python
- name: Setup Python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Run tests
run: |
docker build -f Dockerfile -t scigateway-auth:test --target test .
docker run --name scigateway-auth-container scigateway-auth:test pytest --config-file test/pytest.ini --cov scigateway_auth --cov-report xml
docker cp scigateway-auth-container:/app/coverage.xml coverage.xml

# Checkout repo
- name: Checkout repo
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0

# Prep for the tests
- name: Create log file
run: touch logs.log
- name: Configure log file location
run: echo "`jq -r --arg REPO_DIR "$GITHUB_WORKSPACE/logs.log" \
'.log_location=$REPO_DIR' scigateway_auth/config.json.example`" > scigateway_auth/config.json.example
- name: Create config.json
run: cp scigateway_auth/config.json.example scigateway_auth/config.json

# Install Nox, Poetry and API's dependencies
- name: Install Nox
run: pip install nox==2020.8.22
- name: Install Poetry
run: pip install poetry==1.1.9
# This fixes the issue with cachecontrol (https://github.com/psf/cachecontrol/issues/292).
# We will not be facing this issue when we upgrade to a newer Poetry version.
- name: Install Requests
run: pip install 'requests<2.30'
- name: Install dependencies
run: poetry install

# Run Nox tests session, saves and uploads a coverage report to codecov
- name: Run Nox tests session
run: nox -s tests -- --cov=scigateway_auth --cov-report=xml
- name: Upload code coverage report
if: matrix.python-version == '3.6'
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4

linting:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
name: Linting
steps:
- name: Checkout repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup Python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: '3.6'
architecture: x64
- name: Checkout repo
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
python-version: '3.11'

- name: Install Nox
run: pip install nox==2020.8.22
run: pip install nox==2024.10.9

- name: Install Poetry
run: pip install poetry==1.1.9
run: pip install poetry==1.8.4

- name: Run Nox lint session
run: nox -s lint

formatting:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
name: Code Formatting
steps:
- name: Checkout repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup Python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: '3.6'
architecture: x64
- name: Checkout repo
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
python-version: '3.11'

- name: Install Nox
run: pip install nox==2020.8.22
run: pip install nox==2024.10.9

- name: Install Poetry
run: pip install poetry==1.1.9
run: pip install poetry==1.8.4

- name: Run Nox black session
run: nox -s black

safety:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
name: Dependency Safety
steps:
- name: Checkout repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup Python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: '3.6'
architecture: x64
- name: Checkout repo
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
python-version: '3.11'

- name: Install Nox
run: pip install nox==2020.8.22
- name: Install Poetry
run: pip install poetry==1.1.9
run: pip install nox==2024.10.9

- name: Run Nox safety session
run: nox -s safety

docker:
# This job triggers only if all the other jobs succeed and does different things depending on the context.
# The job builds the Docker image in all cases and also pushes the image to Harbor only if something is
# pushed to the main branch.
needs: [tests, linting, formatting, safety]
name: Docker
runs-on: ubuntu-20.04
env:
PUSH_DOCKER_IMAGE_TO_HARBOR: ${{ inputs.push-docker-image-to-harbor != null && inputs.push-docker-image-to-harbor || 'false' }}
steps:
- name: Check out repo
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.5.2
Expand All @@ -140,10 +111,11 @@ jobs:
with:
images: harbor.stfc.ac.uk/datagateway/scigateway-auth

- name: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && 'Build and push Docker image to Harbor' || 'Build Docker image' }}
- name: ${{ fromJSON(env.PUSH_DOCKER_IMAGE_TO_HARBOR) && 'Build and push Docker image to Harbor' || 'Build Docker image' }}
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v4.0.0
with:
context: .
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
push: ${{ fromJSON(env.PUSH_DOCKER_IMAGE_TO_HARBOR) }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
target: prod
168 changes: 163 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,172 @@
.idea/
venv/
scigateway_auth/logging.ini
keys/*
!keys/.keep
*.pyc
config.json
logs.log
keys/
.vscode/
.python-version

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.python-version
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
*.log.*
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv*/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# Visual Studio Code
.vscode/
Loading
Loading