certdeploy package

Subpackages

Submodules

certdeploy.errors module

Exceptions to use with both CertDeploy servers and CertDeploy clients.

exception certdeploy.errors.CertDeployError[source]

Bases: Exception

CertDeploy specific error.

exception certdeploy.errors.ConfigError[source]

Bases: CertDeployError

Configuration error.

exception certdeploy.errors.ConfigInvalid(key: str, value: Any, must: str = None, config_desc: str = '')[source]

Bases: ConfigError

Invalid configuration exception.

Parameters:
  • key – The config key.

  • value – The value given in the config.

  • must – If the value must have been something set this to be that thing. Defaults to None.

  • config_desc – The description of the config if needed. Defaults to an empty string.

Example

An example of formatting using must.

ConfigInvalid(

‘renew_unit’, None, must=’not be a weekday if renew_every is set and not’

‘ 1’

) -> (‘Invalid value “None” for renew_unit. renew_unit

‘must not be a weekday if renew_every is set and ‘ ‘not 1.’)

exception certdeploy.errors.ConfigInvalidChoice(key: str, value: Any, choices: list[Any], quote: bool = True, config_desc: str = '')[source]

Bases: ConfigInvalid

Invalid configuration from selection.

Note

choices is a list of two or more choices. An exception is raised from this exception if a list of length one is given. The universe may impload if that happens.

Parameters:
  • key – The config key.

  • value – The value given in the config.

  • must – If the value must have been something set this to be that thing. Defaults to None. See ConfigInvalid for an example.

  • choices – A list of two or more valid values for the config. If there are only two choices they will be listed as ‘either A or B’. If there are three or more choices they will be listed as a comma separated list with and oxford comma and an or for the last choice.

  • quote – If True add double quotes to the choices. Defaults to True.

  • config_desc – The description of the config if needed. Defaults to an empty string.

Raises:

ValueError – When the number of choices is invalid.

exception certdeploy.errors.ConfigInvalidNumber(key: str, value: Any, is_type: str = 'number', optional: bool = False, gt: str = None, lt: str = None, ge: str = None, le: str = None, config_desc: str = '')[source]

Bases: ConfigInvalid

Invalid numeric configuration exception.

Parameters:
  • key – The config key.

  • value – The value given in the config.

  • is_type – The name of the required number type. Defaults to ‘number’.

  • optional – If True ‘if set’ is added to the end of the message. Defaults to False.

  • gt – Changes the phrasing to reflect the config must be ‘greater than’ the value of gt. Defaults to None.

  • lt – Changes the phrasing to reflect the config must be ‘less than’ the value of lt. Defaults to None.

  • ge – Changes the phrasing to reflect the config must be ‘greater than or equal to’ the value of ge. Defaults to None.

  • le – Changes the phrasing to reflect the config must be ‘less than or equal to’ the value of le. Defaults to None.

  • config_desc – The description of the config if needed. Defaults to an empty string.

exception certdeploy.errors.ConfigInvalidPath(key: str, value: str, exist: bool = True, writable: bool = False, bad_format: bool = False, is_type: str = '', config_desc: str = '')[source]

Bases: ConfigInvalid

Invalid file system path configuation exception.

Note

One or more of bad_format, exist, or writable must be True or an exception is raised from this exception . The universe may impload if that happens.

Parameters:
  • key – The config key.

  • value – The value given in the config.

  • exist – If True the path must exist. Defaults to True.

  • writable – If True the path must be writable. Defaults to False.

  • bad_format – If True the format of value is invalid. Defaults to False.

  • is_type – If set the message will be phrased as needing to be the value of is_type. Defaults to an empty string.

  • config_desc – The description of the config if needed. Defaults to an empty string.

Raises:

ValueError – When one or more of bad_format, exist, or writable must be True.

Module contents

Shared CertDeploy code.

class certdeploy.LogLevel(value)[source]

Bases: Enum

Logging levels and utilities.

CRITICAL = 'CRITICAL'
DEBUG = 'DEBUG'
ERROR = 'ERROR'
INFO = 'INFO'
WARNING = 'WARNING'
classmethod cast(level: int | str | LogLevel) LogLevel[source]

Cast level to a LogLevel.

Returns:

A LogLevel corresponding to level.

Raises:

TypeError – When level does not correspond to any LogLevel.

classmethod validate(level: int | str | LogLevel) bool[source]

Verify level is a valid LogLevel or equivalent.

Parameters:

level – A log level.

Returns:

True if level is a log level.

class certdeploy.Logger(name: str)[source]

Bases: object

A logging helper with some modified behavior.

Parameters:

name – The name of the logging.Logger.

error(*args: Any, exc_info=None, **kwargs)[source]

Log an error message.

See logging.error for details. This method differs from logging.error in the following ways:

  • If the first argument is an exception it’s formatted so the type

    is given and not just the message.

  • exc_info is ignored if the log level is anything but DEBUG.

classmethod fromLogger(logger: Logger) Logger[source]

Create a Logger from a logging.Logger.

Parameters:

logger – The source logging.Logger.

Returns:

A new Logger with logger as the wrapped logger.

purgeHandlers()[source]

Purge all handlers from the logger.

setLevel(level: int | str | LogLevel)[source]

Set the logging level for this Logger.

This is a more flexible implementation of logging.Logger.setLevel.

Parameters:

level – The desired log level as either the logging log level, the string log level, or the LogLevel.

certdeploy.format_error(err: Exception, message_format: str = '{name}: {message}') str[source]

Format errors consistently.

Parameters:
  • err – The exception to format.

  • message_format – The format string (.format style) to apply the error to. The keys name and message are passed to the format string. Defaults to ‘{name}: {message}’.

Returns:

A formatted string with the name and message of the given error.

certdeploy.set_log_properties(logger_name: str, log_filename: PathLike, log_level: int | str | LogLevel = None, msg_format: str = '%(levelname)s:%(name)s: %(message)s', date_format: str = '%Y.%m.%d-%H:%M:%S')[source]

Set logger properties.

Parameters:
  • logger_name – The name of the logger.

  • log_filename – The path to the log file.

  • log_level – The desired log level. Defaults to LogLevel.ERROR.

  • msg_format – The format for the each log entry. Defaults to DEFAULT_LOG_FORMAT.

  • date_format – The date format for each log entry. This is only used if the msg_format has the date in it. Defaults to DEFAULT_LOG_DATE_FORMAT.

certdeploy.set_paramiko_log_properties(log_filename: PathLike = None, log_level: int | str | LogLevel = None, msg_format: str = '%(levelname)s:%(name)s: %(message)s', date_format: str = '%Y.%m.%d-%H:%M:%S')[source]

Set the paramiko logger properties.

Parameters:
  • log_filename – The path to the log file.

  • log_level – The desired log level. Defaults to LogLevel.ERROR.

  • msg_format – The format for the each log entry. Defaults to DEFAULT_LOG_FORMAT.

  • date_format – The date format for each log entry. This is only used if the msg_format has the date in it. Defaults to DEFAULT_LOG_DATE_FORMAT.