-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dan/per-11149-add-ruff-to-pdp-repo (#226)
* Added ruff * Updated README.md * Removed black from pre-commit * Run ruff format * Run ruff check --fix * Changed setup.py to pathlib * Fixed tests * Fixed state.py * Fixed offline_mode.py * Renamed exceptions * Fixed ruff checks * Fixed (some) mypy errors * Changed to annotated dependencies * Changed to default_factory(dict) * Fixed README.md and setup.py * Fixed header type * Removed extra arg * Added install dev to README.md * Fixed enforcer API
- Loading branch information
Showing
43 changed files
with
753 additions
and
1,065 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,39 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.2.0 | ||
rev: v5.0.0 | ||
hooks: | ||
- id: check-yaml | ||
exclude: "charts/" | ||
- id: end-of-file-fixer | ||
exclude: "charts/" | ||
- id: trailing-whitespace | ||
- repo: https://github.com/psf/black | ||
rev: 22.3.0 | ||
- id: end-of-file-fixer | ||
- id: check-added-large-files | ||
- id: check-case-conflict | ||
- id: check-executables-have-shebangs | ||
- id: check-json | ||
- id: check-toml | ||
- id: check-yaml | ||
exclude: "^charts/.*" | ||
- id: check-xml | ||
- id: check-merge-conflict | ||
- id: mixed-line-ending | ||
args: [ --fix=lf ] | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.8.3 | ||
hooks: | ||
- id: black | ||
# - repo: https://github.com/pycqa/isort | ||
# rev: 5.10.1 | ||
- id: ruff | ||
args: [--fix] | ||
files: \.py$ | ||
types: [ file ] | ||
- id: ruff-format | ||
files: \.py$ | ||
types: [ file ] | ||
|
||
# - repo: https://github.com/pre-commit/mirrors-mypy | ||
# rev: v1.13.0 | ||
# hooks: | ||
# - id: isort | ||
# - id: mypy | ||
# pass_filenames: false | ||
# additional_dependencies: | ||
# - pydantic | ||
# - types-requests | ||
# files: \.py$ | ||
# types: [ file ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,30 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import Header, HTTPException, status | ||
|
||
from horizon.config import MOCK_API_KEY, sidecar_config | ||
from horizon.startup.api_keys import get_env_api_key | ||
|
||
|
||
def enforce_pdp_token(authorization=Header(None)): | ||
def enforce_pdp_token(authorization: Annotated[str | None, Header()]): | ||
if authorization is None: | ||
raise HTTPException( | ||
status.HTTP_401_UNAUTHORIZED, detail="Missing Authorization header" | ||
) | ||
raise HTTPException(status.HTTP_401_UNAUTHORIZED, detail="Missing Authorization header") | ||
schema, token = authorization.split(" ") | ||
|
||
if schema.strip().lower() != "bearer" or token.strip() != get_env_api_key(): | ||
raise HTTPException(status.HTTP_401_UNAUTHORIZED, detail="Invalid PDP token") | ||
|
||
|
||
def enforce_pdp_control_key(authorization=Header(None)): | ||
def enforce_pdp_control_key(authorization: Annotated[str | None, Header()]): | ||
if sidecar_config.CONTAINER_CONTROL_KEY == MOCK_API_KEY: | ||
raise HTTPException( | ||
status.HTTP_503_SERVICE_UNAVAILABLE, | ||
detail="Control API disabled. Set a PDP_CONTAINER_CONTROL_KEY variable to enable.", | ||
) | ||
|
||
if authorization is None: | ||
raise HTTPException( | ||
status.HTTP_401_UNAUTHORIZED, detail="Missing Authorization header" | ||
) | ||
raise HTTPException(status.HTTP_401_UNAUTHORIZED, detail="Missing Authorization header") | ||
schema, token = authorization.split(" ") | ||
|
||
if ( | ||
schema.strip().lower() != "bearer" | ||
or token.strip() != sidecar_config.CONTAINER_CONTROL_KEY | ||
): | ||
if schema.strip().lower() != "bearer" or token.strip() != sidecar_config.CONTAINER_CONTROL_KEY: | ||
raise HTTPException(status.HTTP_401_UNAUTHORIZED, detail="Invalid PDP token") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.