feat: update mirror mapping schema for version 1.2

This commit is contained in:
Iain Learmonth 2023-10-29 19:28:21 +00:00
parent 629993301a
commit 6e5adb8801
3 changed files with 73 additions and 14 deletions

View file

@ -20,9 +20,10 @@ class MMMirror(BaseModel):
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")
# countries: List[Tuple[str, int]] = Field(description="A list mapping of risk levels to country")
country: Optional[str] = Field(description="The country code of the country in which the origin is targeted")
risk: int = Field(description="A risk score for the origin in the target country")
countries: Dict[str, int] = Field(description="A list mapping of risk levels to country")
country: Optional[str] = Field(
description="The country code of the country with the highest risk level where the origin is targeted")
risk: int = Field(description="The risk score for the highest risk country")
class MirrorMapping(BaseModel):
@ -37,7 +38,7 @@ class MirrorMapping(BaseModel):
)
class Config:
title = "Mirror Mapping Version 1.1"
title = "Mirror Mapping Version 1.2"
def mirror_mapping(_: Optional[Pool]) -> Dict[str, Union[str, Dict[str, str]]]:
@ -67,7 +68,7 @@ def mirror_mapping(_: Optional[Pool]) -> Dict[str, Union[str, Dict[str, str]]]:
origin_domain_root=extract(proxy.origin.domain_name).registered_domain,
valid_from=proxy.added.isoformat(),
valid_to=proxy.destroyed.isoformat() if proxy.destroyed is not None else None,
# countries=[], # TODO: countries,
countries=proxy.origin.risk_level,
country=highest_risk_country_code,
risk=highest_risk_level
)