feat: initial api implementation
This commit is contained in:
parent
a482d5bba8
commit
ae905c6d80
4 changed files with 239 additions and 9 deletions
|
@ -33,6 +33,15 @@ class Group(AbstractConfiguration):
|
|||
resource_id=str(self.id)
|
||||
)
|
||||
|
||||
def to_dict(self):
|
||||
active_origins = [o for o in self.origins if o.destroyed is None]
|
||||
return {
|
||||
"Id": self.id,
|
||||
"GroupName": self.group_name,
|
||||
"Description": self.description,
|
||||
"ActiveOriginCount": len(active_origins),
|
||||
}
|
||||
|
||||
|
||||
class Pool(AbstractConfiguration):
|
||||
pool_name = db.Column(db.String(80), unique=True, nullable=False)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import tldextract
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Optional, List, Union, Any, Dict
|
||||
|
||||
import tldextract
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from tldextract import extract
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
@ -96,9 +96,19 @@ class Origin(AbstractConfiguration):
|
|||
frequency_factor += 1
|
||||
risk_levels: Dict[str, int] = {}
|
||||
for country in self.countries:
|
||||
risk_levels[country.country_code.upper()] = int(max(1, min(10, frequency_factor * recency_factor))) + country.risk_level
|
||||
risk_levels[country.country_code.upper()] = int(
|
||||
max(1, min(10, frequency_factor * recency_factor))) + country.risk_level
|
||||
return risk_levels
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"Id": self.id,
|
||||
"Description": self.description,
|
||||
"DomainName": self.domain_name,
|
||||
"RiskLevel": self.risk_level,
|
||||
"RiskLevelOverride": self.risk_level_override,
|
||||
}
|
||||
|
||||
|
||||
class Country(AbstractConfiguration):
|
||||
@property
|
||||
|
@ -268,6 +278,21 @@ class Proxy(AbstractResource):
|
|||
"origin_id", "provider", "psg", "slug", "terraform_updated", "url"
|
||||
]
|
||||
|
||||
def to_dict(self):
|
||||
status = "active"
|
||||
if self.url is None:
|
||||
status = "pending"
|
||||
if self.deprecated is not None:
|
||||
status = "expiring"
|
||||
if self.destroyed is not None:
|
||||
status = "destroyed"
|
||||
return {
|
||||
"Id": self.id,
|
||||
"OriginDomain": self.origin.domain_name,
|
||||
"MirrorDomain": self.url.replace("https://", "") if self.url else None,
|
||||
"Status": status,
|
||||
}
|
||||
|
||||
|
||||
class SmartProxy(AbstractResource):
|
||||
group_id = mapped_column(db.Integer(), db.ForeignKey("group.id"), nullable=False)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue