letsdns package

Submodules

letsdns.action module

class letsdns.action.Action

Bases: abc.ABC

Abstract base class for LetsDNS actions.

abstract execute(conf: letsdns.configuration.Config, *args, **kwargs) int

Action classes MUST implement this method. Unknown positional and keyword arguments MUST be ignored.

Args:

conf: Configuration data. args: Positional arguments. kwargs: Keyword arguments.

classmethod lifecycle(conf: letsdns.configuration.Config, action) int

Invoke the lifecycle methods of a dynamically imported action. The first non-zero method return code will abort execution and will be returned to the caller.

Args:

conf: Configuration data. action: Action object. Ignored in the default implementation.

setup(conf: letsdns.configuration.Config) int

Pre-execution phase, for initialisation.

teardown(conf: letsdns.configuration.Config) int

Post-execution phase, for cleanup.

letsdns.action.import_action(class_name: str) Type[letsdns.action.Action]

Dynamically import an action class. Raises a TypeError exception if the imported class is not a subclass of ‘Action’.

Args:

class_name: Fully qualified class name, e.g. “mymodule.actions.SomeAction”.

letsdns.action.import_class(class_name: str)

Dynamically import a Python class. The containing module must be available in PYTHONPATH.

Args:

class_name: Fully qualified class name, e.g. “mymodule.submodule.MyClass”.

letsdns.configuration module

class letsdns.configuration.Config

Bases: object

Provide access to configuration data.

dump(destination=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>) None

Dump configuration state into a file.

Args:

destination: File pointer.

get(name: str, fallback=None) str

Return an optional configuration value or the specified fallback value.

Args:

name: Option name. fallback: Returned if option is undefined.

get_domain() str

Return the mandatory ‘domain’ configuration value.

Raise an exception if ‘domain’ is undefined.

get_mandatory(name: str) str

Return a mandatory configuration value. Raise an exception if option value is undefined.

Args:

name: Option name.

get_tcp_ports() List[str]

Return the optional ‘tcp_ports’ configuration value.

get_ttl() int

Return the ‘ttl’ configuration value (seconds, integer).

init(filenames=None) None

Initialise object by loading configuration files from disk. Nonexisting or unreadable files are silently ignored.

Args:

filenames: Either a single string or a list of strings.

options() List[str]

Return all options in the active section.

letsdns.configuration.init_logger() None

Initialise logger.

letsdns.configuration.log_level(default: str = 'ERROR') int

Return logging level, using the LOG_LEVEL environment variable if available.

Args:

default: The default log level.

letsdns.core module

letsdns.core.action_class(name: str) Optional[letsdns.action.Action]

Return action class for the given name.

Args:

name: Action name.

letsdns.core.traverse_config(conf: letsdns.configuration.Config) int

Traverse and process the configuration sections. Return the number of processed actions.

Args:

conf: Configuration object.

letsdns.crypto module

letsdns.crypto.dane_tlsa_records(cert: cryptography.x509.base.Certificate) List[str]

Return list of TLSA record data for the certificate.

Args:

cert: x509 certificate.

letsdns.crypto.read_x509_cert(filename: str) cryptography.x509.base.Certificate

Read x509 certificate from file.

letsdns.crypto.sha_digests(something)

Generate hexadecimal SHA256 and SHA512 hashes for some data.

letsdns.hetznerapi module

class letsdns.hetznerapi.HetznerApiUpdate

Bases: letsdns.action.Action

cleanup_records(zone_id: str, name: str) bool

Delete existing TLSA records. Returns True to indicate success.

Args:

zone_id: Parent zone ID. name: DNS record name.

execute(conf: letsdns.configuration.Config, *args, **kwargs) int

Update DNS record using the Hetzner DNS API. Return 0 to indicate success.

find_records(zone_id: str, name: str) Optional[List[str]]

Returns matching record ID list for the given zone ID and name, or None in case of errors.

Args:

zone_id: Parent zone ID. name: DNS record name.

classmethod lifecycle(conf: letsdns.configuration.Config, action: letsdns.action.Action) int

Process configuration data.

zone_id(domain: str) Optional[str]

Returns zone ID for the given domain name, or None in case of errors.

Args:

domain: Domain name, e.g. “example.com”.

letsdns.liveupdate module

class letsdns.liveupdate.DnsLiveUpdate

Bases: letsdns.action.Action

execute(conf: letsdns.configuration.Config, *args, **kwargs) int

Update DNS record using the dnspython library. Return 0 to indicate success.

classmethod lifecycle(conf: letsdns.configuration.Config, action: letsdns.action.Action) int

Invoke the lifecycle methods of a dynamically imported action. The first non-zero method return code will abort execution and will be returned to the caller.

Args:

conf: Configuration data. action: Action object. Ignored in the default implementation.

letsdns.nsupdate module

class letsdns.nsupdate.NsupdateStdout

Bases: letsdns.action.Action

execute(conf: letsdns.configuration.Config, *args, **kwargs) int

Generate ‘nsupdate’ command list and print to stdout.

classmethod lifecycle(conf: letsdns.configuration.Config, action) int

Invoke the lifecycle methods of a dynamically imported action. The first non-zero method return code will abort execution and will be returned to the caller.

Args:

conf: Configuration data. action: Action object. Ignored in the default implementation.

letsdns.tlsa module

letsdns.tlsa.rdata_action_lifecycle(conf: letsdns.configuration.Config, action: letsdns.action.Action) int

Lifecycle method for Rdata-based actions.

letsdns.tlsa.record_name(conf: letsdns.configuration.Config, tcp_port: str) str

Return TLSA record name for the configured host name. A single dot ‘.’ host name denotes the domain apex.

Args:

conf: Configuration object. tcp_port: Desired TCP service port, default 25.

letsdns.tlsa.tlsa_records(conf: letsdns.configuration.Config) List[str]

Generate list of TLSA record strings based on the given configuration options.

Args:

conf: Configuration object.

letsdns.util module

letsdns.util.getenv(name: str, default=None, debug_env=True)

Return environment variable value if available, otherwise return the default value.

Args:

name: Environment variable name. default: Default value. debug_env: Debug variable name/value.

letsdns.util.is_sensitive(name: str) bool

Return True if the specified name is considered sensitive.

letsdns.util.is_truthy(something) bool

Test if ‘something’ represents boolean True.

An object represents True if it is (or can be converted to) a string and said string’s first character, converted to lowercase, is one of: 1, t, y.

Args:

something: The object to examine.

letsdns.util.split(source: str) List[str]

Split a string where whitespace or comma occurs. Return empty list for invalid input.

Args:

source: The string to be split.

Module contents

Copyright © 2022 Ralph Seichter

This file is part of LetsDNS.

LetsDNS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

LetsDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with LetsDNS. If not, see <https://www.gnu.org/licenses/>.