2023-02-26 12:52:08 +00:00
|
|
|
import enum
|
2024-12-06 18:02:59 +00:00
|
|
|
from typing import TYPE_CHECKING, Any, Dict, List
|
2024-11-10 15:13:29 +00:00
|
|
|
|
|
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
2023-02-26 12:52:08 +00:00
|
|
|
|
|
|
|
from app.brm.brn import BRN
|
|
|
|
from app.extensions import db
|
|
|
|
from app.models import AbstractConfiguration
|
2023-05-25 15:32:31 +01:00
|
|
|
from app.models.mirrors import StaticOrigin
|
2023-02-26 12:52:08 +00:00
|
|
|
|
2024-11-10 15:13:29 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from app.models.bridges import Bridge
|
|
|
|
|
|
|
|
|
2023-02-26 12:52:08 +00:00
|
|
|
class CloudProvider(enum.Enum):
|
|
|
|
AWS = ("aws", "Amazon Web Services")
|
|
|
|
AZURE = ("azure", "Microsoft Azure")
|
|
|
|
BUNNY = ("bunny", "bunny.net")
|
|
|
|
CLOUDFLARE = ("cloudflare", "Cloudflare")
|
|
|
|
FASTLY = ("fastly", "Fastly")
|
|
|
|
HTTP = ("http", "HTTP")
|
|
|
|
GANDI = ("gandi", "Gandi")
|
|
|
|
GITHUB = ("github", "GitHub")
|
|
|
|
GITLAB = ("gitlab", "GitLab")
|
|
|
|
HCLOUD = ("hcloud", "Hetzner Cloud")
|
|
|
|
MAXMIND = ("maxmind", "MaxMind")
|
|
|
|
OVH = ("ovh", "OVH")
|
|
|
|
RFC2136 = ("rfc2136", "RFC2136 DNS Server")
|
|
|
|
|
|
|
|
def __init__(self, key: str, description: str):
|
|
|
|
self.key = key
|
|
|
|
self.description = description
|
|
|
|
|
|
|
|
|
|
|
|
class CloudAccount(AbstractConfiguration):
|
2024-11-10 15:13:29 +00:00
|
|
|
provider: Mapped[CloudProvider]
|
|
|
|
credentials: Mapped[Dict[str, Any]] = mapped_column(db.JSON())
|
|
|
|
enabled: Mapped[bool]
|
2023-02-26 12:52:08 +00:00
|
|
|
# CDN Quotas
|
2024-11-10 15:13:29 +00:00
|
|
|
max_distributions: Mapped[int]
|
|
|
|
max_sub_distributions: Mapped[int]
|
2023-02-26 12:52:08 +00:00
|
|
|
# Compute Quotas
|
2024-11-10 15:13:29 +00:00
|
|
|
max_instances: Mapped[int]
|
2023-02-26 12:52:08 +00:00
|
|
|
|
2024-12-06 18:15:47 +00:00
|
|
|
bridges: Mapped[List["Bridge"]] = relationship(
|
|
|
|
"Bridge", back_populates="cloud_account"
|
|
|
|
)
|
|
|
|
statics: Mapped[List["StaticOrigin"]] = relationship(
|
|
|
|
"StaticOrigin",
|
|
|
|
back_populates="storage_cloud_account",
|
|
|
|
foreign_keys=[StaticOrigin.storage_cloud_account_id],
|
|
|
|
)
|
2023-02-26 12:52:08 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def brn(self) -> BRN:
|
|
|
|
raise NotImplementedError("No BRN for cloud accounts")
|