ACME client that automates the process of obtaining, installing, and renewing SSL/TLS certificates from Let's Encrypt certificate authority.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Core functionality for running Certbot and managing configuration, including the main CLI entry point, configuration handling, and argument processing.
The primary function for running Certbot programmatically, providing the same functionality as the command-line interface.
def main(cli_args: Optional[list[str]] = None) -> Optional[Union[str, int]]:
"""
Run Certbot with optional command line arguments.
Args:
cli_args: Command line to Certbot, defaults to sys.argv[1:]
Returns:
Value for sys.exit about the exit status of Certbot (str, int, or None)
"""Usage examples:
from certbot.main import main
# Run certbot for certificate-only mode
result = main(['certonly', '--standalone', '-d', 'example.com'])
# Run with webroot authenticator
result = main(['certonly', '--webroot', '-w', '/var/www/html', '-d', 'example.com'])
# Run with manual authenticator
result = main(['certonly', '--manual', '-d', 'example.com'])
# Renew certificates
result = main(['renew'])
# Use default command line arguments (sys.argv[1:])
result = main()Configuration wrapper that handles command-line arguments, configuration files, and runtime settings.
class NamespaceConfig:
"""
Configuration wrapper around argparse.Namespace.
Provides dynamic resolution of paths and configuration validation.
"""
def __init__(self, namespace: argparse.Namespace):
"""
Initialize configuration with namespace.
Args:
namespace: Namespace typically produced by ArgumentParser.parse_args()
"""
def set_argument_sources(self, argument_sources: dict[str, ArgumentSource]):
"""
Associate the NamespaceConfig with a dictionary describing where each
argument came from for runtime evaluation.
Args:
argument_sources: Dictionary mapping argument names to their sources
"""
def set_by_user(self, name: str) -> bool:
"""
Check if an argument was explicitly set by the user.
Args:
name: Name of the argument to check
Returns:
True if set by user, False if using default value
"""Enumeration for tracking where configuration arguments originated.
class ArgumentSource(enum.Enum):
"""Enum for describing where a configuration argument was set."""
COMMAND_LINE = enum.auto() # Argument specified on command line
CONFIG_FILE = enum.auto() # Argument specified in .ini config file
DEFAULT = enum.auto() # Argument was not set, using default value
ENV_VAR = enum.auto() # Argument specified in environment variable
RUNTIME = enum.auto() # Argument was set at runtime by certbotUsage example:
from certbot import configuration
import argparse
# Create namespace with configuration
namespace = argparse.Namespace()
namespace.config_dir = '/etc/letsencrypt'
namespace.work_dir = '/var/lib/letsencrypt'
namespace.logs_dir = '/var/log/letsencrypt'
# Create configuration wrapper
config = configuration.NamespaceConfig(namespace)
# Set argument sources for tracking
sources = {
'config_dir': configuration.ArgumentSource.CONFIG_FILE,
'work_dir': configuration.ArgumentSource.DEFAULT,
'logs_dir': configuration.ArgumentSource.COMMAND_LINE
}
config.set_argument_sources(sources)
# Check if argument was set by user
if config.set_by_user('config_dir'):
print("Config directory was explicitly set")The NamespaceConfig class provides access to various configuration paths and settings:
# Dynamically resolved using work_dir and relative paths:
config.accounts_dir # Account storage directory
config.in_progress_dir # Temporary operations directory
config.temp_checkpoint_dir # Temporary checkpoint directory
# Dynamically resolved using config_dir and relative paths:
config.default_archive_dir # Certificate archive directory
config.live_dir # Live certificate directory
config.renewal_configs_dir # Renewal configuration directory
# Directly configured paths:
config.config_dir # Main configuration directory
config.work_dir # Working directory for temporary files
config.logs_dir # Log files directoryconfig.email # Contact email address
config.agree_tos # Agree to terms of service
config.non_interactive # Run without user interaction
config.staging # Use staging ACME server
config.dry_run # Perform a test run without changes
config.force_renewal # Force certificate renewalInstall with Tessl CLI
npx tessl i tessl/pypi-certbot