Skip to content
Closed
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
8 changes: 6 additions & 2 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Pytest with Coverage
name: Lint and Test

on:
push:
Expand Down Expand Up @@ -35,7 +35,11 @@ jobs:
- name: Create virtual environment and install dependencies
run: |
uv venv
uv sync --dev # Include dev tools like pytest and pytest-cov
uv sync --extra dev

- name: Run Ruff (lint)
run: |
uv run -- ruff check .

- name: Run tests and generate Cobertura coverage report
run: |
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ Execute the test suite using `pytest`:
```bash
uv run pytest
```
## Run the Linter

This command will automatically fix issues where possible:

```bash
uv run -- ruff check . --fix
```

# Deployment

Expand Down
1 change: 1 addition & 0 deletions auth/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from functools import lru_cache

from pydantic_settings import BaseSettings, SettingsConfigDict


Expand Down
13 changes: 4 additions & 9 deletions auth/validator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import httpx

from auth.config import get_settings
from fastapi import Depends, HTTPException
from fastapi import HTTPException
from fastapi.security import OAuth2PasswordBearer
from jose import jwt, jwk
from jose import jwk, jwt
from jose.exceptions import JWTError

from auth.config import get_settings
from schemas.tokens import AccessTokenPayload
from schemas.user import User

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")

Expand Down Expand Up @@ -64,7 +63,3 @@ def get_rsa_key(token: str) -> jwk.RSAKey | None: # type: ignore

return None


def get_current_user(token: str = Depends(oauth2_scheme)) -> User:
access_token = verify_jwt(token)
return User(access_token=access_token)
27 changes: 21 additions & 6 deletions deploy/aai_backend_deploy/aai_backend_deploy_stack.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
import datetime

from aws_cdk import (
CfnOutput,
Stack,
)
from aws_cdk import (
aws_certificatemanager as acm,
)
from aws_cdk import (
Stack, CfnOutput,
aws_ec2 as ec2,
aws_ecs as ecs,
)
from aws_cdk import (
aws_ecr as ecr,
aws_iam as iam,
aws_route53 as route53,
aws_certificatemanager as acm,
aws_elasticloadbalancingv2 as elbv2,
)
from aws_cdk import (
aws_ecs as ecs,
)
from aws_cdk import (
aws_ecs_patterns as ecs_patterns,
)
from aws_cdk import (
aws_elasticloadbalancingv2 as elbv2,
)
from aws_cdk import (
aws_route53 as route53,
)
from constructs import Construct


Expand Down
2 changes: 1 addition & 1 deletion deploy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import os

import aws_cdk as cdk
from aai_backend_deploy.aai_backend_deploy_stack import AaiBackendDeployStack
from dotenv import load_dotenv

from aai_backend_deploy.aai_backend_deploy_stack import AaiBackendDeployStack

def get_dotenv_config():
load_dotenv()
Expand Down
Empty file removed deploy/tests/__init__.py
Empty file.
Empty file removed deploy/tests/unit/__init__.py
Empty file.
11 changes: 0 additions & 11 deletions deploy/tests/unit/test_aai_backend_deploy_stack.py

This file was deleted.

1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi import FastAPI

from routers import user

app = FastAPI()
Expand Down
30 changes: 23 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,33 @@ dependencies = [
"fastapi[standard]>=0.115.12",
"httpx>=0.28.1",
"pydantic-settings>=2.8.1",
"python-jose>=3.4.0",
"python-jose>=3.4.0"
]

[tool.pytest.ini_options]
pythonpath=["."]
testpaths=["tests"]

[dependency-groups]
[project.optional-dependencies]
dev = [
"polyfactory>=2.21.0",
"pytest>=8.3.5",
"pytest-mock>=3.14.0",
"pytest-cov>=4.1.0",
"ruff>=0.4.4",
"polyfactory>=2.21.0"
]

[tool.pytest.ini_options]
pythonpath = ["."]
testpaths = ["tests"]
addopts = "--cov=auth --cov=deploy --cov=routers --cov=schemas --cov-report=term --cov-report=xml"

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
include = ["auth*", "deploy*", "routers*", "schemas*"]

[tool.ruff]
line-length = 88
target-version = "py311"
lint.select = ["E", "F", "I"]
lint.ignore = ["E501"]
exclude = ["tests/data", ".venv", "venv", "migrations"]
9 changes: 5 additions & 4 deletions routers/user.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from typing import Dict, List, Any
from datetime import datetime, timezone
from typing import Any, Dict, List

from fastapi import APIRouter, Depends, HTTPException
from httpx import AsyncClient

from auth.config import get_settings
from auth.management import get_management_token
from auth.validator import get_current_user
from datetime import datetime, timezone
from fastapi import APIRouter, Depends, HTTPException
from schemas.requests import ResourceRequest, ServiceRequest
from schemas.service import Auth0User, Service, Resource
from schemas.service import Auth0User, Resource, Service
from schemas.user import User

router = APIRouter(
Expand Down
1 change: 0 additions & 1 deletion schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .group import Group
from .service import Resource, Service


__all__ = ["Service", "Resource", "Group"]
3 changes: 2 additions & 1 deletion schemas/service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from datetime import datetime
from pydantic import BaseModel, Field, HttpUrl
from typing import List, Literal, Optional

from pydantic import BaseModel, Field, HttpUrl


class Resource(BaseModel):
name: str
Expand Down
3 changes: 2 additions & 1 deletion schemas/tokens.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pydantic import BaseModel, Field
from typing import Optional

from pydantic import BaseModel, Field


class AccessTokenPayload(BaseModel):
"""
Expand Down
1 change: 1 addition & 0 deletions schemas/user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pydantic import BaseModel

from .tokens import AccessTokenPayload


Expand Down
1 change: 1 addition & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi.testclient import TestClient

from main import app

client = TestClient(app)
Expand Down
7 changes: 4 additions & 3 deletions tests/test_user.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from fastapi import HTTPException
from datetime import datetime

import pytest
from fastapi import HTTPException
from fastapi.testclient import TestClient

from auth.config import Settings
from fastapi.testclient import TestClient
from main import app
from schemas.service import Service, Resource, Group, AppMetadata
from schemas.service import AppMetadata, Group, Resource, Service
from tests.datagen import AccessTokenPayloadFactory, Auth0UserFactory

client = TestClient(app)
Expand Down
Loading
Loading