persistent_ssh_agent package¶
- class persistent_ssh_agent.PersistentSSHAgent(config: SSHConfig | None = None, expiration_time: int = 86400, reuse_agent: bool = True)[source]¶
Bases:
object
Handles persistent SSH agent operations and authentication.
This class manages SSH agent persistence across sessions by saving and restoring agent information. It also handles SSH key management and authentication for various operations including Git.
- SSH_DEFAULT_KEY = 'id_rsa'¶
- SSH_DEFAULT_OPTIONS = {'StrictHostKeyChecking': 'no'}¶
- SSH_KEY_TYPES = ['id_ed25519', 'id_ecdsa', 'id_ecdsa_sk', 'id_ed25519_sk', 'id_rsa', 'id_dsa']¶
- get_git_ssh_command(hostname: str) str | None [source]¶
Generate Git SSH command with proper configuration.
- Parameters:
hostname – Target Git host
- Returns:
SSH command string if successful, None on error
- is_valid_hostname(hostname: str) bool [source]¶
Check if a hostname is valid according to RFC 1123 and supports IPv6.
- Parameters:
hostname – The hostname to validate
- Returns:
True if the hostname is valid, False otherwise
- Return type:
bool
Notes
Maximum length of 255 characters
Can contain letters (a-z), numbers (0-9), dots (.) and hyphens (-)
Cannot start or end with a dot or hyphen
Labels (parts between dots) cannot start or end with a hyphen
Labels cannot be longer than 63 characters
IPv6 addresses are supported (with or without brackets)
- static run_command(command: List[str], shell: bool = False, check_output: bool = True, timeout: int | None = None, env: Dict[str, str] | None = None) CompletedProcess | None [source]¶
Run a command and return its output.
- Parameters:
command – Command and arguments to run
shell – Whether to run command through shell
check_output – Whether to capture command output
timeout – Command timeout in seconds
env – Environment variables for command
- Returns:
CompletedProcess object if successful, None on error
- Return type:
CompletedProcess
- class persistent_ssh_agent.SSHConfig(identity_file: str | None = None, identity_content: str | None = None, identity_passphrase: str | None = None, ssh_options: Dict[str, str] = None)[source]¶
Bases:
object
SSH configuration class.
- identity_content: str | None = None¶
- identity_file: str | None = None¶
- identity_passphrase: str | None = None¶
- ssh_options: Dict[str, str] = None¶