Skip to content

Commit 1fee97f

Browse files
authored
Merge pull request #9703 from aemous/debug-migration
2 parents 7465a39 + 8c1be9f commit 1fee97f

File tree

12 files changed

+59
-9
lines changed

12 files changed

+59
-9
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "enhancement",
3+
"category": "Migration",
4+
"description": "Implement a ``--migrate-v2`` flag that detects breaking changes for AWS CLI v2 for entered commands."
5+
}

awscli/alias.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def __call__(self, args, parsed_globals):
183183
parsed_alias_args, remaining = self._parser.parse_known_args(
184184
alias_args
185185
)
186-
self._update_parsed_globals(parsed_alias_args, parsed_globals)
186+
self._update_parsed_globals(parsed_alias_args, parsed_globals, remaining)
187187
# Take any of the remaining arguments that were not parsed out and
188188
# prepend them to the remaining args provided to the alias.
189189
remaining.extend(args)
@@ -228,7 +228,7 @@ def _get_alias_args(self):
228228
)
229229
return alias_args
230230

231-
def _update_parsed_globals(self, parsed_alias_args, parsed_globals):
231+
def _update_parsed_globals(self, parsed_alias_args, parsed_globals, remaining):
232232
global_params_to_update = self._get_global_parameters_to_update(
233233
parsed_alias_args
234234
)
@@ -237,7 +237,7 @@ def _update_parsed_globals(self, parsed_alias_args, parsed_globals):
237237
# global parameters provided in the alias before updating
238238
# the original provided global parameter values
239239
# and passing those onto subsequent commands.
240-
emit_top_level_args_parsed_event(self._session, parsed_alias_args)
240+
emit_top_level_args_parsed_event(self._session, parsed_alias_args, remaining)
241241
for param_name in global_params_to_update:
242242
updated_param_value = getattr(parsed_alias_args, param_name)
243243
setattr(parsed_globals, param_name, updated_param_value)

