rmLbc@sddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZddlmZmZddlZddlZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddl%m&Z&m'Z'ddl%m(Z(ddl%m)Z)ddl%m*Z*ddl%m+Z+ej,e-Z.e ddddgZ/e0e0dZ1de2fdYZ3d Z4d!Z5d"Z6e7d#Z8d$Z9d%Z:d&Z;d'e2fd(YZ<d)e2fd*YZ=d+e=fd,YZ>d-e>fd.YZ?d/e2fd0YZ@d1e@fd2YZAd3eAfd4YZBd5eAfd6YZCd7e2fd8YZDd9eDfd:YZEd;eDfd<YZFd=eDfd>YZGd?eDfd@YZHdAeDfdBYZIdCeDfdDYZJdEeDfdFYZKdGeDfdHYZLdIeDfdJYZMdKe2fdLYZNdMeDfdNYZOdOe2fdPYZPdQe@fdRYZQdSeDfdTYZRdS(UiN(t namedtuple(tdeepcopy(tsha1(tparse(ttzlocalttzutc(tUNSIGNED(t total_seconds(tcompat_shell_split(tConfig(tUnknownCredentialError(tPartialCredentialsError(tConfigNotFound(tInvalidConfigError(tInfiniteLoopConfigError(tRefreshWithMFAUnsupportedError(tMetadataRetrievalError(tCredentialRetrievalError(tUnauthorizedSSOTokenError(tInstanceMetadataFetchertparse_key_val_file(tContainerMetadataFetcher(tFileWebIdentityTokenLoader(tSSOTokenLoader(tresolve_imds_endpoint_modetReadOnlyCredentialst access_keyt secret_keyttokencsjdpd}jd}jd}jjddk }ijdd6td6}|dkri}nt}t} tdtd|d |d j d |} t d |d |} t dfddt |d |d|dt || | gd| } || g} | jd|d|}tt| | g}| ||}|r|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_attemptstec2_metadata_service_endpointt"ec2_metadata_service_endpoint_modetiam_role_fetcherttimeoutt num_attemptst user_agenttconfigtcachet region_namet load_configcsjS(N(t full_config((tsession(s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt\stclient_creatort profile_nametcredential_sourcertprofile_provider_buildertdisable_env_varssWSkipping environment variable credential check because profile name was explicitly set.t providersN(tget_config_variabletinstance_variablestgettNoneRt EnvProvidertContainerProvidertInstanceMetadataProviderRR&tProfileProviderBuildertAssumeRoleProvidert_get_client_creatortCanonicalNameCredentialSourcerR3tOriginalEC2Providert BotoProvidertremovetloggertdebugtCredentialResolver(R,R(R)R/tmetadata_timeoutR%R2t imds_configt env_providertcontainer_providertinstance_metadata_providerR1tassume_role_providert pre_profiletprofile_providerst post_profileR3tresolver((R,s5/usr/lib/fence-agents/bundled/botocore/credentials.pytcreate_credential_resolver8sX              R;cBsYeZdZddddZedZdZdZdZ dZ 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_cachet _region_namet_sso_token_cache(tselfR,R(R)tsso_token_cache((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt__init__s   cCsC|j|||j||j||j||j|gS(N(t_create_web_identity_providert_create_sso_providert"_create_shared_credential_providert_create_process_providert_create_config_provider(RTR/R2((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR3s     cstd|dfdS(NR/R*cs jjS(N(RPR+((RT(s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR-s(tProcessProvider(RTR/((RTs5/usr/lib/fence-agents/bundled/botocore/credentials.pyRZscCs%|jjd}td|d|S(Ntcredentials_fileR/tcreds_filename(RPR4tSharedCredentialProvider(RTR/tcredential_file((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRYscCs%|jjd}td|d|S(Nt config_fileR/tconfig_filename(RPR4tConfigProvider(RTR/Ra((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR[sc s@tdfddtjjdjd|d|S(NR*cs jjS(N(RPR+((RT(s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR-sR.R(R/R2(t!AssumeRoleWithWebIdentityProviderR=RPRRRQ(RTR/R2((RTs5/usr/lib/fence-agents/bundled/botocore/credentials.pyRWs c s:tdfddjjd|djdjS(NR*cs jjS(N(RPR+((RT(s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR-sR.R/R(t token_cache(t SSOProviderRPt create_clientRQRS(RTR/((RTs5/usr/lib/fence-agents/bundled/botocore/credentials.pyRXs   N( t__name__t __module__t__doc__R7RVtFalseR3RZRYR[RWRX(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR;s      cCst|}|jS(N(ROtload_credentials(R,RN((s5/usr/lib/fence-agents/bundled/botocore/credentials.pytget_credentialss cCstjjtS(N(tdatetimetnowR(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt _local_nowscCs t|tjr|St|S(N(t isinstanceRnR(tvalue((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt_parse_if_neededscCs3t|tjr/|r"|jS|jdS|S(Ns%Y-%m-%dT%H:%M:%S%Z(RqRnt isoformattstrftime(Rrtiso((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt_serialize_if_neededs   csfd}|S(Ncs*id6}|j|j||S(NR)(tupdateRg(t service_nametkwargstcreate_client_kwargs(R)R,(s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR.s  ((R,R)R.((R)R,s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR=scsfd}|S(NcsOj}|d}i|dd6|dd6|dd6t|dd 6S( Nt Credentialst AccessKeyIdRtSecretAccessKeyRt SessionTokenRt Expirationt expiry_time(t assume_roleRw(tresponset credentials(tclienttparams(s5/usr/lib/fence-agents/bundled/botocore/credentials.pytrefreshs    ((RRR((RRs5/usr/lib/fence-agents/bundled/botocore/credentials.pytcreate_assume_role_refreshers cCs dtfdY}||S(Nt _RefreshercBseZdZdZRS(cSs||_t|_dS(N(t_refreshRkt_has_been_called(RTR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRVs cSs(|jrtnt|_|jS(N(RRtTrueR(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt__call__ s   (RhRiRVR(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs (tobject(tactual_refreshR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pytcreate_mfa_serial_refresherst JSONFileCachecBszeZdZejjejjddddZed dZ dZ dZ dZ d Z d Zd ZRS( 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.||_|dkr!|j}n||_dS(N(t _working_dirR7t_default_dumpst_dumps(RTt working_dirt dumps_func((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRV s   cCstj|dtS(NR(tjsontdumpsRw(RTtobj((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR&scCs|j|}tjj|S(N(t_convert_cache_keytostpathtisfile(RTt cache_keyt actual_key((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt __contains__)scCsb|j|}y&t|}tj|SWdQXWn&tttfk r]t|nXdS(s Retrieve value from a cache key.N(RtopenRtloadtOSErrort ValueErrortIOErrortKeyError(RTRRtf((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt __getitem__-s cCsJ|j|}y|}tj|Wntk rEt|nXdS(N(RRtunlinktFileNotFoundErrorR(RTRRtkey_path((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt __delitem__6s  cCs|j|}y|j|}Wn'ttfk rKtd|nXtjj|jsttj|jntj tj |tj tj Bdd}|j |j|WdQXdS(Ns5Value cannot be cached, must be JSON serializable: %sitw(RRt TypeErrorRRRtisdirRtmakedirstfdopenRtO_WRONLYtO_CREATttruncatetwrite(RTRRrtfull_keyt file_contentR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt __setitem__>s cCs tjj|j|d}|S(Ns.json(RRtjoinR(RTRt full_path((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRLsN(RhRiRjRRt expanduserRt CACHE_DIRR7RVRRRRRR(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs'    R|cBs/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(RRRR7tmethodt _normalize(RTRRRR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRV\s      cCs4tjj|j|_tjj|j|_dS(N(tbotocoretcompattensure_unicodeRR(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRhscCst|j|j|jS(N(RRRR(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pytget_frozen_credentialsrs N(RhRiRjR7RVRR(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR|Qs   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(RTRRRRt refresh_usingRt time_fetcher((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRVs       cCs4tjj|j|_tjj|j|_dS(N(RRRRR(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRsc CsJ|d|dd|dd|dd|j|dd|d|}|S(NRRRRRR(t_expiry_datetime(tclstmetadataRRtinstance((s5/usr/lib/fence-agents/bundled/botocore/credentials.pytcreate_from_metadatas    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. (RR(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs cCs ||_dS(N(R(RTRr((s5/usr/lib/fence-agents/bundled/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. (RR(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs cCs ||_dS(N(R(RTRr((s5/usr/lib/fence-agents/bundled/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. (RR(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs cCs ||_dS(N(R(RTRr((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRscCs|j|j}t|S(N(RRR(RTtdelta((s5/usr/lib/fence-agents/bundled/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 needed, False otherwise. s!Credentials need to be refreshed.N(RR7Rkt_advisory_refresh_timeoutRRBRCR(RTt refresh_in((s5/usr/lib/fence-agents/bundled/botocore/credentials.pytrefresh_neededs   cCs|jddS(NRi(R(RT((s5/usr/lib/fence-agents/bundled/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( RRRtacquireRkt_mandatory_refresh_timeoutt_protected_refreshtreleaseR(RTtis_mandatory_refresh((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs   cCsy|j}WnFtk rX|r,dnd}tjd|dt|rTndSX|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 ExceptionRBtwarningRt_set_from_dataRRRRRRt RuntimeError(RTRRt period_nametmsg((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs       cCs t|S(N(R(ttime_str((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR8scCsddddg}|s!|}n%g|D]}||kr(|^q(}|rzd}td|jd|dj|n|d|_|d|_|d|_t|d|_tj d |j|j dS( NRRRRs7Credential refresh failed, response did not contain: %stprovidert error_msgs, s(Retrieved credentials will expire at: %s( RRRRRRRRRBRCR(RTtdatat expected_keyst missing_keystktmessage((s5/usr/lib/fence-agents/bundled/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) (RR(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRRs" iiXN(RhRiRjRRRpRVRt classmethodRtpropertyRtsetterRRRR7RRRRt staticmethodRRR(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRxs(        "   ! 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( RR7RRRRRRRRRR(RTRRR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRV}s       cCs)|jdkrtStt|j|S(N(RR7RtsuperRR(RTR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRsN(RhRiRjRpRVR7R(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRxs tCachedCredentialFetchercBseeZd Zd d dZdZdZdZdZdZ dZ d Z d Z RS( i<icCsR|dkri}n||_|j|_|dkrE|j}n||_dS(N(R7RQt_create_cache_keyt _cache_keytDEFAULT_EXPIRY_WINDOW_SECONDSt_expiry_window_seconds(RTR(texpiry_window_seconds((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRVs     cCstddS(Ns_create_cache_key()(tNotImplementedError(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRscCs4|jddjtjjd}|jddS(Nt:t_t/(treplaceRRtsep(RTtfilename((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt_make_file_safes$cCstddS(Ns_get_credentials()(R(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt_get_credentialsscCs |jS(N(t_get_cached_credentials(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pytfetch_credentialsscCs|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.R|RRvR}RR~RRRRN(t_load_from_cacheR7R t_write_to_cacheRBRCRwR(RTRtcredst expiration((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR s        cCsO|j|jkrKt|j|j}|j|s;|StjdndS(Ns6Credentials were found in cache, but they are expired.(RRQRRRBRCR7(RTR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR s cCst||j|jeZdZejdZdZdZedZ RS(scustom-processcCs(||_||_d|_||_dS(N(t _profile_namet _load_configR7t_loaded_configt_popen(RTR/R*tpopen((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRVs   c sjdkrdSj}|jddk r_tj|fdjStd|dd|dd|jddjS(NRcs jS(N(t_retrieve_credentials_using((tcredential_processRT(s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR-sRRRR(t_credential_processR7RQR6RRRER|(RTt creds_dict((RRRTs5/usr/lib/fence-agents/bundled/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: 1R}RR~RRRRRs$Missing required key in response: %s(RROt subprocesstPIPEt communicatet returncodeRREtdecodeRRRR!R6R( RTRRt process_listtpRURVtparsedtversionte((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRQs2          cCsR|jdkr!|j|_n|jjdij|ji}|jdS(NtprofilesRR(RNR7RMR6RL(RTtprofile_config((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRSs  ( RhRiRERXtPopenRVRRQRRS(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR\s   R:cBs&eZdZdZdZdZRS(siam-roletEc2InstanceMetadatacCs ||_dS(N(t _role_fetcher(RTR#((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRVscCsX|j}|j}|sdStjd|dtj|d|jd|j}|S(Ns#Found credentials from IAM Role: %st role_nameRR(Rftretrieve_iam_role_credentialsR7RBRCRRRE(RTtfetcherRR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR s      (RhRiRERKRVR(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR:s R8cBs\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(R7Rtenviront_build_mappingt_mapping(RTRqRF((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRV(s   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(R7RRqRt_environt_parser(RTRqtparser((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRVs      cCsd|jkrtjj|jd}|j|}|j|krtjd||j}||j}t ||d|j SndSdS(sN Search for a credential file used by original EC2 CLI tools. Rs)Found credentials in AWS_CREDENTIAL_FILE.RN( RRRRRRtRBR|RuR|RER7(RTRRRR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs    N( RhRiRERKt CRED_FILE_ENVRtRuR7RVR(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR?sR_cBsMeZdZdZdZdZddgZd d dZdZ dZ RS( sshared-credentials-filetSharedCredentialsR7R8taws_security_tokenR9cCsO||_|dkrd}n||_|dkrBtjj}n||_dS(NR(t_creds_filenameR7RLRt configloadertraw_config_parset _ini_parser(RTR^R/t ini_parser((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRVs     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( RRR R7RLRtRBR|RJRut_get_session_tokenR|RE(RTtavailable_credsR'RRR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs    cCs,x%|jD]}||kr ||Sq WdS(N(Rv(RTR't token_envvar((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs N( RhRiRERKRtRuRvR7RVRR(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR_s  RccBsPeZdZdZdZdZdZddgZd dZ dZ d Z RS( s0INI based config provider with profile sections.s config-filet SharedConfigR7R8RR9cCs:||_||_|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_filenameRLR7RRR*t_config_parser(RTRbR/t config_parser((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRVs   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. Rbs$Credentials found in config file: %sRN( RRR R7RLRtRBR|RJRuRR|RE(RTR+RcRRR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs    cCs,x%|jD]}||kr ||Sq WdS(N(Rv(RTRct token_name((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs N( RhRiRjRERKRtRuRvR7RVRR(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRcs   R@cBsJeZdZdZdZddgZdZdZd d dZ dZ RS( s boto-configt Boto2Configt BOTO_CONFIGs /etc/boto.cfgs~/.botoR7R8cCsI|dkrtj}n|dkr3tjj}n||_||_dS(N(R7RRqRRRRR(RTRqR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRVs     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. R|s)Found credentials in boto config file: %sRN( tBOTO_CONFIG_ENVRtDEFAULT_CONFIG_FILENAMESRR RtRBR|RJRuR|RE(RTtpotential_locationsRR'RRR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR&s"       N( RhRiRERKRRRtRuR7RVR(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR@s R<cBseZdZdZdZdZdZejdddZ 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(RMRRLt _prompterRNt_credential_sourcert_profile_provider_buildert_visited_profiles(RTR*R.R(R/tprompterR0R1((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRVNs$        cCs\|j|_|jjdi}|j|ji}|j|rX|j|jSdS(NRb(RMRNR6RLt_has_assume_role_config_varst_load_creds_via_assume_role(RTRbR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs cCs|j|ko|j|kS(N(tROLE_CONFIG_VARtWEB_IDENTITY_TOKE_FILE_VAR(RTR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRsc CsA|j|}|j||}i}|jd}|dk rO||d/s(R(RTRt static_keys((Rs5/usr/lib/fence-agents/bundled/botocore/credentials.pyR-s cCsR|jd}|dk r+|j||S|d}|jj||j|S(NRR(R6R7t _resolve_credentials_from_sourceRRDt!_resolve_credentials_from_profile(RTRR/RR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR1s   cCs|jjdi}||}|j|rE|j rE|j|S|j|sd|j| r|jjd|dt}t|}|j }|dkrd}t d||n|S|j |S(NRbR/R2s.The source profile "%s" must have credentials.R( RNR6RRt(_resolve_static_credentials_from_profileRR3RRDRlR7R R(RTR/RbRRLt profile_chainRt error_message((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR<s$        cCsfy.td|dd|dd|jdSWn1tk ra}td|jdt|nXdS( NRR7RR8RR9RRC(R|R6RR REtstr(RTRRa((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRZs  cCs>|jj|}|dkr:td|dd|n|S(NRRsBNo credentials found in credential_source referenced in profile %s(RR*R7R(RTRR/R((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRes    Ni(RhRiRER7RKRRtEXPIRY_WINDOW_SECONDSR)RVRRRRRRRRRRRR(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR<?s&  5  , 2  &   RdcBsneZdZd 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(RMRRLR7t_profile_configt_disable_env_varsRt_token_loader_cls(RTR*R.R/R(R2ttoken_loader_cls((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRV}s        cCs |jS(N(t_assume_role_with_web_identity(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRscCsX|jdkrH|j}|jdi}|j|ji|_n|jj|S(NRb(RR7RMR6RL(RTtkeyt loaded_configRb((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt_get_profile_configs  cCsC|jr dS|jj|}|r?|tjkr?tj|SdS(N(RR7t_CONFIG_TO_ENV_VARR6RRq(RTRtenv_key((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt_get_env_configs   cCs,|j|}|dk r|S|j|S(N(RR7R(RTRt env_value((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt _get_configs c Cs|jd}|sdS|j|}|jd}|sUd}td|ni}|jd}|dk r||dcBs>eZdZdZdZdZdZdZRS(cCs ||_dS(N(t _providers(RTR3((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRVscCs#|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. (RRK(RTt source_nameR^((s5/usr/lib/fence-agents/bundled/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_providerRqRDRlR(RTRtsource((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR*s  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_methodR7RDR (RTtcanonical_nameRRJ((s5/usr/lib/fence-agents/bundled/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(RRKR(RTRRR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs cCs+x$|jD]}|j|kr |Sq WdS(s0Return a credential provider by its METHOD name.N(RRE(RTRR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs(RhRiRVRR*RRR(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR>s    & R9cBsbeZdZdZdZdZdZd 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(R7RRqRRt_fetcher(RTRqRi((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRV,s      cCs2|j|jks$|j|jkr.|jSdS(N(tENV_VARRt ENV_VAR_FULLt_retrieve_or_fail(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR4s$c Cs|jr+|jj|j|j}n|j|j}|j}|j||}|}td|dd|dd|dd|j dt |dd|S(NRRRRRR( t_provided_relative_uriRtfull_urlRRRt_build_headerst_create_fetcherRRERs(RTtfull_uritheadersRiR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR:s       cCs0|jj|j}|dk r,i|d6SdS(Nt Authorization(RR6tENV_VAR_AUTH_TOKENR7(RTt auth_token((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRKs csfd}|S(Ncsyjjd}WnGtk re}tjd|dttdjdt|nXi|dd6|dd 6|d d 6|d d 6S(NRs'Error retrieving container metadata: %sRRRR}RR~RtTokenRRR( Rtretrieve_full_uriRRBRCRRRER(RRa(RRRT(s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt fetch_credsSs    ((RTRRR((RRRTs5/usr/lib/fence-agents/bundled/botocore/credentials.pyRRscCs|j|jkS(N(RR(RT((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyResN(RhRiRERKRRRR7RVRRRRR(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR9%s    RDcBsGeZdZdZdZdZdZdZdZRS(cCs ||_dS(sQ :param providers: A list of ``CredentialProvider`` instances. N(R3(RTR3((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRVjscCsfy,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(R3REtindexRR tinsert(RTRtcredential_providerR^toffset((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt insert_beforers , 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_offsetR3R(RTRRR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt insert_afterscCsRg|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(R3RERtpop(RTRR^tavailable_methodsR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRAs  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. (R3R(RTR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt get_providers cCsQy*g|jD]}|j^q j|SWn tk rLtd|nXdS(NR(R3RERRR (RTRR^((s5/usr/lib/fence-agents/bundled/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(R3RBRCRERR7(RTRR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRls   ( RhRiRVRRRARRRl(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRDis     tSSOCredentialFetchercBs;eZdZddddZdZdZdZRS(s%Y-%m-%dT%H:%M:%SZc CsS||_||_||_||_||_||_tt|j||dS(N( Rt _sso_regiont _role_namet _account_idt _start_urlt _token_loaderRRRV( RTt start_urlt sso_regionRgt account_idR.RR(R((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRVs      cCsgi|jd6|jd6|jd6}tj|dtdd }t|jdj}|j |S( sCreate a predictable cache key for the current configuration. The cache key is intended to be compatible with file names. tstartUrltroleNamet accountIdR t separatorst,Rsutf-8(R R( RRRRRRRR"R#R(RTR$R%((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs   cCs2|d}tjj|t}|j|jS(Ng@@(Rnt fromtimestampRRut_UTC_DATE_FORMAT(RTt timestamp_msttimestamp_secondst timestamp((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyt_parse_timestamps cCstdtd|j}|jdd|}i|jd6|jd6|j|jd6}y|j|}Wn |j j k rt nX|d}idd 6i|d d 6|d d 6|dd6|j |dd6d6}|S(s4Get credentials by calling SSO get role credentials.R>R)tssoR'RRt accessTokentroleCredentialst ProviderTypet accessKeyIdR}tsecretAccessKeyR~t sessionTokenRRRR|( R RRRRRRRtget_role_credentialst exceptionstUnauthorizedExceptionRR(RTR'RRzRR((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyR s*        N(RhRiR R7RVRRR (((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRs   RfcBsheZdZejjejjddddZddddgZd d dZ d Z d Z RS( RRs.awsR(t sso_start_urlRt sso_role_nametsso_account_idcCsd|dkrt|j}n||_|dkr<i}n||_||_||_||_dS(N(R7Rt_SSO_TOKEN_CACHE_DIRt _token_cacheR(RMRRL(RTR*R.R/R(Re((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRV"s       cs|j}|jdi}|j}|j|jitfd|jDr_dSi}g}x;|jD]0}|kr|||4ss, RsSThe profile "%s" is configured to use SSO but is missing required configuration: %s( RMR6RLtallt_SSO_CONFIG_VARSR7RDRR (RTRRbR/R'tmissing_config_varst config_vartmissing((Rcs5/usr/lib/fence-agents/bundled/botocore/credentials.pyt_load_sso_config.s$   c Csu|j}|sdSt|d|d|d|d|jdtd|jd|j}td|jd|j S( NRRRRRR(RR( R&R7RRRRR(RRER (RTt sso_configt sso_fetcher((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRJs    N( RhRiRERRRRRR"R7RVR&R(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyRfs   (SRRntloggingRR)RRRXt collectionsRtcopyRthashlibRtdateutil.parserRt dateutil.tzRRtbotocore.configloaderRtbotocore.compatRRRtbotocore.configR tbotocore.exceptionsR R R R RRRRRtbotocore.utilsRRRRRRt getLoggerRhRBRR7RORR;RmRpRsRkRwR=RRRR|RRRRR&R;RBR\R:R8R?R_RcR@R<RdR>R9RDRRf(((s5/usr/lib/fence-agents/bundled/botocore/credentials.pyts          VD      ;'E1P8-Ft"*7*6YXDdH