Compare commits

...

3 commits

Author SHA1 Message Date
01c49ca34c docs: module template docstrings 2026-05-28 15:41:10 +01:00
b3085e85fd docs: service router response details 2026-05-28 15:30:39 +01:00
aa7dc46533 docs: service router details 2026-05-28 15:25:29 +01:00
11 changed files with 63 additions and 56 deletions

View file

@ -1,7 +1,5 @@
"""
Configurations for <this module>
Configurations for the <this> module
Configurations:
- List: Description
- Configs: Description
Exports:
"""

View file

@ -1,7 +1,5 @@
"""
Constants and error codes for <this module>
Constants for the <this> module
Constants:
- List: Description
- Consts: Description
Exports:
"""

View file

@ -1,11 +1,6 @@
"""
Router dependencies for <this module>
Dependencies related to the <this> module
Classes:
- List: Description
- Classes: Description
Functions:
- List: Description
- Functions: Description
Exports:
- <dep_name>: <return_type>: <description>
"""

View file

@ -1,7 +1,6 @@
"""
Module specific exceptions for <this module>
Exceptions related to the <this> modules
Exceptions:
- List: Description
- Exceptions: Description
- <ExceptionName>: Details e.g. optional params
"""

View file

@ -1,7 +1,9 @@
"""
Database models for <this module>
Database models for the <this> module
Models:
- List: Description
- Models: Description
- <ModelName>:
- <normal_columns[FK][PK]>
- <orm_relationships>
- <calculated_properties>
"""

View file

@ -1,13 +1,12 @@
"""
Router endpoints for <this module>
Router endpoints for the <this> module
Endpoints:
- List: Description
- Endpoints: Description
Exports:
- router: fastapi.APIRouter
"""
from fastapi import APIRouter
_router = APIRouter(
router = APIRouter(
tags=[""],
)
)

View file

@ -1,7 +1,8 @@
"""
Pydantic models for <this module>
Pydantic models for the <this> module
Models:
- List: Description
- Models: Description
Models follow the nomenclature of:
- Sub-models: "<Resource><Opt:>Schema"
- Mixins: "<Attribute>Mixin"
- Models: "<Module><Method><Resource><Opt:Resource><Direction>" ie ""
"""

View file

@ -1,11 +1,5 @@
"""
Module specific business logic for <this module>
Module specific business logic for the <this> module
Classes:
- List: Description
- Classes: Description
Functions:
- List: Description
- Functions: Description
Exports:
"""

View file

@ -1,11 +1,3 @@
"""
Non-business logic reusable functions and classes for <this module>
Classes:
- List: Description
- Classes: Description
Functions:
- List: Description
- Functions: Description
Non-business logic reusable functions and classes for the <this> module
"""

View file

@ -31,7 +31,11 @@ tags_metadata = [
{
"name": "User",
"description": "User related operations, includes getting information about the current user",
}
},
{
"name": "Service",
"description": "Services related operations, includes registering services and reissuing API keys",
},
]

View file

@ -26,16 +26,29 @@ router = APIRouter(
prefix="/service",
)
@router.get("/", response_model=ServiceGetServiceResponse)
@router.get("/", status_code=status.HTTP_200_OK, response_model=ServiceGetServiceResponse, responses={
status.HTTP_200_OK: {"description": "Successful retrieval from database"},
status.HTTP_401_UNAUTHORIZED: {"description": "Unauthorized"},
})
async def get_all_services(db: db_dependency, org_model: org_model_root_claim_query_dependency):
"""
Returns the ID and name of all services registered to the hub.
"""
permission_models = db.query(Service).all()
return {"services": permission_models}
@router.post("/", response_model=ServicePostServiceResponse)
async def register_service(db: db_dependency, su: super_admin_dependency, service_request: ServicePostServiceRequest):
@router.post("/", status_code=status.HTTP_200_OK, response_model=ServicePostServiceResponse, responses={
status.HTTP_200_OK: {"description": "Successfully registered a new service"},
status.HTTP_401_UNAUTHORIZED: {"description": "Unauthorized"},
status.HTTP_409_CONFLICT: {"description": "Service with this name already exists"},
})
async def register_service(db: db_dependency, su: super_admin_dependency, request_model: ServicePostServiceRequest):
"""
Registers a new service to the hub, generating and returning an API key for it.
"""
key = generate_api_key()
service_model = Service(name=service_request.name, api_key=key)
service_model = Service(name=request_model.name, api_key=key)
db.add(service_model)
try:
@ -48,8 +61,14 @@ async def register_service(db: db_dependency, su: super_admin_dependency, servic
db.commit()
return {"service": response}
@router.patch("/key", response_model=ServicePatchKeyResponse)
@router.patch("/key", status_code=status.HTTP_200_OK, response_model=ServicePatchKeyResponse, responses={
status.HTTP_200_OK: {"description": "Successful update of API key"},
status.HTTP_401_UNAUTHORIZED: {"description": "Unauthorized"},
})
async def regenerate_api_key(db: db_dependency, su: super_admin_dependency, service_model: service_model_body_dependency, request_model: ServicePatchKeyRequest):
"""
Generates and returns a new API key for the service to access the hub.
"""
key = generate_api_key()
service_model.api_key = key
@ -58,7 +77,13 @@ async def regenerate_api_key(db: db_dependency, su: super_admin_dependency, serv
db.commit()
return {"service": response}
@router.delete("/", status_code=status.HTTP_204_NO_CONTENT)
@router.delete("/", status_code=status.HTTP_204_NO_CONTENT, responses={
status.HTTP_204_NO_CONTENT: {"description": "Successfully removed service from db"},
status.HTTP_401_UNAUTHORIZED: {"description": "Unauthorized"},
})
async def remove_service(db: db_dependency, service_model: service_model_body_dependency, su: super_admin_dependency, request_model: ServiceDeleteServiceRequest):
"""
Removes a service from the hub.
"""
db.delete(service_model)
db.commit()