airflow.providers.teradata.utils.tpt_util¶
Classes¶
Configuration constants for TPT operations. |
Functions¶
|
Execute a command on remote host and properly manage SSH channels. |
|
|
|
Securely delete a file using shred if available, otherwise use os.remove. |
|
Securely delete remote files via SSH. Attempts shred first, falls back to rm if shred is unavailable. |
|
Terminate a subprocess gracefully with proper error handling. |
|
Detect the operating system of the remote host via SSH. |
|
Set permissions for a local file to be read-only for the owner. |
|
Set permissions for a remote file to be read-only for the owner. |
|
Get the remote temporary directory path based on the operating system. |
|
Verify if a TPT utility (e.g., tbuild) is installed and available in the system's PATH. |
|
Verify if a TPT utility (tbuild) is installed on the remote host via SSH. |
|
Prepare a TPT script for executing DDL statements. |
|
Decrypt a remote file using OpenSSL. |
|
Transfer a file from local to remote host using SFTP. |
Module Contents¶
- class airflow.providers.teradata.utils.tpt_util.TPTConfig[source]¶
Configuration constants for TPT operations.
- airflow.providers.teradata.utils.tpt_util.execute_remote_command(ssh_client, command)[source]¶
Execute a command on remote host and properly manage SSH channels.
- airflow.providers.teradata.utils.tpt_util.secure_delete(file_path, logger=None)[source]¶
Securely delete a file using shred if available, otherwise use os.remove.
- Parameters:
file_path (str) – Path to the file to be deleted
logger (logging.Logger | None) – Optional logger instance
- airflow.providers.teradata.utils.tpt_util.remote_secure_delete(ssh_client, remote_files, logger=None)[source]¶
Securely delete remote files via SSH. Attempts shred first, falls back to rm if shred is unavailable.
- Parameters:
ssh_client (paramiko.SSHClient) – SSH client connection
remote_files (list[str]) – List of remote file paths to delete
logger (logging.Logger | None) – Optional logger instance
- airflow.providers.teradata.utils.tpt_util.terminate_subprocess(sp, logger=None)[source]¶
Terminate a subprocess gracefully with proper error handling.
- Parameters:
sp (subprocess.Popen | None) – Subprocess to terminate
logger (logging.Logger | None) – Optional logger instance
- airflow.providers.teradata.utils.tpt_util.get_remote_os(ssh_client, logger=None)[source]¶
Detect the operating system of the remote host via SSH.
- Parameters:
ssh_client (paramiko.SSHClient) – SSH client connection
logger (logging.Logger | None) – Optional logger instance
- Returns:
Operating system type as string (‘windows’ or ‘unix’)
- Return type:
- airflow.providers.teradata.utils.tpt_util.set_local_file_permissions(local_file_path, logger=None)[source]¶
Set permissions for a local file to be read-only for the owner.
- Parameters:
local_file_path (str) – Path to the local file
logger (logging.Logger | None) – Optional logger instance
- Raises:
FileNotFoundError – If the file does not exist
OSError – If setting permissions fails
- airflow.providers.teradata.utils.tpt_util.set_remote_file_permissions(ssh_client, remote_file_path, logger=None)[source]¶
Set permissions for a remote file to be read-only for the owner.
- Parameters:
ssh_client (paramiko.SSHClient) – SSH client connection
remote_file_path (str) – Path to the remote file
logger (logging.Logger | None) – Optional logger instance
- Raises:
RuntimeError – If permission setting fails
- airflow.providers.teradata.utils.tpt_util.get_remote_temp_directory(ssh_client, logger=None)[source]¶
Get the remote temporary directory path based on the operating system.
- Parameters:
ssh_client (paramiko.SSHClient) – SSH client connection
logger (logging.Logger | None) – Optional logger instance
- Returns:
Path to the remote temporary directory
- Return type:
- airflow.providers.teradata.utils.tpt_util.verify_tpt_utility_installed(utility)[source]¶
Verify if a TPT utility (e.g., tbuild) is installed and available in the system’s PATH.
- airflow.providers.teradata.utils.tpt_util.verify_tpt_utility_on_remote_host(ssh_client, utility, logger=None)[source]¶
Verify if a TPT utility (tbuild) is installed on the remote host via SSH.
- Parameters:
ssh_client (paramiko.SSHClient) – SSH client connection
utility (str) – Name of the utility to verify
logger (logging.Logger | None) – Optional logger instance
- Raises:
FileNotFoundError – If utility is not found on remote host
RuntimeError – If verification fails unexpectedly
- airflow.providers.teradata.utils.tpt_util.prepare_tpt_ddl_script(sql, error_list, source_conn, job_name=None)[source]¶
Prepare a TPT script for executing DDL statements.
This method generates a TPT script that defines a DDL operator and applies the provided SQL statements. It also supports specifying a list of error codes to handle during the operation.
- Parameters:
- Returns:
A formatted TPT script as a string.
- Raises:
ValueError – If the SQL statement list is empty.
- Return type:
- airflow.providers.teradata.utils.tpt_util.decrypt_remote_file(ssh_client, remote_enc_file, remote_dec_file, password, logger=None)[source]¶
Decrypt a remote file using OpenSSL.
- Parameters:
ssh_client (paramiko.SSHClient) – SSH client connection
remote_enc_file (str) – Path to the encrypted file
remote_dec_file (str) – Path for the decrypted file
password (str) – Decryption password
logger (logging.Logger | None) – Optional logger instance
- Returns:
Exit status of the decryption command
- Raises:
RuntimeError – If decryption fails
- Return type:
- airflow.providers.teradata.utils.tpt_util.transfer_file_sftp(ssh_client, local_path, remote_path, logger=None)[source]¶
Transfer a file from local to remote host using SFTP.
- Parameters:
ssh_client (paramiko.SSHClient) – SSH client connection
local_path (str) – Local file path
remote_path (str) – Remote file path
logger (logging.Logger | None) – Optional logger instance
- Raises:
FileNotFoundError – If local file does not exist
RuntimeError – If file transfer fails