aws_encryption_sdk_cli.internal.io_handling

Helper functions for handling all input and output for this CLI.

Functions

output_filename(source_filename, ...)

Duplicates the source filename in the destination directory, adding or stripping a suffix as needed.

Classes

IOHandler(metadata_writer, interactive, ...)

Common handler for all IO operations.

class aws_encryption_sdk_cli.internal.io_handling.IOHandler(metadata_writer: MetadataWriter, interactive: bool, no_overwrite: bool, decode_input: bool, encode_output: bool, required_encryption_context: Dict[str, str], required_encryption_context_keys: List[str], commitment_policy: CommitmentPolicy, buffer_output, max_encrypted_data_keys: Union[None, int])

Bases: object

Common handler for all IO operations. Holds common configuration values used for all operations.

Parameters
  • metadata_writer (aws_encryption_sdk_cli.internal.metadata.MetadataWriter) – File-like to which metadata should be written

  • interactive (bool) – Should prompt before overwriting existing files

  • no_overwrite (bool) – Should never overwrite existing files

  • decode_input (bool) – Should input be base64 decoded before operation

  • encode_output (bool) – Should output be base64 encoded after operation

  • buffer_output (bool) – Should buffer entire output before releasing to destination

  • required_encryption_context (dict) – Encryption context key-value pairs to require

  • required_encryption_context_keys (list) – Encryption context keys to require

Workaround pending resolution of attrs/mypy interaction. https://github.com/python/mypy/issues/2088 https://github.com/python-attrs/attrs/issues/215

process_single_operation(stream_args: Dict[str, Union[CryptoMaterialsManager, str, Dict[str, str], AlgorithmSuite, int]], source: Union[str, bytes, IO], destination: str) OperationResult

Processes a single encrypt/decrypt operation given a pre-loaded source.

Parameters
  • stream_args (dict) – kwargs to pass to aws_encryption_sdk.stream

  • source (str or file-like object) – source to write

  • destination (str) – destination identifier

Returns

OperationResult stating whether the file was written

Return type

aws_encryption_sdk_cli.internal.identifiers.OperationResult

process_single_file(stream_args: Dict[str, Union[CryptoMaterialsManager, str, Dict[str, str], AlgorithmSuite, int]], source: str, destination: str) None

Processes a single encrypt/decrypt operation on a source file.

Parameters
  • stream_args (dict) – kwargs to pass to aws_encryption_sdk.stream

  • source (str) – Full file path to source file

  • destination (str) – Full file path to destination file

process_dir(stream_args: Dict[str, Union[CryptoMaterialsManager, str, Dict[str, str], AlgorithmSuite, int]], source: str, destination: str, suffix: str) None

Processes encrypt/decrypt operations on all files in a directory tree.

Parameters
  • stream_args (dict) – kwargs to pass to aws_encryption_sdk.stream

  • source (str) – Full file path to source directory root

  • destination (str) – Full file path to destination directory root

  • suffix (str) – Suffix to append to output filename

aws_encryption_sdk_cli.internal.io_handling.output_filename(source_filename: str, destination_dir: str, mode: str, suffix: str) str

Duplicates the source filename in the destination directory, adding or stripping a suffix as needed.

Parameters
  • source_filename (str) – Full file path to source file

  • destination_dir (str) – Full file path to destination directory

  • mode (str) – Operating mode (encrypt/decrypt)

  • suffix (str) – Suffix to append to output filename

Returns

Full file path of new destination file in destination directory

Return type

str