awscli/clidriver.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ def main():
7979
def create_clidriver():
8080
session = botocore.session.Session(EnvironmentVariables)
8181
_set_user_agent_for_session(session)
82+
# TODO check if full config plugins is empty or not. if it's not, we signal the warning for plugin support being provisional
83+
# similarly, we check for api_versions config value here.
8284
load_plugins(
8385
session.full_config.get('plugins', {}),
8486
event_hooks=session.get_component('event_emitter'),
@@ -225,7 +227,7 @@ def main(self, args=None):
225227
# that exceptions can be raised, which should have the same
226228
# general exception handling logic as calling into the
227229
# command table. This is why it's in the try/except clause.
228-
self._handle_top_level_args(parsed_args)
230+
self._handle_top_level_args(parsed_args, remaining)
229231
self._emit_session_event(parsed_args)
230232
HISTORY_RECORDER.record(
231233
'CLI_VERSION', self.session.user_agent(), 'CLI'
@@ -279,8 +281,8 @@ def _show_error(self, msg):
279281
sys.stderr.write(msg)
280282
sys.stderr.write('\n')
281283

282-
def _handle_top_level_args(self, args):
283-
emit_top_level_args_parsed_event(self.session, args)
284+
def _handle_top_level_args(self, args, remaining):
285+
emit_top_level_args_parsed_event(self.session, args, remaining)
284286
if args.profile:
285287
self.session.set_config_variable('profile', args.profile)
286288
if args.region:

awscli/customizations/cloudformation/deploy.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ def deploy(self, deployer, stack_name, template_str,
339339
tags=tags
340340
)
341341
except exceptions.ChangeEmptyError as ex:
342+
# TODO print the runtime check for cli v2 breakage. technically won't be breaking if --fail-on-empty-changeset is
343+
# explicitly provided. but we cannot differentiate between whether fail-on-empty-changeset is true because it's default
344+
# or because it's explicitly specified.
342345
if fail_on_empty_changeset:
343346
raise
344347
write_exception(ex, outfile=get_stdout_text_writer())

awscli/customizations/globalargs.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# language governing permissions and limitations under the License.
1313
import sys
1414
import os
15+
16+
from awscli.customizations.argrename import HIDDEN_ALIASES
17+
from awscli.customizations.utils import uni_print
1518
from botocore.client import Config
1619
from botocore import UNSIGNED
1720
from botocore.endpoint import DEFAULT_TIMEOUT
@@ -30,6 +33,8 @@ def register_parse_global_args(cli):
3033
unique_id='resolve-cli-read-timeout')
3134
cli.register('top-level-args-parsed', resolve_cli_connect_timeout,
3235
unique_id='resolve-cli-connect-timeout')
36+
cli.register('top-level-args-parsed', detect_migration_breakage,
37+
unique_id='detect-migration-breakage')
3338

3439

3540
def resolve_types(parsed_args, **kwargs):
@@ -90,6 +95,20 @@ def resolve_cli_connect_timeout(parsed_args, session, **kwargs):
9095
arg_name = 'connect_timeout'
9196
_resolve_timeout(session, parsed_args, arg_name)
9297

98+
def detect_migration_breakage(parsed_args, remaining_args, session, **kwargs):
99+
if parsed_args.v2_debug:
100+
url_params = [param for param in remaining_args if param.startswith('http://') or param.startswith('https://')]
101+
if parsed_args.command == 'ecr' and remaining_args[0] == 'get-login':
102+
uni_print('AWS CLI v2 MIGRATION WARNING: The ecr get-login command has been removed in AWS CLI v2. See https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration-changes.html#cliv2-migration-ecr-get-login.\n')
103+
if url_params and session.full_config.get('cli_follow_urlparam', True):
104+
uni_print('AWS CLI v2 MIGRATION WARNING: For input parameters that have a prefix of http:// or https://, AWS CLI v2 will no longer automatically request the content of the URL for the parameter, and the cli_follow_urlparam option has been removed. See https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration-changes.html#cliv2-migration-paramfile.\n')
105+
for working, obsolete in HIDDEN_ALIASES.items():
106+
working_split = working.split('.')
107+
working_service = working_split[0]
108+
working_cmd = working_split[1]
109+
working_param = working_split[2]
110+
if parsed_args.command == working_service and remaining_args[0] == working_cmd and f"--{working_param}" in remaining_args:
111+
uni_print('AWS CLI v2 MIGRATION WARNING: You have entered command arguments that uses at least 1 of 21 hidden aliases that were removed in AWS CLI v2. See https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration-changes.html#cliv2-migration-aliases.\n')
93112

94113
def resolve_cli_read_timeout(parsed_args, session, **kwargs):
95114
arg_name = 'read_timeout'

awscli/customizations/scalarparse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def add_timestamp_parser(session):
6464
# parser (which parses to a datetime.datetime object) with the
6565
# identity function which prints the date exactly the same as it comes
6666
# across the wire.
67+
# TODO create an inner function that wraps identity here. it'll signal to print the runtime check.
6768
timestamp_parser = identity
6869
elif timestamp_format == 'iso8601':
6970
timestamp_parser = iso_format

awscli/data/cli.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@
6464
"dest": "connect_timeout",
6565
"type": "int",
6666
"help": "<p>The maximum socket connect time in seconds. If the value is set to 0, the socket connect will be blocking and not timeout. The default value is 60 seconds.</p>"
67+
},
68+
"v2-debug": {
69+
"action": "store_true",
70+
"dest": "v2_debug",
71+
"help": "<p>Enable AWS CLI v2 migration assistance. Prints warnings if the command would face a breaking change after swapping AWS CLI v1 for AWS CLI v2 in the current environment. Prints one warning for each breaking change detected.</p>"
6772
}
6873
}
6974
}

awscli/examples/global_options.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,7 @@
7070

7171
The maximum socket connect time in seconds. If the value is set to 0, the socket connect will be blocking and not timeout. The default value is 60 seconds.
7272

73+
``--v2-debug`` (boolean)
74+
75+
Enable AWS CLI v2 migration assistance. Prints warnings if the command would face a breaking change after swapping AWS CLI v1 for AWS CLI v2 in the current environment. Prints one warning for each breaking change detected.
76+

awscli/examples/global_synopsis.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
[--ca-bundle <value>]
1313
[--cli-read-timeout <value>]
1414
[--cli-connect-timeout <value>]
15+
[--v2-debug]

awscli/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,13 @@ def ignore_ctrl_c():
205205
signal.signal(signal.SIGINT, original)
206206

207207

208-
def emit_top_level_args_parsed_event(session, args):
209-
session.emit('top-level-args-parsed', parsed_args=args, session=session)
208+
def emit_top_level_args_parsed_event(session, args, remaining):
209+
session.emit(
210+
'top-level-args-parsed',
211+
parsed_args=args,
212+
remaining_args=remaining,
213+
session=session
214+
)
210215

211216

212217
def is_a_tty():

0 commit comments

Comments
 (0)