Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : AlephDNS #47

Merged
merged 4 commits into from
Aug 25, 2023
Merged

Feature : AlephDNS #47

merged 4 commits into from
Aug 25, 2023

Conversation

1yam
Copy link
Collaborator

@1yam 1yam commented Jul 13, 2023

Implement AlephDNS from @aliel inside SDK

src/aleph/sdk/conf.py Outdated Show resolved Hide resolved
src/aleph/sdk/conf.py Outdated Show resolved Hide resolved
tests/unit/test_domains.py Outdated Show resolved Hide resolved
src/aleph/sdk/domain.py Outdated Show resolved Hide resolved
src/aleph/sdk/domain.py Outdated Show resolved Hide resolved
src/aleph/sdk/domain.py Outdated Show resolved Hide resolved
@odesenfans odesenfans requested a review from aliel July 13, 2023 10:09
@aliel aliel force-pushed the 1yam_domain branch 2 times, most recently from ebb4afb to 93ea8ad Compare July 13, 2023 17:34
Copy link
Member

@aliel aliel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@aliel aliel requested a review from odesenfans July 13, 2023 17:37
@MHHukiewitz
Copy link
Member

Merge? Yes/No/Only with PBJ?

@aliel aliel removed the request for review from odesenfans August 8, 2023 15:11
Copy link
Member

@aliel aliel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to Merge

@aliel aliel requested a review from odesenfans August 8, 2023 15:13
@aliel aliel removed the request for review from odesenfans August 25, 2023 09:06
@aliel aliel dismissed odesenfans’s stale review August 25, 2023 09:07

already reviewed

@aliel aliel merged commit 86df08f into aleph-im:main Aug 25, 2023
5 checks passed
Copy link
Member

@hoh hoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for reviewing late for merge, but I have a few issues with the quality of this branch that should be improved before releasing it.

async def query(self, name: str, query_type: str):
try:
return await self.resolver.query(name, query_type)
except Exception as e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aliel what is the exception that we are expected here ? Catching all exceptions to stdout is not a best practice.

class AlephDNS:
def __init__(self):
self.resolver = aiodns.DNSResolver(servers=settings.DNS_RESOLVERS)
self.fqdn_matcher = re.compile(r"https?://?")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the second ? at the end ?

return None

def url_to_domain(self, url):
return self.fqdn_matcher.sub("", url).strip().strip("/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify the strip() call

return self.fqdn_matcher.sub("", url).strip(" /")

def url_to_domain(self, url):
return self.fqdn_matcher.sub("", url).strip().strip("/")

async def get_ipv6_address(self, url: str):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type does this return ?


async def check_domain_configured(self, domain, target, owner):
try:
print("Check...", target)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use logging.debug instead of print here ?

},
"info": f"Create a CNAME record for {domain} with value {cname_value}",
"on_error": f"CNAME record not found: {domain}"
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use a dataclasses instead of a dict for this data ?


async def check_domain(
self, url: str, target: str, owner: Optional[str] = None
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a docstring to explain what this is checking ?

Comment on lines +67 to +74
for _res in res:
if hasattr(_res, "text") and _res.text == record_value:
found = True

if found == False:
raise DomainConfigurationError(
(dns_rule["info"], dns_rule["on_error"], status)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a for ... else ... loop ?

                for _res in res:
                    if hasattr(_res, "text") and _res.text == record_value:
                        break
                else:
                    raise DomainConfigurationError(
                        (dns_rule["info"], dns_rule["on_error"], status)
                    )

hoh pushed a commit that referenced this pull request Oct 23, 2023
* Feature : AlephDNS
add instances support
add ipfs support
add program support

---------

Co-authored-by: aliel <[email protected]>
aliel added a commit that referenced this pull request Nov 10, 2023
* Feature : AlephDNS
add instances support
add ipfs support
add program support

---------

Co-authored-by: aliel <[email protected]>
MHHukiewitz added a commit that referenced this pull request Nov 21, 2023
* Feature : AlephDNS (#47)

* Feature : AlephDNS
add instances support
add ipfs support
add program support

---------

Co-authored-by: aliel <[email protected]>

* Fix: Reformat with `black`

* minor change on dns settings

* avoid not valid local variable in certain conditions

* add method to retreive txt values

* fix dns record check

* fix program cname value

* Refactor: str -> Enum for DNS target

* Refactor: Add types to arguments

* Fix: variable did not exist

* Add typing

* Cleanup: imports with isort

* Cleanup: typing

* Refactor: domain_from_url

* Refactor: use a generator

* Cleanup: Add docstring and property

* WIP: Refactor and cleanup domain related code

* [dns] let checks continue

* fix hostname_from_url when it's already a hostname

* remove unused import

* speedup dns detection using authoritative ns server

* fix cname to target

* fix cond

* fix while loop

* Fix typing; add docs; refactor for clarity

---------

Co-authored-by: 1yam <[email protected]>
Co-authored-by: aliel <[email protected]>
Co-authored-by: mhh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants