o .&ai@sddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z ddl mZddl mZddl mZdd lmZdd lmZmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddl#m$Z$ddl#m%Z%ddl#m&Z&ddl'm(Z(ddl'm)Z)ddl'm*Z*ddl'm+Z+ddl'm,Z,ddl-m.Z.ddl/m0Z0ddl/m1Z1ddl2m3Z3dd l2m4Z4e5d!Z6d"Z7eZ8d#9d$d%d&Z:d'd(Z;d)d*ZGd-d.d.eZ?Gd/d0d0e=Z@Gd1d2d2e=ZAdS)3N) __version__)HierarchicalEmitter) xform_name) copy_kwargs OrderedDict)NoCredentialsError) NoRegionError)ProfileNotFound)get_global_history_recorder)EnvironmentVariablesr)get_stderr_text_writer) get_formatter) load_plugins) CLICommand)six) MainArgParser)ServiceArgParserArgTableArgParser)USAGE)ProviderHelpCommand)ServiceHelpCommand)OperationHelpCommand)CustomArgument) ListArgument)BooleanArgument) CLIArgument)UnknownArgumentError)unpack_argument) AliasLoader)AliasCommandInjector) emit_top_level_args_parsed_event)write_exceptionzawscli.clidriverzE%(asctime)s - %(threadName)s - %(name)s - %(levelname)s - %(message)sidnacCs t}|}td|d|S)NCLI_RCCLI)create_clidrivermainHISTORY_RECORDERrecord)driverrcr-2/usr/lib/python3/dist-packages/awscli/clidriver.pyr(Dsr(cCs>tjt}t|t|jdi|ddt |d}|S)Nplugins event_emitter) event_hookssession) botocorer3Sessionr _set_user_agent_for_sessionr full_configget get_component CLIDriver)r3r+r-r-r.r'Ks  r'cCsd|_t|_dt|_dS)Nzaws-cliz botocore/%s)user_agent_nameruser_agent_versionbotocore_versionuser_agent_extrar2r-r-r.r6Tsr6c@seZdZd ddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ d ddZddZddZddZdS)!r:NcCsF|durtjt|_t|jn||_d|_d|_d|_t|_ dSN) r4r3 get_sessionr r6 _cli_data_command_table_argument_tabler alias_loaderselfr3r-r-r.__init__\s  zCLIDriver.__init__cCs|jdur |jd|_|jS)Ncli)rAr3get_datarFr-r-r. _get_cli_datags zCLIDriver._get_cli_datacC|jdur ||_|jSr?)rB_build_command_tablerJr-r-r._get_command_tableo  zCLIDriver._get_command_tablecCrLr?)rC_build_argument_tablerJr-r-r._get_argument_tabletrOzCLIDriver._get_argument_tablecCs&||j}|jjd||j|d|S)z Create the main parser to handle the global arguments. :rtype: ``argparser.ArgumentParser`` :return: The parser object zbuilding-command-table.main command_tabler3command_object)_build_builtin_commandsr3emitrFrSr-r-r.rMys zCLIDriver._build_command_tablecCs0t}|}|D] }t||j|d||<q |S)N)cli_namer3 service_name)rget_available_servicesServiceCommandr3)rFr3commandsservicesrYr-r-r.rUs z!CLIDriver._build_builtin_commandscCs(||}t|j|j}|||dSr?)_create_parserr r3rDinject_aliases)rFrSparserinjectorr-r-r. _add_aliasess zCLIDriver._add_aliasescCsZt}|}|dd}|D]}t||}|||}||q|jjd|d|S)Noptionszbuilding-top-level-params)argument_table)rrKr8r_create_cli_argumentadd_to_arg_tabler3rV)rFrdcli_data cli_argumentsoption option_params cli_argumentr-r-r.rPs    zCLIDriver._build_argument_tablec CsDt||dd|d|d|d|d|d|dd S) Nhelpr#destdefaultactionrequiredchoicestype) help_textrmrnrorprq cli_type_name)rr8)rF option_namerjr-r-r.res zCLIDriver._create_cli_argumentc Cs<|}t|j|||dd|dd|ddS)N descriptionsynopsis help_usage)rKrr3rNrQr8)rFrgr-r-r.create_help_commands    zCLIDriver.create_help_commandcCs<||d<|}t||j|dd|dd}|S)Nrlrvaws)prog)ryrKrr3 user_agentr8rQ)rFrSrgr`r-r-r.r^s   zCLIDriver._create_parserc Cs|dur tjdd}|}||}|||||\}}z$||||t d|j dt d|d||j ||WSt yn}ztjdttjt|tjdWYd}~dSd}~wty}zd |}||WYd}~dSd}~wty}zd |}||WYd}~dSd}~wtytjdd tjYSty}ztjd d dtdt|tdWYd}~dSd}~ww)z :param args: List of arguments, with the 'aws' removed. For example, the command "aws s3 list-objects --bucket foo" will have an args list of ``['s3', 'list-objects', '--bucket', 'foo']``. N CLI_VERSIONr& CLI_ARGUMENTSz usage: %s  zA%s You can also configure your region by running "aws configure".z=%s. You can configure credentials by running "aws configure".zException caught in main()Texc_infozExiting with rc 255)outfile)sysargvrNr^rbparse_known_args_handle_top_level_args_emit_session_eventr)r*r3r|commandrstderrwriterstrr _show_errorrKeyboardInterruptstdoutsignalSIGINT ExceptionLOGdebugr"r )rFargsrSr` parsed_args remainingemsgr-r-r.r(sX           zCLIDriver.maincCs|jjd|j|ddS)Nzsession-initialized)r3r)r3rV)rFrr-r-r.rs zCLIDriver._emit_session_eventcCs*tj|ddtj|tjddS)NTrr)rrrrr)rFrr-r-r.rs zCLIDriver._show_errorcCst|j||jr|jd|j|jr|jd|j|jr]|jjdtjt d|jjdtjt d|jjdtjt d|jjdtjt dt d|j t d t j d ddS|jjdtjd dS) Nprofileregionr4) format_stringawscli s3transferurllib3zCLI version: %szArguments entered to CLI: %sr}) logger_name log_level)r!r3rset_config_variablerrset_stream_loggerloggingDEBUG LOG_FORMATrr|rrERROR)rFrr-r-r.rs.      z CLIDriver._handle_top_level_argsr?)__name__ __module__ __qualname__rGrKrNrQrMrUrbrPreryr^r(rrrr-r-r-r.r:Zs      4 r:c@seZdZdZdddZeddZejddZedd Zed d Z e jd d Z d dZ ddZ ddZ ddZ ddZddZddZdS)r[zA service command for the CLI. For example, ``aws ec2 ...`` we'd create a ServiceCommand object that represents the ec2 service. NcCs:||_||_d|_|dur||_n||_|g|_d|_dSr?)_namer3rB _service_name_lineage_service_model)rFrXr3rYr-r-r.rG)s  zServiceCommand.__init__cC|jSr?rrJr-r-r.name?zServiceCommand.namecC ||_dSr?rrFvaluer-r-r.rC cCs|Sr?)_get_service_modelrJr-r-r. service_modelGszServiceCommand.service_modelcCrr?rrJr-r-r.lineageKrzServiceCommand.lineagecCrr?rrr-r-r.rOrcCrLr?)rB_create_command_tablerJr-r-r.rNSrOz!ServiceCommand._get_command_tablecCsV|jdur(z |jd|jd}Wn tyd}Ynw|jj|j|d|_|jS)N api_versions) api_version)rr3get_config_variabler8rr get_service_model)rFrr-r-r.rXs   z!ServiceCommand._get_service_modelcCs.|}||\}}|}||j||Sr?)r^rrN operation)rFrparsed_globalsservice_parserrrrSr-r-r.__call__cszServiceCommand.__call__cCsxt}|}|jD]}t|d}||}t||j|j|t|jd||<q |jj d|j||j|d| ||S)N-)r parent_namer3operation_modeloperation_callerzbuilding-command-table.%srR) rroperation_namesrrServiceOperationrr3CLIOperationCallerrV _add_lineage)rFrSroperation_namerXrr-r-r.rls&     z$ServiceCommand._create_command_tablecCs$|D] }||}|j|g|_qdSr?r)rFrSr command_objr-r-r.rszServiceCommand._add_lineagecCs,|}t|j||dd|j|jdS)N.)r3objrS arg_table event_classr)rNrr3rjoin lineage_namesrrWr-r-r.rys z"ServiceCommand.create_help_commandcCs"|}||d<t||jdS)Nrl)operations_tablerY)rNryrrrWr-r-r.r^s  zServiceCommand._create_parserr?)rrr__doc__rGpropertyrsetterrrrNrrrrryr^r-r-r-r.r[ s(         r[c@seZdZdZeedZeZddZ e ddZ e j ddZ e dd Z e j d d Z e d d Ze d dZddZddZddZddZddZddZddZddZdd Zd!S)"rzA single operation of a service. This class represents a single operation for a service, for example ``ec2.DescribeInstances``. )listbooleancCs@d|_||_||_||_|g|_||_||_|jrd|_dSdS)aT :type name: str :param name: The name of the operation/subcommand. :type parent_name: str :param parent_name: The name of the parent command. :type operation_model: ``botocore.model.OperationModel`` :param operation_object: The operation model associated with this subcommand. :type operation_caller: ``CLIOperationCaller`` :param operation_caller: An object that can properly call the operation. :type session: ``botocore.session.Session`` :param session: The session object. NT) _arg_tabler _parent_name_operation_callerr_operation_model_session deprecated _UNDOCUMENTED)rFrrrrr3r-r-r.rGs zServiceOperation.__init__cCrr?rrJr-r-r.rrzServiceOperation.namecCrr?rrr-r-r.rrcCrr?rrJr-r-r.rrzServiceOperation.lineagecCrr?rrr-r-r.rrcCsdd|jDS)NcSsg|]}|jqSr-)r).0cmdr-r-r. sz2ServiceOperation.lineage_names..rrJr-r-r.rszServiceOperation.lineage_namescCrLr?)r_create_argument_tablerJr-r-r.rs  zServiceOperation.arg_tablec Csd|j|jf}|j||j||jd||j}||||\}}|jdkr3| }|||S|jr<| |j|rGt dd |d|j|jf}|j|||d| ||j}d|j|jf}|j||||d } | dur|t| trz| | S|j|jjj|jj||S) Nz+before-building-argument-table-parser.%s.%s)rdrr3rlzUnknown options: %sz, zoperation-args-parsed.%s.%s)rrzcalling-command.%s.%s)call_parametersrr)rr_emitrr_create_operation_parser _add_helprrlryappendrr_build_call_parameters_emit_first_non_none_response isinstancerrinvokerrrYr) rFrreventoperation_parserrrop_helproverrider-r-r.rsZ         zServiceOperation.__call__cCs"t|j|j|j|jd|jdS)Nr)rrrr)rrrrrrrrJr-r-r.rys z$ServiceOperation.create_help_commandcCs|jddddS)Nrl?)nargs) add_argument)rFr`r-r-r.rszServiceOperation._add_helpcCsLi}t|}|D]}|j}||vr#||}|||}|||q |Sr?)varsvaluespy_name _unpack_arg add_to_params)rFrrservice_paramsr arg_objectrrr-r-r.r%s   z'ServiceOperation._build_call_parameterscCs,|j}|jjj}t|jd}t|||||S)Nr)rrrendpoint_prefixrrr)rFrkrr3rYrr-r-r.r4s   zServiceOperation._unpack_argc Cst}|jj}g}i}|dur|j}|j}|D]6\}}t|d}|j|j |j }|j dd} ||vo8| } |j d} |||| |j|| d} | |qt||jd|j|jf|j|j ||d|S)NridempotencyTokenFr0)rargument_model is_requiredrserialized_namer0zbuilding-argument-table.%s.%s)rr3rrd)rr input_shaperequired_membersmembersitemsr ARG_TYPESr8 type_nameDEFAULT_ARG_CLASSmetadatarr9rfrrrrr) rFrdrrequired_argumentsarg_dictarg_name arg_shape cli_arg_name arg_classis_tokenrr0rr-r-r.r>sD      z'ServiceOperation._create_argument_tablecK|jj|fi|Sr?)rrVrFrkwargsr-r-r.r^szServiceOperation._emitcKrr?)remit_first_non_none_responserr-r-r.ras z.ServiceOperation._emit_first_non_none_responsecCs t|}|Sr?r)rFrr`r-r-r.resz)ServiceOperation._create_operation_parserN)rrrrrrrrr rGrrrrrrrryrrrrrrrr-r-r-r.rs8"      6   rc@s0eZdZdZddZddZddZdd Zd S) rz.Call an AWS operation and format the response.cCrr?)rrEr-r-r.rGns zCLIOperationCaller.__init__cCs<|jj||j|j|jd}|||||}||||dS)aInvoke an operation and format the response. :type service_name: str :param service_name: The name of the service. Note this is the service name, not the endpoint prefix (e.g. ``ses`` not ``email``). :type operation_name: str :param operation_name: The operation name of the service. The casing of the operation name should match the exact casing used by the service, e.g. ``DescribeInstances``, not ``describe-instances`` or ``describe_instances``. :type parameters: dict :param parameters: The parameters for the operation call. Again, these values have the same casing used by the service. :type parsed_globals: Namespace :param parsed_globals: The parsed globals from the command line. :return: None, the result is displayed through a formatter, but no value is returned. ) region_name endpoint_urlverifyr)r create_clientrr verify_ssl_make_client_call_display_response)rFrYr parametersrclientresponser-r-r.rqszCLIOperationCaller.invokecCsRt|}||r|jr||}|jdi|}|St|t|di|}|S)Nr-)r can_paginatepaginate get_paginatorgetattr)rFrrrrpy_operation_name paginatorr r-r-r.rs z$CLIOperationCaller._make_client_callcCs2|j}|dur |jd}t||}|||dS)Noutput)r'rrr )rF command_namer rr' formatterr-r-r.rs   z$CLIOperationCaller._display_responseN)rrrrrGrrrr-r-r-r.rjs ! r)Brrrbotocore.sessionr4rr=botocore.hooksrrbotocore.compatrrbotocore.exceptionsrrr botocore.historyr rr awscli.compatr awscli.formatterr awscli.pluginrawscli.commandsrrawscli.argparserrrrr awscli.helprrrawscli.argumentsrrrrrawscli.argprocessr awscli.aliasrr awscli.utilsr!r" getLoggerrrr)encoder(r'r6objectr:r[rrr-r-r-r.sb                                 GvU