Compare commits

..

3 Commits

Author SHA1 Message Date
d564710004 Merge pull request 'feature/base_file' (#1) from feature/base_file into main
Reviewed-on: #1
2025-09-18 07:36:51 +00:00
Pascal Scheiben
76c5353afa Adding base logic for config handling. Adding example config to root 2025-09-18 09:33:55 +02:00
Pascal Scheiben
19e9cd6625 Adding python dotenv to requirements/pyproject 2025-09-18 09:07:09 +02:00
11 changed files with 60 additions and 9 deletions

8
.env Normal file
View 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
View File

@@ -129,7 +129,7 @@ celerybeat.pid
*.sage.py
# Environments
.env
#.env
.venv
env/
venv/

View File

@@ -12,5 +12,6 @@ requires-python = ">=3.13"
dependencies = [
"fastapi[standard]>=0.116.2",
"httpx>=0.28.1",
"python-dotenv>=1.1.1",
"redis>=6.4.0",
]

View File

@@ -1,3 +1,4 @@
fastapi[standard]>=0.116.2
httpx>=0.28.1
redis>=6.4.0
redis>=6.4.0
python-dotenv>=1.1.1

View File

@@ -1,2 +1,2 @@
# contains a constant definition
FOO: int = 42
FOO: int = 42

View File

@@ -4,6 +4,7 @@ from .schema import ExampleSchema
router = APIRouter(tags=["example"])
@router.get("/example")
async def example_endpoint() -> ExampleSchema:
return ExampleSchema(example_field="foo", another_field=42)
return ExampleSchema(example_field="foo", another_field=42)

View File

@@ -1,6 +1,7 @@
# contains the schema definitions for the example service
from pydantic import BaseModel
class ExampleSchema(BaseModel):
example_field: str
another_field: int

View File

@@ -1,3 +1,3 @@
# contains the business logic for the example service
async def example_service() -> str:
return "This is an example service"
return "This is an example service"

View File

@@ -1,5 +1,21 @@
def main() -> None:
print("Hello, World!")
from src.service import load_config
from fastapi import FastAPI
import logging
if __name__ == "__main__":
main()
logger = logging.getLogger("uvicorn")
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
View File

@@ -0,0 +1,7 @@
from pydantic import BaseModel
class ConfigSchema(BaseModel):
hostname: str
username: str
password: str

16
src/service.py Normal file
View 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"],
)