]c@sddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZddlmZddlZddlZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddl#m$Z$m%Z%ddl#m&Z&ddl#m'Z'ej(e)Z*e ddddgZ+e,dZ-de.fdYZ/dZ0dZ1dZ2e3d Z4d!Z5d"Z6d#e.fd$YZ7d%e.fd&YZ8d'e8fd(YZ9d)e9fd*YZ:d+e.fd,YZ;d-e;fd.YZ<d/e<fd0YZ=d1e<fd2YZ>d3e.fd4YZ?d5e?fd6YZ@d7e?fd8YZAd9e?fd:YZBd;e?fd<YZCd=e?fd>YZDd?e?fd@YZEdAe?fdBYZFdCe?fdDYZGdEe?fdFYZHdGe.fdHYZIdIe?fdJYZJdKe.fdLYZKdS(MiN(t namedtuple(tdeepcopy(tsha1(tparse(ttzlocal(tUNSIGNED(t total_seconds(tcompat_shell_split(tConfig(tUnknownCredentialError(tPartialCredentialsError(tConfigNotFound(tInvalidConfigError(tInfiniteLoopConfigError(tRefreshWithMFAUnsupportedError(tMetadataRetrievalError(tCredentialRetrievalError(tInstanceMetadataFetchertparse_key_val_file(tContainerMetadataFetcher(tFileWebIdentityTokenLoadertReadOnlyCredentialst access_keyt secret_keyttokencsyjdpd}jd}jd}jjddk }|dkrci}nt}t}tdtd|d|dj}t d |} t d fd d j d |d |dt |||gd| } || g} | j d |d|} tt||g} | | | }|rf|j|tjdntd|}|S(sCreate a default credential resolver. This creates a pre-configured credential resolver that includes the default lookup chain for credentials. tprofiletdefaulttmetadata_service_timeouttmetadata_service_num_attemptstiam_role_fetcherttimeoutt num_attemptst user_agenttcachet load_configcsjS(N(t full_config((tsession(s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pytPstclient_creatort profile_nametcredential_sourcertprofile_provider_buildertdisable_env_varssWSkipping environment variable credential check because profile name was explicitly set.t providersN(tget_config_variabletinstance_variablestgettNonet EnvProvidertContainerProvidertInstanceMetadataProviderRR tProfileProviderBuildertAssumeRoleProvidert create_clienttCanonicalNameCredentialSourcerR+tOriginalEC2Providert BotoProvidertremovetloggertdebugtCredentialResolver(R$R!R'tmetadata_timeoutRR*t env_providertcontainer_providertinstance_metadata_providerR)tassume_role_providert pre_profiletprofile_providerst post_profileR+tresolver((R$s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pytcreate_credential_resolver5sJ           R3cBsJeZdZddZedZdZdZdZ dZ RS(sThis class handles the creation of profile based providers. NOTE: This class is only intended for internal use. This class handles the creation and ordering of the various credential providers that primarly source their configuration from the shared config. This is needed to enable sharing between the default credential chain and the source profile chain created by the assume role provider. cCs||_||_dS(N(t_sessiont_cache(tselfR$R!((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt__init__s cCs7|j|||j||j||j|gS(N(t_create_web_identity_providert"_create_shared_credential_providert_create_process_providert_create_config_provider(RIR'R*((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR+s    cstd|dfdS(NR'R"cs jjS(N(RGR#((RI(s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR%s(tProcessProvider(RIR'((RIs6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRMscCs%|jjd}td|d|S(Ntcredentials_fileR'tcreds_filename(RGR,tSharedCredentialProvider(RIR'tcredential_file((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRLscCs%|jjd}td|d|S(Nt config_fileR'tconfig_filename(RGR,tConfigProvider(RIR'RT((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRNsc s7tdfddjjdjd|d|S(NR"cs jjS(N(RGR#((RI(s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR%sR&R!R'R*(t!AssumeRoleWithWebIdentityProviderRGR5RH(RIR'R*((RIs6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRKs   N( t__name__t __module__t__doc__R/RJtFalseR+RMRLRNRK(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR3s     cCst|}|jS(N(RFtload_credentials(R$RE((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pytget_credentialss cCstjjtS(N(tdatetimetnowR(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt _local_nowscCs t|tjr|St|S(N(t isinstanceR^R(tvalue((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt_parse_if_neededscCs3t|tjr/|r"|jS|jdS|S(Ns%Y-%m-%dT%H:%M:%S%Z(RaR^t isoformattstrftime(Rbtiso((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt_serialize_if_neededs   csfd}|S(NcsOj}|d}i|dd6|dd6|dd6t|dd 6S( Nt Credentialst AccessKeyIdRtSecretAccessKeyRt SessionTokenRt Expirationt expiry_time(t assume_roleRg(tresponset credentials(tclienttparams(s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pytrefreshs    ((RqRrRs((RqRrs6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pytcreate_assume_role_refreshers cCs dtfdY}||S(Nt _RefreshercBseZdZdZRS(cSs||_t|_dS(N(t_refreshR[t_has_been_called(RIRs((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJs cSs(|jrtnt|_|jS(N(RwRtTrueRv(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt__call__s   (RXRYRJRy(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRus (tobject(tactual_refreshRu((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pytcreate_mfa_serial_refresherst JSONFileCachecBseeZdZejjejjddddZedZdZ dZ dZ d Z RS( sJSON file cache. This provides a dict like interface that stores JSON serializable objects. The objects are serialized to JSON and stored in a file. These values can be retrieved at a later time. t~s.awstbotoR!cCs ||_dS(N(t _working_dir(RIt working_dir((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJscCs|j|}tjj|S(N(t_convert_cache_keytostpathtisfile(RIt cache_keyt actual_key((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt __contains__scCsb|j|}y&t|}tj|SWdQXWn&tttfk r]t|nXdS(s Retrieve value from a cache key.N(RtopentjsontloadtOSErrort ValueErrortIOErrortKeyError(RIRRtf((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt __getitem__s cCs|j|}ytj|dt}Wn'ttfk rQtd|nXtjj|j sztj |j ntj tj |tj tjBdd}|j|j|WdQXdS(NRs5Value cannot be cached, must be JSON serializable: %sitw(RRtdumpsRgt TypeErrorRRRtisdirRtmakedirstfdopenRtO_WRONLYtO_CREATttruncatetwrite(RIRRbtfull_keyt file_contentR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt __setitem__ s cCs tjj|j|d}|S(Ns.json(RRtjoinR(RIRt full_path((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs( RXRYRZRRt expanduserRt CACHE_DIRRJRRRR(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR}s'   RhcBs/eZdZdddZdZdZRS(s\ Holds the credentials needed to authenticate requests. :ivar access_key: The access key part of the credentials. :ivar secret_key: The secret key part of the credentials. :ivar token: The security token, valid only for session credentials. :ivar method: A string which identifies where the credentials were found. cCsG||_||_||_|dkr0d}n||_|jdS(Ntexplicit(RRRR/tmethodt _normalize(RIRRRR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJ)s      cCs4tjj|j|_tjj|j|_dS(N(tbotocoretcompattensure_unicodeRR(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR5scCst|j|j|jS(N(RRRR(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pytget_frozen_credentials?s N(RXRYRZR/RJRR(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRhs   tRefreshableCredentialscBseZdZdZdZedZdZedZ e dZ e j dZ e d Z e j d Z e d Zej d Zd ZddZdZdZdZedZdZdZRS(s Holds the credentials needed to authenticate requests. In addition, it knows how to refresh itself. :ivar access_key: The access key part of the credentials. :ivar secret_key: The secret key part of the credentials. :ivar token: The security token, valid only for session credentials. :ivar method: A string which identifies where the credentials were found. ii<i cCsq||_||_||_||_||_||_tj|_||_ t ||||_ |j dS(N( t_refresh_usingt _access_keyt _secret_keyt_tokent _expiry_timet _time_fetchert threadingtLockt _refresh_lockRRt_frozen_credentialsR(RIRRRRmt refresh_usingRt time_fetcher((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJWs       cCs4tjj|j|_tjj|j|_dS(N(RRRRR(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRfsc CsJ|d|dd|dd|dd|j|dd|d|}|S(NRRRRmRR(t_expiry_datetime(tclstmetadataRRtinstance((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pytcreate_from_metadatajs    cCs|j|jS(sWarning: Using this property can lead to race conditions if you access another property subsequently along the refresh boundary. Please use get_frozen_credentials instead. (RvR(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRvs cCs ||_dS(N(R(RIRb((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRscCs|j|jS(sWarning: Using this property can lead to race conditions if you access another property subsequently along the refresh boundary. Please use get_frozen_credentials instead. (RvR(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs cCs ||_dS(N(R(RIRb((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRscCs|j|jS(sWarning: Using this property can lead to race conditions if you access another property subsequently along the refresh boundary. Please use get_frozen_credentials instead. (RvR(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs cCs ||_dS(N(R(RIRb((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRscCs|j|j}t|S(N(RRR(RItdelta((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt_seconds_remainingscCsR|jdkrtS|dkr+|j}n|j|krAtStjdtS(sCheck if a refresh is needed. A refresh is needed if the expiry time associated with the temporary credentials is less than the provided ``refresh_in``. If ``time_delta`` is not provided, ``self.advisory_refresh_needed`` will be used. For example, if your temporary credentials expire in 10 minutes and the provided ``refresh_in`` is ``15 * 60``, then this function will return ``True``. :type refresh_in: int :param refresh_in: The number of seconds before the credentials expire in which refresh attempts should be made. :return: True if refresh neeeded, False otherwise. s!Credentials need to be refreshed.N(RR/R[t_advisory_refresh_timeoutRR:R;Rx(RIt refresh_in((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pytrefresh_neededs   cCs|jddS(NRi(R(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt _is_expiredscCs|j|jsdS|jjtr|z@|j|jsAdS|j|j}|jd|dSWd|jjXnK|j|jr|j+|j|jsdS|jdtWdQXndS(Nt is_mandatory( RRRtacquireR[t_mandatory_refresh_timeoutt_protected_refreshtreleaseRx(RItis_mandatory_refresh((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRvs   cCsy|j}WnHtk rZ}|r.dnd}tjd|dt|rVndSX|j|t|j|j|j |_ |j rd}tj|t |ndS(Nt mandatorytadvisorysARefreshing temporary credentials failed during %s refresh period.texc_infosLCredentials were refreshed, but the refreshed credentials are still expired.( Rt ExceptionR:twarningRxt_set_from_dataRRRRRRt RuntimeError(RIRRtet period_nametmsg((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs      cCs t|S(N(R(ttime_str((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRscCsddddg}|s!|}n%g|D]}||kr(|^q(}|rzd}td|jd|dj|n|d|_|d|_|d|_t|d|_tj d |j|j dS( NRRRRms7Credential refresh failed, response did not contain: %stprovidert error_msgs, s(Retrieved credentials will expire at: %s( RRRRRRRRR:R;R(RItdatat expected_keyst missing_keystktmessage((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR s  %      cCs|j|jS(sReturn immutable credentials. The ``access_key``, ``secret_key``, and ``token`` properties on this class will always check and refresh credentials if needed before returning the particular credentials. This has an edge case where you can get inconsistent credentials. Imagine this: # Current creds are "t1" tmp.access_key ---> expired? no, so return t1.access_key # ---- time is now expired, creds need refreshing to "t2" ---- tmp.secret_key ---> expired? yes, refresh and return t2.secret_key This means we're using the access key from t1 with the secret key from t2. To fix this issue, you can request a frozen credential object which is guaranteed not to change. The frozen credentials returned from this method should be used immediately and then discarded. The typical usage pattern would be:: creds = RefreshableCredentials(...) some_code = SomeSignerObject() # I'm about to sign the request. # The frozen credentials are only used for the # duration of generate_presigned_url and will be # immediately thrown away. request = some_code.sign_some_request( with_credentials=creds.get_frozen_credentials()) print("Signed request:", request) (RvR(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs" iiXN(RXRYRZRRR`RJRt classmethodRtpropertyRtsetterRRRR/RRRvRt staticmethodRRR(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyREs(        "   ! tDeferredRefreshableCredentialscBs&eZdZedZddZRS(syRefreshable credentials that don't require initial credentials. refresh_using will be called upon first access. cCs[||_d|_d|_d|_d|_||_tj|_ ||_ d|_ dS(N( RR/RRRRRRRRRR(RIRRR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJJs       cCs)|jdkrtStt|j|S(N(RR/RxtsuperRR(RIR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRUsN(RXRYRZR`RJR/R(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyREs tCachedCredentialFetchercBseeZd Zd d dZdZdZdZdZdZ dZ d Z d Z RS( i<icCsR|dkri}n||_|j|_|dkrE|j}n||_dS(N(R/RHt_create_cache_keyt _cache_keytDEFAULT_EXPIRY_WINDOW_SECONDSt_expiry_window_seconds(RIR!texpiry_window_seconds((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJ`s     cCstddS(Ns_create_cache_key()(tNotImplementedError(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRiscCs4|jddjtjjd}|jddS(Nt:t_t/(treplaceRRtsep(RItfilename((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt_make_file_safels$cCstddS(Ns_get_credentials()(R(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt_get_credentialsqscCs |jS(N(t_get_cached_credentials(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pytfetch_credentialstscCs|j}|d kr4|j}|j|n tjd|d}t|ddt}i|dd6|dd6|d d 6|d 6S( sGet up-to-date credentials. This will check the cache for up-to-date credentials, calling assume role if none are available. s*Credentials for role retrieved from cache.RhRlRfRiRRjRRkRRmN(t_load_from_cacheR/Rt_write_to_cacheR:R;RgRx(RIRotcredst expiration((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRws        cCsO|j|jkrKt|j|j}|j|s;|StjdndS(Ns6Credentials were found in cache, but they are expired.(RRHRRR:R;R/(RIR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs cCst||j|jeZdZejdZdZdZedZ RS(scustom-processcCs(||_||_d|_||_dS(N(t _profile_namet _load_configR/t_loaded_configt_popen(RIR'R"tpopen((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJs   c sjdkrdSj}|jddk r_tj|fdjStd|dd|dd|jddjS(NRmcs jS(N(t_retrieve_credentials_using((tcredential_processRI(s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR%sRRRR(t_credential_processR/R8R.RRR,Rh(RIt creds_dict((R9RIs6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs     c CsAt|}|j|dtjdtj}|j\}}|jdkrrtd|jd|jdnt j j j |jd}|j dd}|d krtd|jdd |ny>i|d d 6|d d6|j dd6|j dd6SWn/tk r<}td|jdd|nXdS(NtstdouttstderriRRsutf-8tVersionsisOUnsupported version '%s' for credential process provider, supported versions: 1RiRRjRRkRRlRms$Missing required key in response: %s(RR6t subprocesstPIPEt communicatet returncodeRR,tdecodeRRRRR.R( RIR9t process_listtpR<R=tparsedtversionR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR8s2          cCsR|jdkr!|j|_n|jjdij|ji}|jdS(NtprofilesR9(R5R/R4R.R3(RItprofile_config((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR:s  ( RXRYR,R?tPopenRJRR8RR:(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyROs   R2cBs&eZdZdZdZdZRS(siam-roletEc2InstanceMetadatacCs ||_dS(N(t _role_fetcher(RIR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJscCsX|j}|j}|sdStjd|dtj|d|jd|j}|S(Ns#Found credentials from IAM Role: %st role_nameRR(RLtretrieve_iam_role_credentialsR/R:R;RRR,(RItfetcherRR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs      (RXRYR,R2RJR(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR2s R0cBs\eZdZdZdZdZddgZdZd d dZ dZ d Z d Z RS( tenvt EnvironmenttAWS_ACCESS_KEY_IDtAWS_SECRET_ACCESS_KEYtAWS_SECURITY_TOKENtAWS_SESSION_TOKENtAWS_CREDENTIAL_EXPIRATIONcCs7|dkrtj}n||_|j||_dS(s :param environ: The environment variables (defaults to ``os.environ`` if no value is provided). :param mapping: An optional mapping of variable names to environment variable names. Use this if you want to change the mapping of access_key->AWS_ACCESS_KEY_ID, etc. The dict can have up to 3 keys: ``access_key``, ``secret_key``, ``session_token``. N(R/Rtenviront_build_mappingt_mapping(RIRWR-((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJs   cCsi}|dkrI|j|d<|j|d<|j|d<|j|dtdddn||d<jdd}|stdddn||deZdZdZdZdZdZdddZdZ RS(sec2-credentials-filet Ec2ConfigtAWS_CREDENTIAL_FILEtAWSAccessKeyIdt AWSSecretKeycCsC|dkrtj}n|dkr-t}n||_||_dS(N(R/RRWRt_environt_parser(RIRWtparser((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJgs      cCsd|jkrtjj|jd}|j|}|j|krtjd||j}||j}t ||d|j SndSdS(sN Search for a credential file used by original EC2 CLI tools. Rfs)Found credentials in AWS_CREDENTIAL_FILE.RN( RiRRRRjRZR:RbR[RhR,R/(RIRRRR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRos    N( RXRYR,R2t CRED_FILE_ENVRZR[R/RJR(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR7_sRRcBsMeZdZdZdZdZddgZd d dZdZ dZ RS( sshared-credentials-filetSharedCredentialsRRtaws_security_tokenRcCsO||_|dkrd}n||_|dkrBtjj}n||_dS(NR(t_creds_filenameR/R3Rt configloadertraw_config_parset _ini_parser(RIRQR't ini_parser((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJs     cCsy|j|j}Wntk r*dSX|j|kr||j}|j|krtjd|j|j||j|j \}}|j |}t |||d|j SndS(Ns0Found credentials in shared credentials file: %sR( RrRoR R/R3RZR:RbR1R[t_get_session_tokenRhR,(RItavailable_credsR%RRR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs    cCs,x%|jD]}||kr ||Sq WdS(N(R\(RIR%t token_envvar((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRts N( RXRYR,R2RZR[R\R/RJRRt(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRRs  RVcBsPeZdZdZdZdZdZddgZd dZ dZ d Z RS( s0INI based config provider with profile sections.s config-filet SharedConfigRRRnRcCs:||_||_|dkr-tjj}n||_dS(s :param config_filename: The session configuration scoped to the current profile. This is available via ``session.config``. :param profile_name: The name of the current profile. :param config_parser: A config parser callable. N(t_config_filenameR3R/RRpR"t_config_parser(RIRUR't config_parser((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJs   cCsy|j|j}Wntk r*dSX|j|dkr|d|j}|j|krtjd|j|j||j|j \}}|j |}t |||d|j SndSdS(sr If there is are credentials in the configuration associated with the session, use those. RHs$Credentials found in config file: %sRN( RyRxR R/R3RZR:RbR1R[RtRhR,(RIR#RIRRR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs    cCs,x%|jD]}||kr ||Sq WdS(N(R\(RIRIt token_name((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRts N( RXRYRZR,R2RZR[R\R/RJRRt(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRVs   R8cBsJeZdZdZdZddgZdZdZd d dZ dZ RS( s boto-configt Boto2Configt BOTO_CONFIGs /etc/boto.cfgs~/.botoRRcCsI|dkrtj}n|dkr3tjj}n||_||_dS(N(R/RRWRRpRqRiRr(RIRWRs((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJs     cCs|j|jkr(|j|jg}n |j}x|D]}y|j|}Wntk rgq8nXd|kr8|d}|j|krtjd||j||j|j \}}t ||d|j Sq8q8WdS(s; Look for credentials in boto config file. Rhs)Found credentials in boto config file: %sRN( tBOTO_CONFIG_ENVRitDEFAULT_CONFIG_FILENAMESRrR RZR:RbR1R[RhR,(RItpotential_locationsRR%RpRR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs"       N( RXRYR,R2R~RRZR[R/RJR(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR8s R4cBseZdZdZdZdZdZejdddZ dZ dZ dZ d Z d Zd Zd Zd ZdZdZdZdZRS(s assume-roleRtweb_identity_token_filei<icCs[||_||_||_||_||_i|_||_||_|jg|_dS(s :type load_config: callable :param load_config: A function that accepts no arguments, and when called, will return the full configuration dictionary for the session (``session.full_config``). :type client_creator: callable :param client_creator: A factory function that will create a client when called. Has the same interface as ``botocore.session.Session.create_client``. :type cache: dict :param cache: An object that supports ``__getitem__``, ``__setitem__``, and ``__contains__``. An example of this is the ``JSONFileCache`` class in the CLI. :type profile_name: str :param profile_name: The name of the profile. :type prompter: callable :param prompter: A callable that returns input provided by the user (i.e raw_input, getpass.getpass, etc.). :type credential_sourcer: CanonicalNameCredentialSourcer :param credential_sourcer: A credential provider that takes a configuration, which is used to provide the source credentials for the STS call. N( R!R4RR3t _prompterR5t_credential_sourcert_profile_provider_buildert_visited_profiles(RIR"R&R!R'tprompterR(R)((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJs$        cCs\|j|_|jjdi}|j|ji}|j|rX|j|jSdS(NRH(R4R5R.R3t_has_assume_role_config_varst_load_creds_via_assume_role(RIRHR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRRs cCs|j|ko|j|kS(N(tROLE_CONFIG_VARtWEB_IDENTITY_TOKE_FILE_VAR(RIR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRYsc CsA|j|}|j||}i}|jd}|dk rO||ds(R(RIRt static_keys((Rs6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs cCsR|jd}|dk r+|j||S|d}|jj||j|S(NRR(R.R/t _resolve_credentials_from_sourceRR+t!_resolve_credentials_from_profile(RIRR'RR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs   cCs|jjdi}||}|j|rE|j rE|j|S|j|sd|j| r|jjd|dt}t|}|j }|dkrd}t d||n|S|j |S(NRHR'R*s.The source profile "%s" must have credentials.R( R5R.RRt(_resolve_static_credentials_from_profileRR+RxR<R\R/R R(RIR'RHRRCt profile_chainRpt error_message((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR s$        cCsfy.td|dd|dd|jdSWn1tk ra}td|jdt|nXdS( NRRRRRRRR*(RhR.RR R,tstr(RIRR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR's  cCs>|jj|}|dkr:td|dd|n|S(NRRsBNo credentials found in credential_source referenced in profile %s(RRR/R(RIRR'Rp((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR2s    Ni(RXRYR,R/R2RRtEXPIRY_WINDOW_SECONDSRRJRRRRRRRRRRRR(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR4 s&  5  , 2  &   RWcBsneZdZd Zidd6dd6dd6Zd ed dZdZd Z d Z d Z d Z RS(sassume-role-with-web-identitytAWS_WEB_IDENTITY_TOKEN_FILERtAWS_ROLE_SESSION_NAMERt AWS_ROLE_ARNRcCsX||_||_||_||_d|_||_|dkrKt}n||_dS(N( R!R4RR3R/t_profile_configt_disable_env_varsRt_token_loader_cls(RIR"R&R'R!R*ttoken_loader_cls((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJJs        cCs |jS(N(t_assume_role_with_web_identity(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR]scCsX|jdkrH|j}|jdi}|j|ji|_n|jj|S(NRH(RR/R4R.R3(RItkeyt loaded_configRH((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt_get_profile_config`s  cCsC|jr dS|jj|}|r?|tjkr?tj|SdS(N(RR/t_CONFIG_TO_ENV_VARR.RRW(RIRtenv_key((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt_get_env_configgs   cCs,|j|}|dk r|S|j|S(N(RR/R(RIRt env_value((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt _get_configos c Cs|jd}|sdS|j|}|jd}|sUd}td|ni}|jd}|dk r||deZdZdZdZdZdZdZRS(cCs ||_dS(N(t _providers(RIR+((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJscCs#|g|jD]}|j^q kS(sLValidates a given source name. :type source_name: str :param source_name: The value of credential_source in the config file. This is the canonical name of the credential provider. :rtype: bool :returns: True if the credential provider is supported, False otherwise. (RR2(RIt source_nameRE((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs cCs2|j|}t|tr(|jS|jS(sLoads source credentials based on the provided configuration. :type source_name: str :param source_name: The value of credential_source in the config file. This is the canonical name of the credential provider. :rtype: Credentials (t _get_providerRaR<R\R(RIRtsource((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs  cCs|j|}|jdkr_|jd}|dk r_|dkrL|St||gSn|dkr}td|n|S(s#Return a credential provider by its canonical name. :type canonical_name: str :param canonical_name: The canonical name of the provider. :raises UnknownCredentialError: Raised if no credential provider by the provided name is found. t sharedconfigtsharedcredentialss assume-roletname(RRN(t_get_provider_by_canonical_nametlowert_get_provider_by_methodR/R<R (RItcanonical_nameRRA((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs    cCsCx<|jD]1}|j}|r |j|jkr |Sq WdS(sReturn a credential provider by its canonical name. This function is strict, it does not attempt to address compatibility issues. N(RR2R(RIRRR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs cCs+x$|jD]}|j|kr |Sq WdS(s0Return a credential provider by its METHOD name.N(RR,(RIRR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs(RXRYRJRRRRR(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR6s    & R1cBsbeZdZdZdZdZdZd d dZdZ dZ dZ d Z d Z RS( scontainer-rolet EcsContainert&AWS_CONTAINER_CREDENTIALS_RELATIVE_URIt"AWS_CONTAINER_CREDENTIALS_FULL_URIt!AWS_CONTAINER_AUTHORIZATION_TOKENcCsF|dkrtj}n|dkr0t}n||_||_dS(N(R/RRWRRit_fetcher(RIRWRO((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJs      cCs2|j|jks$|j|jkr.|jSdS(N(tENV_VARRit ENV_VAR_FULLt_retrieve_or_fail(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs$c Cs|jr+|jj|j|j}n|j|j}|j}|j||}|}td|dd|dd|dd|j dt |dd|S(NRRRRRmR( t_provided_relative_uriRtfull_urlRiRRt_build_headerst_create_fetcherRR,Rc(RItfull_uritheadersROR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs       cCs6i}|jj|j}|dk r2i|d6SdS(Nt Authorization(RiR.tENV_VAR_AUTH_TOKENR/(RIRt auth_token((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs  csfd}|S(Ncsyjjd}WnGtk re}tjd|dttdjdt|nXi|dd6|dd 6|d d 6|d d 6S(NRs'Error retrieving container metadata: %sRRRRiRRjRtTokenRRlRm( Rtretrieve_full_uriRR:R;RxRR,R(RoR(RRRI(s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt fetch_creds!s    ((RIRRR((RRRIs6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR scCs|j|jkS(N(RRi(RI((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR3sN(RXRYR,R2RRRR/RJRRRRR(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR1s    R<cBsGeZdZdZdZdZdZdZdZRS(cCs ||_dS(sQ :param providers: A list of ``CredentialProvider`` instances. N(R+(RIR+((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRJ8scCsfy,g|jD]}|j^q j|}Wn tk rNtd|nX|jj||dS(s= Inserts a new instance of ``CredentialProvider`` into the chain that will be tried before an existing one. :param name: The short name of the credentials you'd like to insert the new credentials before. (ex. ``env`` or ``config``). Existing names & ordering can be discovered via ``self.available_methods``. :type name: string :param cred_instance: An instance of the new ``Credentials`` object you'd like to add to the chain. :type cred_instance: A subclass of ``Credentials`` RN(R+R,tindexRR tinsert(RIRtcredential_providerREtoffset((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt insert_before@s , cCs*|j|}|jj|d|dS(s9 Inserts a new type of ``Credentials`` instance into the chain that will be tried after an existing one. :param name: The short name of the credentials you'd like to insert the new credentials after. (ex. ``env`` or ``config``). Existing names & ordering can be discovered via ``self.available_methods``. :type name: string :param cred_instance: An instance of the new ``Credentials`` object you'd like to add to the chain. :type cred_instance: A subclass of ``Credentials`` iN(t_get_provider_offsetR+R(RIRRR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt insert_afterTscCsRg|jD]}|j^q }||kr/dS|j|}|jj|dS(s Removes a given ``Credentials`` instance from the chain. :param name: The short name of the credentials instance to remove. :type name: string N(R+R,Rtpop(RIRREtavailable_methodsR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR9es  cCs|j|j|S(sReturn a credential provider by name. :type name: str :param name: The name of the provider. :raises UnknownCredentialError: Raised if no credential provider by the provided name is found. (R+R(RIR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyt get_providerts cCsQy*g|jD]}|j^q j|SWn tk rLtd|nXdS(NR(R+R,RRR (RIRRE((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyRs* cCsGx@|jD]5}tjd|j|j}|dk r |Sq WdS(sw Goes through the credentials chain, returning the first ``Credentials`` that could be loaded. sLooking for credentials via: %sN(R+R:R;R,RR/(RIRR((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR\s   ( RXRYRJRRR9RRR\(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyR<7s     (LRR^tloggingRRRRR?t collectionsRtcopyRthashlibRtdateutil.parserRt dateutil.tzRtbotocore.configloaderRtbotocore.compatRRRtbotocore.configRtbotocore.exceptionsR R R R R RRRtbotocore.utilsRRRRt getLoggerRXR:RR/RFRzR3R]R`RcR[RgRtR|R}RhRRRRR R!R)ROR2R0R7RRRVR8R4RWR6R1R<(((s6/tmp/pip-build-Q8jF4w/botocore/botocore/credentials.pyts           M6      -'E1P8-Ft"*7*6YXE