set region to optional
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Roy Olav Purser 2022-02-12 13:05:42 +01:00
parent f9964a8157
commit 7281614024
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -44,7 +44,7 @@ proxy_server = os.environ.get("PROXY_SERVER")
class ProxyCreateLink(pydantic.BaseModel):
upstream: pydantic.HttpUrl
ctype: Optional[pydantic.StrictStr]
region: pydantic.StrictStr
region: Optional[pydantic.StrictStr]
class ProxyRequest(pydantic.BaseModel):
@ -75,10 +75,16 @@ class ProxyElem:
for url in urls:
if isinstance(url, tuple):
clean_urls.append(url[0])
link_requests.append(ProxyCreateLink.parse_obj({"upstream": url[0], "ctype": url[1], "region": self.region}))
link_requests.append(
ProxyCreateLink.parse_obj(
{"upstream": url[0], "ctype": url[1], "region": self.region}
)
)
else:
clean_urls.append(url)
link_requests.append(ProxyCreateLink.parse_obj({"upstream": url, "region": self.region}))
link_requests.append(
ProxyCreateLink.parse_obj({"upstream": url, "region": self.region})
)
if not isinstance(proxy_server, str):
return clean_urls
@ -86,7 +92,9 @@ class ProxyElem:
response_data: ProxyResponse
try:
request_data = ProxyRequest.parse_obj({"urls": link_requests, "action": "create-urls"})
request_data = ProxyRequest.parse_obj(
{"urls": link_requests, "action": "create-urls"}
)
except pydantic.ValidationError as e:
logger.info(e)
return clean_urls
@ -94,7 +102,9 @@ class ProxyElem:
try:
async with self.local() as session:
resp = await session.post(proxy_server, json=request_data)
response_data = cast(ProxyResponse, ProxyResponse.parse_obj(await resp.text()))
response_data = cast(
ProxyResponse, ProxyResponse.parse_obj(await resp.text())
)
except Exception as e:
logger.info(e)
else: