4848 ServiceHelpCommand ,
4949)
5050from awscli .plugin import load_plugins
51- from awscli .utils import emit_top_level_args_parsed_event , write_exception , create_nested_client
51+ from awscli .utils import emit_top_level_args_parsed_event , write_exception , create_nested_client , resolve_v2_debug_mode
5252from botocore import __version__ as botocore_version
5353from botocore import xform_name
5454
@@ -225,7 +225,7 @@ def main(self, args=None):
225225 # that exceptions can be raised, which should have the same
226226 # general exception handling logic as calling into the
227227 # command table. This is why it's in the try/except clause.
228- self ._handle_top_level_args (parsed_args )
228+ self ._handle_top_level_args (parsed_args , remaining )
229229 self ._emit_session_event (parsed_args )
230230 HISTORY_RECORDER .record (
231231 'CLI_VERSION' , self .session .user_agent (), 'CLI'
@@ -279,8 +279,8 @@ def _show_error(self, msg):
279279 sys .stderr .write (msg )
280280 sys .stderr .write ('\n ' )
281281
282- def _handle_top_level_args (self , args ):
283- emit_top_level_args_parsed_event (self .session , args )
282+ def _handle_top_level_args (self , args , remaining ):
283+ emit_top_level_args_parsed_event (self .session , args , remaining )
284284 if args .profile :
285285 self .session .set_config_variable ('profile' , args .profile )
286286 if args .region :
@@ -542,9 +542,15 @@ def __call__(self, args, parsed_globals):
542542 event , parsed_args = parsed_args , parsed_globals = parsed_globals
543543 )
544544 call_parameters = self ._build_call_parameters (
545- parsed_args , self .arg_table
545+ parsed_args , self .arg_table , parsed_globals
546546 )
547547
548+ self ._detect_binary_file_migration_change (
549+ self ._session ,
550+ parsed_args ,
551+ parsed_globals ,
552+ self .arg_table
553+ )
548554 event = f'calling-command.{ self ._parent_name } .{ self ._name } '
549555 override = self ._emit_first_non_none_response (
550556 event ,
@@ -590,7 +596,7 @@ def _add_help(self, parser):
590596 # CLIArguments for values.
591597 parser .add_argument ('help' , nargs = '?' )
592598
593- def _build_call_parameters (self , args , arg_table ):
599+ def _build_call_parameters (self , args , arg_table , parsed_globals ):
594600 # We need to convert the args specified on the command
595601 # line as valid **kwargs we can hand to botocore.
596602 service_params = {}
@@ -601,19 +607,19 @@ def _build_call_parameters(self, args, arg_table):
601607 py_name = arg_object .py_name
602608 if py_name in parsed_args :
603609 value = parsed_args [py_name ]
604- value = self ._unpack_arg (arg_object , value )
610+ value = self ._unpack_arg (arg_object , value , parsed_globals )
605611 arg_object .add_to_params (service_params , value )
606612 return service_params
607613
608- def _unpack_arg (self , cli_argument , value ):
614+ def _unpack_arg (self , cli_argument , value , parsed_globals ):
609615 # Unpacks a commandline argument into a Python value by firing the
610616 # load-cli-arg.service-name.operation-name event.
611617 session = self ._session
612618 service_name = self ._operation_model .service_model .endpoint_prefix
613619 operation_name = xform_name (self ._name , '-' )
614620
615621 return unpack_argument (
616- session , service_name , operation_name , cli_argument , value
622+ session , service_name , operation_name , cli_argument , value , parsed_globals
617623 )
618624
619625 def _create_argument_table (self ):
@@ -661,6 +667,46 @@ def _create_operation_parser(self, arg_table):
661667 parser = ArgTableArgParser (arg_table )
662668 return parser
663669
670+ def _detect_binary_file_migration_change (
671+ self ,
672+ session ,
673+ parsed_args ,
674+ parsed_globals ,
675+ arg_table
676+ ):
677+ if (
678+ session .get_scoped_config ()
679+ .get ('cli_binary_format' , None ) == 'raw-in-base64-out'
680+ ):
681+ # if cli_binary_format is set to raw-in-base64-out, then v2 behavior will
682+ # be the same as v1, so there is no breaking change in this case.
683+ return
684+ if resolve_v2_debug_mode (parsed_globals ):
685+ parsed_args_to_check = {
686+ arg : getattr (parsed_args , arg )
687+ for arg in vars (parsed_args ) if getattr (parsed_args , arg )
688+ }
689+
690+ arg_values_to_check = [
691+ arg .py_name for arg in arg_table .values ()
692+ if arg .py_name in parsed_args_to_check
693+ and arg .argument_model .type_name == 'blob'
694+ ]
695+ if arg_values_to_check :
696+ print (
697+ '\n AWS CLI v2 UPGRADE WARNING: When specifying a '
698+ 'blob-type parameter, AWS CLI v2 will assume the '
699+ 'parameter value is base64-encoded. This is different '
700+ 'from v1 behavior, where the AWS CLI will automatically '
701+ 'encode the value to base64. To retain v1 behavior in '
702+ 'AWS CLI v2, set the `cli_binary_format` configuration '
703+ 'variable to `raw-in-base64-out`. See '
704+ 'https://docs.aws.amazon.com/cli/latest/userguide/'
705+ 'cliv2-migration-changes.html'
706+ '#cliv2-migration-binaryparam.\n ' ,
707+ file = sys .stderr
708+ )
709+
664710
665711class CLIOperationCaller :
666712 """Call an AWS operation and format the response."""
0 commit comments