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.
aws_encryption_sdk_cli.internal.io_handling.output_filename(source_filename, destination_dir, mode, suffix)

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

class aws_encryption_sdk_cli.internal.io_handling.IOHandler(metadata_writer, interactive, no_overwrite, decode_input, encode_output, required_encryption_context, required_encryption_context_keys)

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
  • 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, source, destination)

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, source, destination)

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, source, destination, suffix)

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