Skip to content

Commit

Permalink
Merge pull request #33 from pogzyb/add-basic-validation
Browse files Browse the repository at this point in the history
Add basic response validation to `to_whois_dict`
  • Loading branch information
pogzyb authored Oct 5, 2023
2 parents dd0c495 + 944644d commit 9296870
Show file tree
Hide file tree
Showing 6 changed files with 691 additions and 60 deletions.
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,37 @@ async with whodap.DNSClient.new_aio_client_context(aio_httpx_client) as dns_clie
response = await dns_client.aio_lookup(domain, tld)
```

- Using the `to_whois_dict` method and `RDAPConformanceException`
```python
import logging

from whodap import lookup_domain
from whodap.errors import RDAPConformanceException

logger = logging.getLogger(__name__)

# strict = False (default)
rdap_response = lookup_domain("example", "com")
whois_format = rdap_response.to_whois_dict()
logger.info(f"whois={whois_format}")
# Given a valid RDAP response, the `to_whois_dict` method will attempt to
# convert the RDAP format into a flattened dictionary of WHOIS key/values

# strict = True
try:
# Unfortunately, there are instances in which the RDAP protocol is not
# properly implemented by the registrar. By default, the `to_whois_dict`
# will still attempt to parse the into the WHOIS dictionary. However,
# there is no guarantee that the information will be correct or non-null.
# If your applications rely on accurate information, the `strict=True`
# parameter will raise an `RDAPConformanceException` when encountering
# invalid or incorrectly formatted RDAP responses.
rdap_response = lookup_domain("example", "com")
whois_format = rdap_response.to_whois_dict(strict=True)
except RDAPConformanceException:
logger.exception("RDAP response is incorrectly formatted.")
```

#### Contributions
- Interested in contributing?
- Have any questions or comments?
Expand All @@ -186,8 +217,8 @@ Please post a question or comment.
- ~~Support for RDAP ASN queries~~
- Abstract the HTTP Client (`httpx` is the defacto client for now)
- Add parser utils/helpers for IPv4, IPv6, and ASN Responses (if someone shows interest)
- Add RDAP response validation support leveraging [ICANN's tool](https://github.com/icann/rdap-conformance-tool/)

#### RDAP Resources:
- https://rdap.org/
- https://tools.ietf.org/html/rfc7483
- https://tools.ietf.org/html/rfc6350
- [rdap.org](https://rdap.org/)
- [RFC 9082](https://datatracker.ietf.org/doc/html/rfc9082)
Loading

0 comments on commit 9296870

Please sign in to comment.