Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions awscli/customizations/s3/subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@
}

CHECKSUM_ALGORITHM = {
'name': 'checksum-algorithm', 'choices': ['CRC64NVME', 'CRC32', 'SHA256', 'SHA1', 'CRC32C', 'SHA512', 'XXHASH64', 'XXHASH3', 'XXHASH128'],
'name': 'checksum-algorithm', 'choices': ['CRC64NVME', 'CRC32', 'SHA256', 'SHA1', 'CRC32C', 'SHA512', 'XXHASH64', 'XXHASH3', 'XXHASH128', 'MD5'],
'help_text': 'Indicates the algorithm used to create the checksum for the object.'
}

Expand Down Expand Up @@ -795,6 +795,15 @@ def _run_main(self, parsed_args, parsed_globals):

class S3TransferCommand(S3Command):
def _run_main(self, parsed_args, parsed_globals):
s3_config = self._session.get_scoped_config().get('s3', {})
if not isinstance(s3_config, dict):
raise transferconfig.InvalidConfigError(
"Invalid value for 's3' in your AWS config file. "
"The s3 section must use indented sub-keys, not a plain "
"string value. For example:\n\n"
"s3 =\n"
" max_concurrent_requests = 10\n"
)
super(S3TransferCommand, self)._run_main(parsed_args, parsed_globals)
self._convert_path_args(parsed_args)
params = self._build_call_parameters(parsed_args, {})
Expand All @@ -810,7 +819,7 @@ def _run_main(self, parsed_args, parsed_globals):
cmd_params.add_v2_debug(parsed_globals)

runtime_config = transferconfig.RuntimeConfig().build_config(
**self._session.get_scoped_config().get('s3', {}))
**s3_config)
cmd = CommandArchitecture(self._session, self.NAME,
cmd_params.parameters,
runtime_config)
Expand Down
24 changes: 23 additions & 1 deletion tests/unit/customizations/s3/test_subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from awscli.customizations.s3.subcommands import CommandParameters, \
CommandArchitecture, CpCommand, SyncCommand, ListCommand, \
RbCommand, get_client
from awscli.customizations.s3.transferconfig import RuntimeConfig
from awscli.customizations.s3.transferconfig import RuntimeConfig, InvalidConfigError
from awscli.customizations.s3.syncstrategy.base import \
SizeAndLastModifiedSync, NeverSync, MissingFileSync
from awscli.testutils import mock, unittest, BaseAWSHelpOutputTest, \
Expand Down Expand Up @@ -80,6 +80,20 @@ def test_rb_command_with_force_requires_strict_path(self):
parsed_globals=self.parsed_globals)


class TestS3ConfigValidation(unittest.TestCase):
def setUp(self):
self.session = mock.Mock()
self.parsed_args = mock.Mock()
self.parsed_globals = mock.Mock()

def test_plain_string_s3_config_raises_invalid_config_error(self):
self.session.get_scoped_config.return_value = {'s3': ''}
cp_command = CpCommand(self.session)
with self.assertRaises(InvalidConfigError) as ctx:
cp_command._run_main(self.parsed_args, self.parsed_globals)
self.assertIn('nested section', str(ctx.exception))


class TestLSCommand(unittest.TestCase):
def setUp(self):
self.session = mock.Mock()
Expand Down Expand Up @@ -753,6 +767,14 @@ def test_validate_checksum_algorithm_download_error(self):
cmd_params.add_paths(paths)
self.assertIn('Expected checksum-algorithm parameter to be used with one of following path formats', cm.msg)

def test_validate_checksum_algorithm_md5_upload(self):
paths = [self.file_creator.rootdir, 's3://bucket/key']
parameters = {'checksum_algorithm': 'MD5'}
cmd_params = CommandParameters('cp', parameters, '')
cmd_params.add_paths(paths)
self.assertEqual(cmd_params.parameters['checksum_algorithm'], 'MD5')


def test_validate_checksum_algorithm_sync_download_error(self):
paths = ['s3://bucket/key', self.file_creator.rootdir]
parameters = {'checksum_algorithm': 'CRC32C'}
Expand Down