feature/base_file #1
8
.env
Normal file
8
.env
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Environment variables for NetApp ONTAP clusters
|
||||||
|
CLUSTER1_HOSTNAME=172.16.57.2
|
||||||
|
CLUSTER1_USERNAME=admin
|
||||||
|
CLUSTER1_PASSWORD=Netapp12
|
||||||
|
|
||||||
|
CLUSTER2_HOSTNAME=172.16.56.2
|
||||||
|
CLUSTER2_USERNAME=admin
|
||||||
|
CLUSTER2_PASSWORD=Netapp12
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -129,7 +129,7 @@ celerybeat.pid
|
|||||||
*.sage.py
|
*.sage.py
|
||||||
|
|
||||||
# Environments
|
# Environments
|
||||||
.env
|
#.env
|
||||||
.venv
|
.venv
|
||||||
env/
|
env/
|
||||||
venv/
|
venv/
|
||||||
|
|||||||
@@ -12,5 +12,6 @@ requires-python = ">=3.13"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"fastapi[standard]>=0.116.2",
|
"fastapi[standard]>=0.116.2",
|
||||||
"httpx>=0.28.1",
|
"httpx>=0.28.1",
|
||||||
|
"python-dotenv>=1.1.1",
|
||||||
"redis>=6.4.0",
|
"redis>=6.4.0",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
fastapi[standard]>=0.116.2
|
fastapi[standard]>=0.116.2
|
||||||
httpx>=0.28.1
|
httpx>=0.28.1
|
||||||
redis>=6.4.0
|
redis>=6.4.0
|
||||||
|
python-dotenv>=1.1.1
|
||||||
@@ -4,6 +4,7 @@ from .schema import ExampleSchema
|
|||||||
|
|
||||||
router = APIRouter(tags=["example"])
|
router = APIRouter(tags=["example"])
|
||||||
|
|
||||||
|
|
||||||
@router.get("/example")
|
@router.get("/example")
|
||||||
async def example_endpoint() -> ExampleSchema:
|
async def example_endpoint() -> ExampleSchema:
|
||||||
return ExampleSchema(example_field="foo", another_field=42)
|
return ExampleSchema(example_field="foo", another_field=42)
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
# contains the schema definitions for the example service
|
# contains the schema definitions for the example service
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
class ExampleSchema(BaseModel):
|
class ExampleSchema(BaseModel):
|
||||||
example_field: str
|
example_field: str
|
||||||
another_field: int
|
another_field: int
|
||||||
|
|||||||
24
src/main.py
24
src/main.py
@@ -1,5 +1,21 @@
|
|||||||
def main() -> None:
|
from src.service import load_config
|
||||||
print("Hello, World!")
|
from fastapi import FastAPI
|
||||||
|
import logging
|
||||||
|
|
||||||
if __name__ == "__main__":
|
logger = logging.getLogger("uvicorn")
|
||||||
main()
|
|
||||||
|
logger.info("Starting application")
|
||||||
|
config = load_config()
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
async def main():
|
||||||
|
return {"Hello": "World"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/config")
|
||||||
|
async def get_config():
|
||||||
|
"""Endpoint to get the current configuration."""
|
||||||
|
return config.model_dump()
|
||||||
|
|||||||
7
src/schema.py
Normal file
7
src/schema.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigSchema(BaseModel):
|
||||||
|
hostname: str
|
||||||
|
username: str
|
||||||
|
password: str
|
||||||
16
src/service.py
Normal file
16
src/service.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from dotenv import dotenv_values
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from src.schema import ConfigSchema
|
||||||
|
|
||||||
|
logger = logging.getLogger("uvicorn")
|
||||||
|
|
||||||
|
|
||||||
|
def load_config() -> ConfigSchema:
|
||||||
|
logger.info("Loading config from .env file")
|
||||||
|
config = dotenv_values(".env")
|
||||||
|
return ConfigSchema(
|
||||||
|
hostname=config["CLUSTER1_HOSTNAME"],
|
||||||
|
username=config["CLUSTER1_USERNAME"],
|
||||||
|
password=config["CLUSTER1_PASSWORD"],
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user