airflow.providers.teradata.utils.tpt_util

Classes

TPTConfig

Configuration constants for TPT operations.

Functions

execute_remote_command(ssh_client, command)

Execute a command on remote host and properly manage SSH channels.

write_file(path, content)

secure_delete(file_path[, logger])

Securely delete a file using shred if available, otherwise use os.remove.

remote_secure_delete(ssh_client, remote_files[, logger])

Securely delete remote files via SSH. Attempts shred first, falls back to rm if shred is unavailable.

terminate_subprocess(sp[, logger])

Terminate a subprocess gracefully with proper error handling.

get_remote_os(ssh_client[, logger])

Detect the operating system of the remote host via SSH.

set_local_file_permissions(local_file_path[, logger])

Set permissions for a local file to be read-only for the owner.

set_remote_file_permissions(ssh_client, remote_file_path)

Set permissions for a remote file to be read-only for the owner.

get_remote_temp_directory(ssh_client[, logger])

Get the remote temporary directory path based on the operating system.

verify_tpt_utility_installed(utility)

Verify if a TPT utility (e.g., tbuild) is installed and available in the system's PATH.

verify_tpt_utility_on_remote_host(ssh_client, utility)

Verify if a TPT utility (tbuild) is installed on the remote host via SSH.

prepare_tpt_ddl_script(sql, error_list, source_conn[, ...])

Prepare a TPT script for executing DDL statements.

decrypt_remote_file(ssh_client, remote_enc_file, ...)

Decrypt a remote file using OpenSSL.

transfer_file_sftp(ssh_client, local_path, remote_path)

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.

DEFAULT_TIMEOUT = 5[source]
FILE_PERMISSIONS_READ_ONLY = 256[source]
TEMP_DIR_WINDOWS = 'C:\\Windows\\Temp'[source]
TEMP_DIR_UNIX = '/tmp'[source]
airflow.providers.teradata.utils.tpt_util.execute_remote_command(ssh_client, command)[source]

Execute a command on remote host and properly manage SSH channels.

Parameters:
  • ssh_client (paramiko.SSHClient) – SSH client connection

  • command (str) – Command to execute

Returns:

Tuple of (exit_status, stdout, stderr)

Return type:

tuple[int, str, str]

airflow.providers.teradata.utils.tpt_util.write_file(path, content)[source]
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:
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:

str

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:
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:

str

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:
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:
  • sql (list[str]) – A list of DDL statements to execute.

  • error_list (list[int] | None) – A list of error codes to handle during the operation.

  • source_conn (dict[str, Any]) – Connection details for the source database.

  • job_name (str | None) – The name of the TPT job. Defaults to unique name if None.

Returns:

A formatted TPT script as a string.

Raises:

ValueError – If the SQL statement list is empty.

Return type:

str

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:

int

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:

Was this entry helpful?