schemas: generate some good schemas
This commit is contained in:
parent
ed56ed5368
commit
b7a2201ad6
10 changed files with 205 additions and 122 deletions
31
app/lists/mirror_mapping.py
Normal file
31
app/lists/mirror_mapping.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
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():
|
||||
return MirrorMapping(**{
|
||||
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()
|
Loading…
Add table
Add a link
Reference in a new issue