Skip to content

Commit

Permalink
Fix typing failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain-S committed Jul 2, 2024
1 parent 1d53533 commit d56676f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 50 deletions.
94 changes: 47 additions & 47 deletions rctab/crud/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UserRBAC(BaseModel):
"""The access that a user has to RCTab."""

oid: UUID
username: Optional[str]
username: Optional[str] = None
has_access: bool
is_admin: bool

Expand All @@ -34,52 +34,52 @@ class Usage(HashBaseModel):

# See https://docs.microsoft.com/en-us/rest/api/consumption/usage-details/list#legacyusagedetail
id: str
name: Optional[str]
type: Optional[str]
tags: Optional[Dict[str, str]]
billing_account_id: Optional[str]
billing_account_name: Optional[str]
billing_period_start_date: Optional[datetime.date]
billing_period_end_date: Optional[datetime.date]
billing_profile_id: Optional[str]
billing_profile_name: Optional[str]
account_owner_id: Optional[str]
account_name: Optional[str]
name: Optional[str] = None
type: Optional[str] = None
tags: Optional[Dict[str, str]] = None
billing_account_id: Optional[str] = None
billing_account_name: Optional[str] = None
billing_period_start_date: Optional[datetime.date] = None
billing_period_end_date: Optional[datetime.date] = None
billing_profile_id: Optional[str] = None
billing_profile_name: Optional[str] = None
account_owner_id: Optional[str] = None
account_name: Optional[str] = None
subscription_id: UUID
subscription_name: Optional[str]
subscription_name: Optional[str] = None
date: datetime.date
product: Optional[str]
part_number: Optional[str]
meter_id: Optional[str]
quantity: Optional[float]
effective_price: Optional[float]
cost: Optional[float]
amortised_cost: Optional[float]
product: Optional[str] = None
part_number: Optional[str] = None
meter_id: Optional[str] = None
quantity: Optional[float] = None
effective_price: Optional[float] = None
cost: Optional[float] = None
amortised_cost: Optional[float] = None
total_cost: float
unit_price: Optional[float]
billing_currency: Optional[str]
resource_location: Optional[str]
consumed_service: Optional[str]
resource_id: Optional[str]
resource_name: Optional[str]
service_info1: Optional[str]
service_info2: Optional[str]
additional_info: Optional[str]
invoice_section: Optional[str]
cost_center: Optional[str]
resource_group: Optional[str]
reservation_id: Optional[str]
reservation_name: Optional[str]
product_order_id: Optional[str]
offer_id: Optional[str]
is_azure_credit_eligible: Optional[bool]
term: Optional[str]
publisher_name: Optional[str]
publisher_type: Optional[str]
plan_name: Optional[str]
charge_type: Optional[str]
frequency: Optional[str]
monthly_upload: Optional[datetime.date]
unit_price: Optional[float] = None
billing_currency: Optional[str] = None
resource_location: Optional[str] = None
consumed_service: Optional[str] = None
resource_id: Optional[str] = None
resource_name: Optional[str] = None
service_info1: Optional[str] = None
service_info2: Optional[str] = None
additional_info: Optional[str] = None
invoice_section: Optional[str] = None
cost_center: Optional[str] = None
resource_group: Optional[str] = None
reservation_id: Optional[str] = None
reservation_name: Optional[str] = None
product_order_id: Optional[str] = None
offer_id: Optional[str] = None
is_azure_credit_eligible: Optional[bool] = None
term: Optional[str] = None
publisher_name: Optional[str] = None
publisher_type: Optional[str] = None
plan_name: Optional[str] = None
charge_type: Optional[str] = None
frequency: Optional[str] = None
monthly_upload: Optional[datetime.date] = None


class AllUsage(BaseModel):
Expand All @@ -92,7 +92,7 @@ class CMUsage(HashBaseModel):
"""A usage object from the Azure cost management API."""

subscription_id: UUID
name: Optional[str]
name: Optional[str] = None
start_datetime: datetime.date
end_datetime: datetime.date
cost: confloat(ge=0.0) # type: ignore
Expand All @@ -112,8 +112,8 @@ class RoleAssignment(HashBaseModel):
role_name: str
principal_id: str
display_name: str
mail: Optional[str]
scope: Optional[str]
mail: Optional[str] = None
scope: Optional[str] = None


class SubscriptionState(str, Enum):
Expand Down
9 changes: 6 additions & 3 deletions rctab/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from typing import Any, List, Optional
from uuid import UUID

from pydantic import HttpUrl, PostgresDsn, field_validator, model_validator
from pydantic import PostgresDsn, field_validator, model_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
from typing_extensions import Self


class Settings(BaseSettings):
Expand Down Expand Up @@ -60,8 +59,12 @@ class Settings(BaseSettings):
# Settings for the settings class itself.
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")

# Note that mode="before" means that we get (and return)
# a dict and not a Settings object.
@model_validator(mode="before")
def validate_postgres_dsn(self) -> Self:
def validate_postgres_dsn( # type: ignore
self: dict[str, Any],
) -> dict[str, Any]:
"""Build a DSN string from the host, db name, port, username and password."""
# We want to build the Data Source Name ourselves so none should be provided
if self.get("postgres_dsn") is not None:
Expand Down

0 comments on commit d56676f

Please sign in to comment.