Added valid_from and valid_to fields to Bypass Censorship Analytics JSON output

This commit is contained in:
Owen 2022-11-15 15:03:29 +00:00 committed by irl
parent 0a13b3ee75
commit 8c3ef42a8c

View file

@ -1,10 +1,12 @@
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
import builtins import builtins
import datetime
from typing import Dict, List, Union from typing import Dict, List, Union
from flask import current_app from flask import current_app
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from pydantic.typing import Optional
from tldextract import extract from tldextract import extract
from app.models.base import Group, Pool from app.models.base import Group, Pool
@ -15,6 +17,8 @@ class MMMirror(BaseModel):
origin_domain: str = Field(description="The full origin domain name") 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_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") origin_domain_root: str = Field(description="The registered domain name of the origin, excluding subdomains")
valid_from: str = Field(description="The date on which the mirror was added to the system")
valid_to: Optional[str] = Field(description="The date on which the mirror was decommissioned")
class MirrorMapping(BaseModel): class MirrorMapping(BaseModel):
@ -39,7 +43,9 @@ def mirror_mapping(pool: Pool) -> Dict[str, Union[str, Dict[str, str]]]:
d.url.lstrip("https://"): MMMirror( d.url.lstrip("https://"): MMMirror(
origin_domain=d.origin.domain_name, origin_domain=d.origin.domain_name,
origin_domain_normalized=d.origin.domain_name.replace("www.", ""), origin_domain_normalized=d.origin.domain_name.replace("www.", ""),
origin_domain_root=extract(d.origin.domain_name).registered_domain origin_domain_root=extract(d.origin.domain_name).registered_domain,
valid_from=d.origin.added.isoformat(),
valid_to=d.origin.destroyed.isoformat() if d.origin.destroyed is not None else None
) for d in Proxy.query.all() if d.url is not None ) for d in Proxy.query.all() if d.url is not None
}, },
s3_buckets=[ s3_buckets=[