Adding config endpoint
This commit is contained in:
3
src/config/__init__.py
Normal file
3
src/config/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from src.config.router import router as config_router
|
||||||
|
|
||||||
|
__all__ = ["config_router"]
|
||||||
14
src/config/config.http
Normal file
14
src/config/config.http
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
POST http://127.0.0.1:8000/config
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"cluster_list": [
|
||||||
|
{
|
||||||
|
"hostname": "cluster1.demo.netapp.com",
|
||||||
|
"username": "admin",
|
||||||
|
"password": "Netapp1!"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
16
src/config/router.py
Normal file
16
src/config/router.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from fastapi import APIRouter
|
||||||
|
from .schema import ConfigSchema, ConfigReturnSchema
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger("uvicorn")
|
||||||
|
|
||||||
|
router = APIRouter(tags=["config"])
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/config", response_model=ConfigReturnSchema)
|
||||||
|
async def create_config(config: ConfigSchema) -> ConfigSchema:
|
||||||
|
"""
|
||||||
|
Endpoint to receive and return configuration data.
|
||||||
|
"""
|
||||||
|
logger.info("Received configuration data")
|
||||||
|
return config
|
||||||
21
src/config/schema.py
Normal file
21
src/config/schema.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# contains the schema definitions for the aggregate service
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigEntrySchema(BaseModel):
|
||||||
|
hostname: str
|
||||||
|
username: str
|
||||||
|
password: str
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigOutSchema(BaseModel):
|
||||||
|
hostname: str
|
||||||
|
username: str
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigReturnSchema(BaseModel):
|
||||||
|
cluster_list: list[ConfigOutSchema]
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigSchema(BaseModel):
|
||||||
|
cluster_list: list[ConfigEntrySchema]
|
||||||
3
src/config/service.py
Normal file
3
src/config/service.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# contains the business logic for the aggregate service
|
||||||
|
async def example_service() -> str:
|
||||||
|
return "This is an aggregate service"
|
||||||
@@ -2,6 +2,7 @@ from src.service import load_config
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
import logging
|
import logging
|
||||||
from src.aggregate import aggregate_router
|
from src.aggregate import aggregate_router
|
||||||
|
from src.config import config_router
|
||||||
|
|
||||||
logger = logging.getLogger("uvicorn")
|
logger = logging.getLogger("uvicorn")
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ config = load_config()
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
app.include_router(aggregate_router)
|
app.include_router(aggregate_router)
|
||||||
|
app.include_router(config_router)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
|
|||||||
Reference in New Issue
Block a user