template for service rather than hub
Previous template structure had direct handling of auth. This structure is designed to get auth from the hub instead.
This commit is contained in:
parent
ed4a3fe0b8
commit
ea9803536a
27 changed files with 223 additions and 117 deletions
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Configurations for the _____ module
|
||||
Configurations for the <this> module
|
||||
|
||||
Exports:
|
||||
"""
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Constants and error codes for the _____ module
|
||||
Constants for the <this> module
|
||||
|
||||
Exports:
|
||||
"""
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
"""
|
||||
Router dependencies for the _____ module
|
||||
Dependencies related to the <this> module
|
||||
|
||||
Exports:
|
||||
- <dep_name>: <return_type>: <description>
|
||||
"""
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
"""
|
||||
Module specific exceptions for the _____ module
|
||||
Exceptions related to the <this> modules
|
||||
|
||||
Exports:
|
||||
Exceptions:
|
||||
- <ExceptionName>: Details e.g. optional params
|
||||
"""
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
"""
|
||||
Database models for the _____ module
|
||||
Database models for the <this> module
|
||||
|
||||
Exports:
|
||||
Models:
|
||||
- <ModelName>:
|
||||
- <normal_columns[FK][PK]>
|
||||
- <orm_relationships>
|
||||
- <calculated_properties>
|
||||
"""
|
||||
|
|
@ -1,15 +1,31 @@
|
|||
"""
|
||||
Router endpoints for the _____ module
|
||||
Router endpoints for the <this> module
|
||||
|
||||
Endpoints:
|
||||
- /timer/start
|
||||
- /timer/stop
|
||||
Exports:
|
||||
- router: fastapi.APIRouter
|
||||
|
||||
### Router Guidelines ###
|
||||
- Add responses to decorators
|
||||
- Add status_codes to decorators
|
||||
- All endpoints should either return a response object or 204
|
||||
- Ensure response_model is declared in the decorator
|
||||
- All query and path params should have validation and descriptions
|
||||
- All endpoints should have a docstring (this is used in place of a description)
|
||||
- All endpoints should have a summary
|
||||
- All modules should have metadata in main.py
|
||||
- All exceptions should have a custom definition in exceptions.py
|
||||
- Dependencies should be used for db model get and validation where possible
|
||||
- Verify module level docstring is still accurate after updates
|
||||
"""
|
||||
import threading
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Request, HTTPException
|
||||
from fastapi.params import Query
|
||||
|
||||
from src.utils import create_timer
|
||||
from src.utils import create_timer, generate_resource_name
|
||||
from src.auth.dependencies import header_dependency
|
||||
from src.dependencies import http_client_dependency
|
||||
|
||||
router = APIRouter(
|
||||
tags=[""],
|
||||
|
|
@ -52,3 +68,28 @@ async def stop_timer(request: Request, ident: str):
|
|||
timers.pop(idx)
|
||||
|
||||
return {"timer_ident": ident, "status": "stopped"}
|
||||
|
||||
|
||||
@router.get("/hub/access")
|
||||
async def test_hub_access(headers: header_dependency, client: http_client_dependency, org_name: Annotated[str, Query()]):
|
||||
resource_name = "example_resource"
|
||||
action = "read"
|
||||
rn = generate_resource_name(resource=resource_name, org=org_name)
|
||||
|
||||
hub_response = await client.post(
|
||||
f"http://localhost:8001/api/v1/iam/can_act_on_resource",
|
||||
headers=headers,
|
||||
params={"action": action},
|
||||
json=rn.model_dump()
|
||||
)
|
||||
|
||||
response = {
|
||||
"resource_name": rn,
|
||||
"action": action,
|
||||
"response": {
|
||||
"status": hub_response.status_code,
|
||||
"json": hub_response.json()
|
||||
}
|
||||
}
|
||||
|
||||
return response
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
"""
|
||||
Pydantic models for the _____ module
|
||||
Pydantic models for the <this> module
|
||||
|
||||
Exports:
|
||||
Models follow the nomenclature of:
|
||||
- Sub-models: "<Resource><Opt:>Schema"
|
||||
- Mixins: "<Attribute>Mixin"
|
||||
- Models: "<Module><Method><Resource><Opt:Resource><Direction>" ie ""
|
||||
"""
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Module specific business logic for the _____ module
|
||||
Module specific business logic for the <this> module
|
||||
|
||||
Exports:
|
||||
"""
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
"""
|
||||
Non-business logic reusable functions and classes for the _____ module
|
||||
|
||||
Exports:
|
||||
Non-business logic reusable functions and classes for the <this> module
|
||||
"""
|
||||
Loading…
Add table
Add a link
Reference in a new issue