add support for any DoH provider; closes #254; closes #256

This commit is contained in:
thatmattlove 2024-06-01 15:25:41 -04:00
parent bfcae89bf0
commit aab4ada723
2 changed files with 11 additions and 4 deletions

View file

@ -16,8 +16,9 @@ hyperglass provides extensive customization options for the look and feel of the
[DNS over HTTPS](https://www.rfc-editor.org/rfc/rfc8484) is used to look up an FQDN query target from the perspective of the user's browser. [DNS over HTTPS](https://www.rfc-editor.org/rfc/rfc8484) is used to look up an FQDN query target from the perspective of the user's browser.
| Parameter | Type | Default Value | Description | | Parameter | Type | Default Value | Description |
| :------------------ | :----- | :------------ | :-------------------------------------- | | :------------------ | :----- | :------------------------------------- | :-------------------------------------------------------------------------- |
| `dns_provider.name` | String | cloudflare | Cloudflare or Google DNS are supported. | | `dns_provider.name` | String | cloudflare | If `cloudflare` or `google` are provided, no URL is necessary. |
| `dns_provider.url` | String | `https://cloudflare-dns.com/dns-query` | Provide a custom DNS over HTTPS URL if you'd like to use your own resolver. |
### Logo ### Logo

View file

@ -186,13 +186,19 @@ class Theme(HyperglassModel):
class DnsOverHttps(HyperglassModel): class DnsOverHttps(HyperglassModel):
"""Validation model for DNS over HTTPS resolution.""" """Validation model for DNS over HTTPS resolution."""
name: str = Field(default="cloudflare", pattern=DOH_PROVIDERS_PATTERN) name: str = "cloudflare"
url: str = "" url: str = ""
@model_validator(mode="before") @model_validator(mode="before")
def validate_dns(cls, data: "DnsOverHttps") -> t.Dict[str, str]: def validate_dns(cls, data: "DnsOverHttps") -> t.Dict[str, str]:
"""Assign url field to model based on selected provider.""" """Assign url field to model based on selected provider."""
name = data.get("name", "cloudflare") name = data.get("name", "cloudflare")
url = data.get("url", DNS_OVER_HTTPS["cloudflare"])
if url not in DNS_OVER_HTTPS.values():
return {
"name": "custom",
"url": url,
}
url = DNS_OVER_HTTPS[name] url = DNS_OVER_HTTPS[name]
return { return {
"name": name, "name": name,