Skip to content

Commit ecfe731

Browse files
authored
Update debug-migration function changes to be backwards-compatible. (#9916)
1 parent 6c7c7df commit ecfe731

File tree

6 files changed

+26
-16
lines changed

6 files changed

+26
-16
lines changed

awscli/customizations/globalargs.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def resolve_cli_connect_timeout(parsed_args, session, **kwargs):
9898
arg_name = 'connect_timeout'
9999
_resolve_timeout(session, parsed_args, arg_name)
100100

101-
def detect_migration_breakage(parsed_args, remaining_args, session, **kwargs):
101+
def detect_migration_breakage(parsed_args, session, remaining_args, **kwargs):
102102
if not resolve_v2_debug_mode(parsed_args):
103103
return
104104
region = parsed_args.region or session.get_config_variable('region')
@@ -174,7 +174,11 @@ def detect_migration_breakage(parsed_args, remaining_args, session, **kwargs):
174174
'#cliv2-migration-profile-plugins.\n',
175175
out_file=sys.stderr
176176
)
177-
if parsed_args.command == 'ecr' and remaining_args[0] == 'get-login':
177+
if (
178+
parsed_args.command == 'ecr' and
179+
remaining_args is not None and
180+
remaining_args[0] == 'get-login'
181+
):
178182
uni_print(
179183
'\nAWS CLI v2 UPGRADE WARNING: The `ecr get-login` command has '
180184
'been removed in AWS CLI v2. You must use `ecr get-login-password` '
@@ -189,6 +193,7 @@ def detect_migration_breakage(parsed_args, remaining_args, session, **kwargs):
189193
working_param = working_split[2]
190194
if (
191195
parsed_args.command == working_service
196+
and remaining_args is not None
192197
and remaining_args[0] == working_cmd
193198
and f"--{working_param}" in remaining_args
194199
):

awscli/customizations/scalarparse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def iso_format(value):
4949
return parse_timestamp(value).isoformat()
5050

5151

52-
def add_timestamp_parser(session, v2_debug):
52+
def add_timestamp_parser(session, v2_debug=False):
5353
factory = session.get_component('response_parser_factory')
5454
print_v2_debug_warnings = v2_debug
5555
try:
@@ -112,7 +112,7 @@ def identity_with_warning(x):
112112
factory.set_parser_defaults(timestamp_parser=timestamp_parser)
113113

114114

115-
def add_scalar_parsers(session, parsed_args, **kwargs):
115+
def add_scalar_parsers(session, parsed_args=None, **kwargs):
116116
factory = session.get_component('response_parser_factory')
117117
factory.set_parser_defaults(blob_parser=identity)
118118
add_timestamp_parser(session, resolve_v2_debug_mode(parsed_args))

awscli/paramfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def __init__(self, prefixes=None):
169169
prefixes.update(REMOTE_PREFIX_MAP)
170170
self._prefixes = prefixes
171171

172-
def __call__(self, event_name, param, value, parsed_globals, **kwargs):
172+
def __call__(self, event_name, param, value, parsed_globals=None, **kwargs):
173173
"""Handler that supports param values from URIs."""
174174
cli_argument = param
175175
qualified_param_name = '.'.join(event_name.split('.')[1:])

awscli/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def find_service_and_method_in_event_name(event_name):
137137
def resolve_v2_debug_mode(args):
138138
# Resolve whether v2-debug mode is enabled,
139139
# following the correct precedence order.
140+
if args is None:
141+
return False
140142
if getattr(args, 'v2_debug', False):
141143
return True
142144
if os.environ.get('AWS_CLI_UPGRADE_DEBUG_MODE', '').lower() == 'true':
@@ -215,12 +217,12 @@ def ignore_ctrl_c():
215217
signal.signal(signal.SIGINT, original)
216218

217219

218-
def emit_top_level_args_parsed_event(session, args, remaining):
220+
def emit_top_level_args_parsed_event(session, args, remaining=None):
219221
session.emit(
220222
'top-level-args-parsed',
221223
parsed_args=args,
224+
session=session,
222225
remaining_args=remaining,
223-
session=session
224226
)
225227

226228

tests/unit/customizations/test_globalargs.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ def test_register_feature_id(self):
193193
session = get_session()
194194
globalargs.detect_migration_breakage(
195195
parsed_args,
196+
session,
196197
[],
197-
session
198198
)
199199
# Verify the correct feature ID is registered during the
200200
# provide-client-params event.
@@ -216,8 +216,8 @@ def test_ecr_login_v2_debug(self):
216216
with capture_output() as output:
217217
globalargs.detect_migration_breakage(
218218
parsed_args,
219+
session,
219220
remaining_args,
220-
session
221221
)
222222
# Verify the expected warning is printed
223223
self.assertIn(
@@ -235,8 +235,8 @@ def test_ecr_login_v2_debug_env_var(self):
235235
with mock.patch('os.environ', env):
236236
globalargs.detect_migration_breakage(
237237
parsed_args,
238+
session,
238239
remaining_args,
239-
session
240240
)
241241
# Verify the expected warning is printed
242242
self.assertIn(
@@ -251,7 +251,7 @@ def test_v2_debug_python_utf8_env_var(self):
251251
environ = {'PYTHONUTF8': '1'}
252252
with mock.patch('os.environ', environ):
253253
with capture_output() as output:
254-
globalargs.detect_migration_breakage(parsed_args, [], session)
254+
globalargs.detect_migration_breakage(parsed_args, session, [])
255255
self.assertIn(
256256
'The AWS CLI v2 does not support The `PYTHONUTF8` and '
257257
'`PYTHONIOENCODING` environment variables, and instead '
@@ -265,7 +265,7 @@ def test_v2_debug_python_utf8_resolved_env_var(self):
265265
environ = {'PYTHONUTF8': '1', 'AWS_CLI_FILE_ENCODING': 'UTF-8'}
266266
with mock.patch('os.environ', environ):
267267
with capture_output() as output:
268-
globalargs.detect_migration_breakage(parsed_args, [], session)
268+
globalargs.detect_migration_breakage(parsed_args, session, [])
269269
self.assertNotIn(
270270
'AWS CLI v2 UPGRADE WARNING: The PYTHONUTF8 and '
271271
'PYTHONIOENCODING environment variables are unsupported '
@@ -279,7 +279,7 @@ def test_v2_debug_python_io_encoding_env_var(self):
279279
environ = {'PYTHONIOENCODING': 'UTF8'}
280280
with mock.patch('os.environ', environ):
281281
with capture_output() as output:
282-
globalargs.detect_migration_breakage(parsed_args, [], session)
282+
globalargs.detect_migration_breakage(parsed_args, session, [])
283283
self.assertIn(
284284
'The AWS CLI v2 does not support The `PYTHONUTF8` and '
285285
'`PYTHONIOENCODING` environment variables, and instead '
@@ -290,7 +290,7 @@ def test_v2_debug_python_io_encoding_env_var(self):
290290
def test_v2_debug_s3_sigv2(self):
291291
parsed_args = FakeParsedArgs(v2_debug=True)
292292
session = get_session()
293-
globalargs.detect_migration_breakage(parsed_args, [], session)
293+
globalargs.detect_migration_breakage(parsed_args, session, [])
294294
with capture_output() as output:
295295
session.emit(
296296
'choose-signer.s3.*',
@@ -308,7 +308,7 @@ def test_v2_debug_s3_sigv2(self):
308308
def test_v2_debug_s3_us_east_1(self):
309309
parsed_args = FakeParsedArgs(v2_debug=True, region='us-east-1')
310310
session = get_session()
311-
globalargs.detect_migration_breakage(parsed_args, [], session)
311+
globalargs.detect_migration_breakage(parsed_args, session, [])
312312
def mock_get(key: str):
313313
if key == 'retries':
314314
return {'invocation-id': '012345'}
@@ -335,7 +335,7 @@ def mock_get(key: str):
335335
def test_v2_debug_s3api_us_east_1(self):
336336
parsed_args = FakeParsedArgs(v2_debug=True, region='us-east-1')
337337
session = get_session()
338-
globalargs.detect_migration_breakage(parsed_args, [], session)
338+
globalargs.detect_migration_breakage(parsed_args, session, [])
339339

340340
def mock_get(key: str):
341341
if key == 'retries':

tests/unit/test_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ def test_env_var_non_true_value(self):
155155
with mock.patch.dict(os.environ, {'AWS_CLI_UPGRADE_DEBUG_MODE': 'false'}):
156156
self.assertFalse(resolve_v2_debug_mode(args))
157157

158+
def test_args_none(self):
159+
self.assertFalse(resolve_v2_debug_mode(None))
160+
158161

159162
class MockProcess(object):
160163
@property

0 commit comments

Comments
 (0)