2022-06-17 14:02:10 +01:00
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
|
2022-04-27 14:50:41 +01:00
|
|
|
import builtins
|
2022-05-16 11:44:03 +01:00
|
|
|
from typing import Dict, List, Union
|
2022-04-27 13:30:49 +01:00
|
|
|
|
2022-05-17 08:28:37 +01:00
|
|
|
from flask import current_app
|
2022-04-27 13:30:49 +01:00
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from tldextract import extract
|
|
|
|
|
2022-05-11 10:38:27 +01:00
|
|
|
from app.models.base import Group
|
|
|
|
from app.models.mirrors import Proxy
|
2022-04-27 13:30:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
class MMMirror(BaseModel):
|
|
|
|
origin_domain: str = Field(description="The full origin domain name")
|
|
|
|
origin_domain_normalized: str = Field(description="The origin_domain with \"www.\" removed, if present")
|
|
|
|
origin_domain_root: str = Field(description="The registered domain name of the origin, excluding subdomains")
|
|
|
|
|
|
|
|
|
|
|
|
class MirrorMapping(BaseModel):
|
2022-05-10 15:07:23 +01:00
|
|
|
version: str = Field(
|
|
|
|
description="Version number of the mirror mapping schema in use"
|
|
|
|
)
|
|
|
|
mappings: Dict[str, MMMirror] = Field(
|
2022-04-27 13:30:49 +01:00
|
|
|
description="The domain name for the mirror"
|
|
|
|
)
|
2022-05-11 10:38:27 +01:00
|
|
|
s3_buckets: List[str] = Field(
|
|
|
|
description="The names of all S3 buckets used for CloudFront logs"
|
|
|
|
)
|
2022-04-27 13:30:49 +01:00
|
|
|
|
|
|
|
class Config:
|
2022-05-11 10:38:27 +01:00
|
|
|
title = "Mirror Mapping Version 1.1"
|
2022-04-27 13:30:49 +01:00
|
|
|
|
|
|
|
|
2022-05-16 11:44:03 +01:00
|
|
|
def mirror_mapping() -> Dict[str, Union[str, Dict[str, str]]]:
|
2022-05-11 10:38:27 +01:00
|
|
|
return MirrorMapping(
|
|
|
|
version="1.1",
|
|
|
|
mappings={
|
|
|
|
d.url.lstrip("https://"): MMMirror(
|
2022-05-12 09:57:42 +01:00
|
|
|
origin_domain=d.origin.description[len("proxy:"):] if d.origin.description.startswith(
|
|
|
|
"proxy:") else d.origin.domain_name,
|
2022-06-23 13:42:45 +01:00
|
|
|
origin_domain_normalized=d.origin.description[
|
|
|
|
len("proxy:"):].replace("www.", "") if d.origin.description.startswith(
|
2022-05-12 09:57:42 +01:00
|
|
|
"proxy:") else d.origin.domain_name.replace("www.", ""),
|
|
|
|
origin_domain_root=extract(d.origin.description[len("proxy:"):] if d.origin.description.startswith(
|
|
|
|
"proxy:") else d.origin.domain_name).registered_domain
|
2022-05-11 10:38:27 +01:00
|
|
|
) for d in Proxy.query.all() if d.url is not None
|
|
|
|
},
|
|
|
|
s3_buckets=[
|
2022-05-17 08:28:37 +01:00
|
|
|
f"{current_app.config['GLOBAL_NAMESPACE']}-{g.group_name.lower()}-logs-cloudfront"
|
2022-05-16 13:29:48 +01:00
|
|
|
for g in Group.query.filter(Group.destroyed.is_(None)).all()
|
2022-05-11 10:38:27 +01:00
|
|
|
]
|
|
|
|
).dict()
|
2022-04-27 14:50:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
if getattr(builtins, "__sphinx_build__", False):
|
|
|
|
schema = MirrorMapping.schema_json()
|