Compare commits
No commits in common. "01c49ca34cf5f24ef1c8d55c501d18f15642f240" and "d03478637a283684edf68f31236456f71639bcce" have entirely different histories.
01c49ca34c
...
d03478637a
11 changed files with 56 additions and 63 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Configurations for the <this> module
|
Configurations for <this module>
|
||||||
|
|
||||||
Exports:
|
Configurations:
|
||||||
|
- List: Description
|
||||||
|
- Configs: Description
|
||||||
"""
|
"""
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Constants for the <this> module
|
Constants and error codes for <this module>
|
||||||
|
|
||||||
Exports:
|
Constants:
|
||||||
|
- List: Description
|
||||||
|
- Consts: Description
|
||||||
"""
|
"""
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
"""
|
"""
|
||||||
Dependencies related to the <this> module
|
Router dependencies for <this module>
|
||||||
|
|
||||||
Exports:
|
Classes:
|
||||||
- <dep_name>: <return_type>: <description>
|
- List: Description
|
||||||
|
- Classes: Description
|
||||||
|
|
||||||
|
Functions:
|
||||||
|
- List: Description
|
||||||
|
- Functions: Description
|
||||||
"""
|
"""
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Exceptions related to the <this> modules
|
Module specific exceptions for <this module>
|
||||||
|
|
||||||
Exceptions:
|
Exceptions:
|
||||||
- <ExceptionName>: Details e.g. optional params
|
- List: Description
|
||||||
|
- Exceptions: Description
|
||||||
"""
|
"""
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Database models for the <this> module
|
Database models for <this module>
|
||||||
|
|
||||||
Models:
|
Models:
|
||||||
- <ModelName>:
|
- List: Description
|
||||||
- <normal_columns[FK][PK]>
|
- Models: Description
|
||||||
- <orm_relationships>
|
|
||||||
- <calculated_properties>
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
"""
|
"""
|
||||||
Router endpoints for the <this> module
|
Router endpoints for <this module>
|
||||||
|
|
||||||
Exports:
|
Endpoints:
|
||||||
- router: fastapi.APIRouter
|
- List: Description
|
||||||
|
- Endpoints: Description
|
||||||
"""
|
"""
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
|
||||||
|
|
||||||
router = APIRouter(
|
_router = APIRouter(
|
||||||
tags=[""],
|
tags=[""],
|
||||||
)
|
)
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Pydantic models for the <this> module
|
Pydantic models for <this module>
|
||||||
|
|
||||||
Models follow the nomenclature of:
|
Models:
|
||||||
- Sub-models: "<Resource><Opt:>Schema"
|
- List: Description
|
||||||
- Mixins: "<Attribute>Mixin"
|
- Models: Description
|
||||||
- Models: "<Module><Method><Resource><Opt:Resource><Direction>" ie ""
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
"""
|
"""
|
||||||
Module specific business logic for the <this> module
|
Module specific business logic for <this module>
|
||||||
|
|
||||||
Exports:
|
Classes:
|
||||||
|
- List: Description
|
||||||
|
- Classes: Description
|
||||||
|
|
||||||
|
Functions:
|
||||||
|
- List: Description
|
||||||
|
- Functions: Description
|
||||||
"""
|
"""
|
||||||
|
|
@ -1,3 +1,11 @@
|
||||||
"""
|
"""
|
||||||
Non-business logic reusable functions and classes for the <this> module
|
Non-business logic reusable functions and classes for <this module>
|
||||||
|
|
||||||
|
Classes:
|
||||||
|
- List: Description
|
||||||
|
- Classes: Description
|
||||||
|
|
||||||
|
Functions:
|
||||||
|
- List: Description
|
||||||
|
- Functions: Description
|
||||||
"""
|
"""
|
||||||
|
|
@ -31,11 +31,7 @@ tags_metadata = [
|
||||||
{
|
{
|
||||||
"name": "User",
|
"name": "User",
|
||||||
"description": "User related operations, includes getting information about the current 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",
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,29 +26,16 @@ router = APIRouter(
|
||||||
prefix="/service",
|
prefix="/service",
|
||||||
)
|
)
|
||||||
|
|
||||||
@router.get("/", status_code=status.HTTP_200_OK, response_model=ServiceGetServiceResponse, responses={
|
@router.get("/", response_model=ServiceGetServiceResponse)
|
||||||
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):
|
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()
|
permission_models = db.query(Service).all()
|
||||||
|
|
||||||
return {"services": permission_models}
|
return {"services": permission_models}
|
||||||
|
|
||||||
@router.post("/", status_code=status.HTTP_200_OK, response_model=ServicePostServiceResponse, responses={
|
@router.post("/", response_model=ServicePostServiceResponse)
|
||||||
status.HTTP_200_OK: {"description": "Successfully registered a new service"},
|
async def register_service(db: db_dependency, su: super_admin_dependency, service_request: ServicePostServiceRequest):
|
||||||
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()
|
key = generate_api_key()
|
||||||
service_model = Service(name=request_model.name, api_key=key)
|
service_model = Service(name=service_request.name, api_key=key)
|
||||||
|
|
||||||
db.add(service_model)
|
db.add(service_model)
|
||||||
try:
|
try:
|
||||||
|
|
@ -61,14 +48,8 @@ async def register_service(db: db_dependency, su: super_admin_dependency, reques
|
||||||
db.commit()
|
db.commit()
|
||||||
return {"service": response}
|
return {"service": response}
|
||||||
|
|
||||||
@router.patch("/key", status_code=status.HTTP_200_OK, response_model=ServicePatchKeyResponse, responses={
|
@router.patch("/key", response_model=ServicePatchKeyResponse)
|
||||||
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):
|
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()
|
key = generate_api_key()
|
||||||
service_model.api_key = key
|
service_model.api_key = key
|
||||||
|
|
||||||
|
|
@ -77,13 +58,7 @@ async def regenerate_api_key(db: db_dependency, su: super_admin_dependency, serv
|
||||||
db.commit()
|
db.commit()
|
||||||
return {"service": response}
|
return {"service": response}
|
||||||
|
|
||||||
@router.delete("/", status_code=status.HTTP_204_NO_CONTENT, responses={
|
@router.delete("/", status_code=status.HTTP_204_NO_CONTENT)
|
||||||
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):
|
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.delete(service_model)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue