Initial YakPanel commit
This commit is contained in:
77
class/sewer/dns_providers/common.py
Normal file
77
class/sewer/dns_providers/common.py
Normal file
@@ -0,0 +1,77 @@
|
||||
import logging
|
||||
|
||||
|
||||
class BaseDns(object):
|
||||
"""
|
||||
"""
|
||||
|
||||
def __init__(self, LOG_LEVEL="INFO"):
|
||||
self.LOG_LEVEL = LOG_LEVEL
|
||||
self.dns_provider_name = self.__class__.__name__
|
||||
|
||||
self.logger = logging.getLogger("sewer")
|
||||
handler = logging.StreamHandler()
|
||||
formatter = logging.Formatter("%(message)s")
|
||||
handler.setFormatter(formatter)
|
||||
if not self.logger.handlers:
|
||||
self.logger.addHandler(handler)
|
||||
self.logger.setLevel(self.LOG_LEVEL)
|
||||
|
||||
def log_response(self, response):
|
||||
"""
|
||||
renders a python-requests response as json or as a string
|
||||
"""
|
||||
try:
|
||||
log_body = response.json()
|
||||
except ValueError:
|
||||
log_body = response.content
|
||||
return log_body
|
||||
|
||||
def create_dns_record(self, domain_name, domain_dns_value):
|
||||
"""
|
||||
Method that creates/adds a model TXT record for a domain/subdomain name on
|
||||
a chosen DNS provider.
|
||||
|
||||
:param domain_name: :string: The domain/subdomain name whose model record ought to be
|
||||
created/added on a chosen DNS provider.
|
||||
:param domain_dns_value: :string: The value/content of the TXT record that will be
|
||||
created/added for the given domain/subdomain
|
||||
|
||||
This method should return None
|
||||
|
||||
Basic Usage:
|
||||
If the value of the `domain_name` variable is example.com and the value of
|
||||
`domain_dns_value` is HAJA_4MkowIFByHhFaP8u035skaM91lTKplKld
|
||||
Then, your implementation of this method ought to create a DNS TXT record
|
||||
whose name is '_acme-challenge' + '.' + domain_name + '.' (ie: _acme-challenge.example.com. )
|
||||
and whose value/content is HAJA_4MkowIFByHhFaP8u035skaM91lTKplKld
|
||||
|
||||
Using a model client like dig(https://linux.die.net/man/1/dig) to do a model lookup should result
|
||||
in something like:
|
||||
dig TXT _acme-challenge.example.com
|
||||
...
|
||||
;; ANSWER SECTION:
|
||||
_acme-challenge.example.com. 120 IN TXT "HAJA_4MkowIFByHhFaP8u035skaM91lTKplKld"
|
||||
_acme-challenge.singularity.brandur.org. 120 IN TXT "9C0DqKC_4MkowIFByHhFaP8u0Zv4z7Wz2IHM91lTKec"
|
||||
Optionally, you may also use an online model client like: https://toolbox.googleapps.com/apps/dig/#TXT/
|
||||
|
||||
Please consult your model provider on how/format of their DNS TXT records.
|
||||
You may also want to consult the cloudflare DNS implementation that is found in this repository.
|
||||
"""
|
||||
self.logger.info("create_dns_record")
|
||||
raise NotImplementedError("create_dns_record method must be implemented.")
|
||||
|
||||
def delete_dns_record(self, domain_name, domain_dns_value):
|
||||
"""
|
||||
Method that deletes/removes a model TXT record for a domain/subdomain name on
|
||||
a chosen DNS provider.
|
||||
|
||||
:param domain_name: :string: The domain/subdomain name whose model record ought to be
|
||||
deleted/removed on a chosen DNS provider.
|
||||
:param domain_dns_value: :string: The value/content of the TXT record that will be
|
||||
deleted/removed for the given domain/subdomain
|
||||
|
||||
This method should return None
|
||||
"""
|
||||
self.logger.info("delete_dns_record")
|
||||
raise NotImplementedError("delete_dns_record method must be implemented.")
|
||||
Reference in New Issue
Block a user