Skip to content

Commit

Permalink
Fix: Reformat with black
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Aug 28, 2023
1 parent 86df08f commit 038a7ff
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 40 deletions.
79 changes: 43 additions & 36 deletions src/aleph/sdk/domain.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import aiodns
import re
from .conf import settings
from typing import Optional

import aiodns

from aleph.sdk.exceptions import DomainConfigurationError

from .conf import settings


class AlephDNS:
def __init__(self):
Expand Down Expand Up @@ -42,9 +45,7 @@ async def check_domain_configured(self, domain, target, owner):
except Exception as error:
raise DomainConfigurationError(error)

async def check_domain(
self, url: str, target: str, owner: Optional[str] = None
):
async def check_domain(self, url: str, target: str, owner: Optional[str] = None):
status = {"cname": False, "owner_proof": False}

target = target.lower()
Expand Down Expand Up @@ -73,7 +74,11 @@ async def check_domain(
(dns_rule["info"], dns_rule["on_error"], status)
)

elif res is None or not hasattr(res, record_type) or getattr(res, record_type) != record_value:
elif (
res is None
or not hasattr(res, record_type)
or getattr(res, record_type) != record_value
):
raise DomainConfigurationError(
(dns_rule["info"], dns_rule["on_error"], status)
)
Expand All @@ -95,41 +100,43 @@ def get_required_dns_rules(self, url, target, owner: Optional[str] = None):
cname_value = f"{domain}.{settings.DNS_INSTANCE_DOMAIN}"

# cname rule
dns_rules.append({
"rule_name": "cname",
"dns": {
"type": "cname",
"name": domain,
"value": cname_value
},
"info": f"Create a CNAME record for {domain} with value {cname_value}",
"on_error": f"CNAME record not found: {domain}"
})
dns_rules.append(
{
"rule_name": "cname",
"dns": {"type": "cname", "name": domain, "value": cname_value},
"info": f"Create a CNAME record for {domain} with value {cname_value}",
"on_error": f"CNAME record not found: {domain}",
}
)

if target == "ipfs":
# ipfs rule
dns_rules.append({
"rule_name": "delegation",
"dns": {
"type": "cname",
"name": f"_dnslink.{domain}",
"value": f"_dnslink.{domain}.{settings.DNS_ROOT_DOMAIN}"
},
"info": f"Create a CNAME record for _dnslink.{domain} with value _dnslink.{domain}.{settings.DNS_ROOT_DOMAIN}",
"on_error": f"CNAME record not found: _dnslink.{domain}"
})
dns_rules.append(
{
"rule_name": "delegation",
"dns": {
"type": "cname",
"name": f"_dnslink.{domain}",
"value": f"_dnslink.{domain}.{settings.DNS_ROOT_DOMAIN}",
},
"info": f"Create a CNAME record for _dnslink.{domain} with value _dnslink.{domain}.{settings.DNS_ROOT_DOMAIN}",
"on_error": f"CNAME record not found: _dnslink.{domain}",
}
)

if owner:
# ownership rule
dns_rules.append({
"rule_name": "owner_proof",
"dns": {
"type": "txt",
"name": f"_control.{domain}",
"value": owner
},
"info": f"Create a TXT record for _control.{domain} with value = owner address",
"on_error": f"Owner address mismatch"
})
dns_rules.append(
{
"rule_name": "owner_proof",
"dns": {
"type": "txt",
"name": f"_control.{domain}",
"value": owner,
},
"info": f"Create a TXT record for _control.{domain} with value = owner address",
"on_error": f"Owner address mismatch",
}
)

return dns_rules
8 changes: 4 additions & 4 deletions tests/unit/test_domains.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import asyncio

import pytest

from aleph.sdk.domain import AlephDNS
from aleph.sdk.exceptions import DomainConfigurationError

Expand Down Expand Up @@ -36,15 +37,14 @@ async def test_dnslink():
@pytest.mark.asyncio
async def test_configured_domain():
alephdns = AlephDNS()
url = 'https://custom-domain-unit-test.aleph.sh'
url = "https://custom-domain-unit-test.aleph.sh"
status = await alephdns.check_domain(url, "ipfs", "0xfakeaddress")
assert type(status) is dict


@pytest.mark.asyncio
async def test_not_configured_domain():
alephdns = AlephDNS()
url = 'https://not-configured-domain.aleph.sh'
url = "https://not-configured-domain.aleph.sh"
with pytest.raises(DomainConfigurationError):
status = await alephdns.check_domain(url, "ipfs", "0xfakeaddress")

0 comments on commit 038a7ff

Please sign in to comment.