Skip to content

Commit

Permalink
Implement validation for checksum-algorithm and checksum-mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
aemous committed Sep 19, 2024
1 parent 14f5fa6 commit d946d3d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion awscli/customizations/s3/subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@
}

CHECKSUM_ALGORITHM = {
'name': 'checksum-algorithm', 'choices': ['CRC32', 'SHA256', 'SHA1', 'CRC64NVME', 'CRC32C'],
'name': 'checksum-algorithm', 'choices': ['CRC32', 'SHA256', 'SHA1', 'CRC32C'],
'help_text': 'Indicates the algorithm used to create the checksum for the object when you use the SDK. '
'This header will not provide any additional functionality if you don’t use the SDK.'
} # TODO truncated some of the doc description from low-level api until i see exactly how this affects things.
Expand Down Expand Up @@ -1286,6 +1286,18 @@ def _validate_path_args(self):
self._validate_same_underlying_s3_paths()
if self._should_emit_validate_s3_paths_warning():
self._emit_validate_s3_paths_warning()
# If we're using the checksum-algorithm flag, the path type must be locals3
if params['checksum_algorithm']:
self._raise_if_paths_type_incorrect_for_param(
CHECKSUM_ALGORITHM['name'],
params['paths_type'],
'locals3')
# If we're using the checksum-mode flag, the path type must be s3local
elif params['checksum_mode']:
self._raise_if_paths_type_incorrect_for_param(
CHECKSUM_MODE['name'],
params['paths_type'],
's3local')

# If the user provided local path does not exist, hard fail because
# we know that we will not be able to upload the file.
Expand Down Expand Up @@ -1370,6 +1382,19 @@ def _raise_if_mv_same_paths(self, src, dest):
f"{self.parameters['src']} - {self.parameters['dest']}"
)

def _raise_if_paths_type_incorrect_for_param(self, param, paths_type, expected_paths_type):
if paths_type != expected_paths_type:
expected_usage_map = {
'locals3': '<LocalPath> <S3Uri>',
's3s3': '<S3Uri> <S3Uri>',
's3local': '<S3Uri> <LocalPath>',
's3': '<S3Uri>'
}
raise ParamValidationError(
"The %s flag is only compatible with the format: %s. You used the format: %s." %
(param, expected_usage_map[expected_paths_type], expected_usage_map[paths_type])
)

def _normalize_s3_trailing_slash(self, paths):
for i, path in enumerate(paths):
if path.startswith('s3://'):
Expand Down

0 comments on commit d946d3d

Please sign in to comment.