Skip to content

Commit 6373d6b

Browse files
committed
style: streamline CI pipeline in app entry point, utils, config and exceptions
1 parent b7a1ba0 commit 6373d6b

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

app/config.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ class Settings(BaseSettings):
5858
rate_limit_requests_per_minute: int = 60
5959

6060
model_config = SettingsConfigDict(
61-
env_file=".env",
62-
env_file_encoding="utf-8",
63-
case_sensitive=False,
64-
extra="ignore"
61+
env_file=".env", env_file_encoding="utf-8", case_sensitive=False, extra="ignore"
6562
)
6663

6764

@@ -76,7 +73,7 @@ def configure_logging():
7673
logging.basicConfig(
7774
level=log_level,
7875
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
79-
datefmt="%Y-%m-%d %H:%M:%S"
76+
datefmt="%Y-%m-%d %H:%M:%S",
8077
)
8178

8279
# Set uvicorn log level

app/exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
class VMException(Exception):
1212
"""Base exception for VM operations"""
13+
1314
def __init__(self, message: str, status_code: int = 500):
1415
self.message = message
1516
self.status_code = status_code
@@ -18,6 +19,7 @@ def __init__(self, message: str, status_code: int = 500):
1819

1920
class VMNotFoundException(VMException):
2021
"""Exception raised when VM is not found"""
22+
2123
def __init__(self, vm_id: UUID):
2224
message = f"VM with ID {vm_id} not found"
2325
super().__init__(message, status_code=404)
@@ -26,6 +28,7 @@ def __init__(self, vm_id: UUID):
2628

2729
class InvalidStateTransitionException(VMException):
2830
"""Exception raised when attempting an invalid state transition"""
31+
2932
def __init__(self, vm_id: UUID, current_state: str, attempted_action: str):
3033
message = (
3134
f"Cannot perform '{attempted_action}' on VM {vm_id} "
@@ -39,13 +42,15 @@ def __init__(self, vm_id: UUID, current_state: str, attempted_action: str):
3942

4043
class ValidationException(VMException):
4144
"""Exception raised for validation errors"""
45+
4246
def __init__(self, message: str, field: Optional[str] = None):
4347
super().__init__(message, status_code=422)
4448
self.field = field
4549

4650

4751
class VMAlreadyExistsException(VMException):
4852
"""Exception raised when trying to create a VM with a name that already exists"""
53+
4954
def __init__(self, name: str):
5055
message = f"VM with name '{name}' already exists"
5156
super().__init__(message, status_code=409)

app/utils/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
def get_datetime_now() -> datetime:
55
"""Return the current date and time in UTC timezone"""
6-
return datetime.now(tz=timezone.utc)
6+
return datetime.now(tz=timezone.utc)

main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def lifespan(_app: FastAPI):
4141
docs_url="/docs",
4242
redoc_url="/redoc",
4343
openapi_url="/openapi.json",
44-
lifespan=lifespan
44+
lifespan=lifespan,
4545
)
4646

4747
# Configure CORS
@@ -64,16 +64,17 @@ async def root():
6464
"message": "OpenStack VM Lifecycle Management API",
6565
"version": __version__,
6666
"docs": "/docs",
67-
"health": f"/api/{settings.api_version}/health"
67+
"health": f"/api/{settings.api_version}/health",
6868
}
6969

7070

7171
if __name__ == "__main__":
7272
import uvicorn
73+
7374
uvicorn.run(
7475
"main:app",
7576
host=settings.host,
7677
port=settings.port,
7778
reload=settings.debug,
78-
log_level=settings.log_level.lower()
79+
log_level=settings.log_level.lower(),
7980
)

0 commit comments

Comments
 (0)