2022-04-27 14:50:41 +01:00
|
|
|
import builtins
|
2022-04-27 13:30:49 +01:00
|
|
|
from typing import Dict
|
|
|
|
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from tldextract import extract
|
|
|
|
|
|
|
|
from app import Proxy
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
__root__: Dict[str, MMMirror] = Field(
|
|
|
|
description="The domain name for the mirror"
|
|
|
|
)
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
title = "Mirror Mapping Version 1"
|
|
|
|
|
|
|
|
|
|
|
|
def mirror_mapping():
|
2022-05-01 17:08:48 +01:00
|
|
|
return MirrorMapping(__root__={
|
2022-04-27 13:30:49 +01:00
|
|
|
d.url.lstrip("https://"): MMMirror(
|
|
|
|
origin_domain=d.origin.domain_name,
|
|
|
|
origin_domain_normalized=d.origin.domain_name.lstrip("www."),
|
|
|
|
origin_domain_root=extract(d.origin.domain_name).registered_domain
|
|
|
|
) for d in Proxy.query.all() if d.url is not None
|
|
|
|
}).dict()
|
2022-04-27 14:50:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
if getattr(builtins, "__sphinx_build__", False):
|
|
|
|
schema = MirrorMapping.schema_json()
|