當前位置: 首頁>>代碼示例>>Python>>正文


Python session.get_credentials方法代碼示例

本文整理匯總了Python中botocore.session.get_credentials方法的典型用法代碼示例。如果您正苦於以下問題:Python session.get_credentials方法的具體用法?Python session.get_credentials怎麽用?Python session.get_credentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在botocore.session的用法示例。


在下文中一共展示了session.get_credentials方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: check_aws_credentials

# 需要導入模塊: from botocore import session [as 別名]
# 或者: from botocore.session import get_credentials [as 別名]
def check_aws_credentials():
    session = botocore.session.get_session()
    session.get_credentials().access_key
    session.get_credentials().secret_key 
開發者ID:Alephbet,項目名稱:gimel,代碼行數:6,代碼來源:aws_api.py

示例2: _get_presigned_url

# 需要導入模塊: from botocore import session [as 別名]
# 或者: from botocore.session import get_credentials [as 別名]
def _get_presigned_url(self, cluster_name, role_arn):
        session = self._session_handler.get_session(
            self._region_name,
            role_arn
        )

        if self._region_name is None:
            self._region_name = session.get_config_variable('region')

        loader = botocore.loaders.create_loader()
        data = loader.load_data("endpoints")
        endpoint_resolver = botocore.regions.EndpointResolver(data)
        endpoint = endpoint_resolver.construct_endpoint(
            AUTH_SERVICE,
            self._region_name
        )
        signer = RequestSigner(
            ServiceId(AUTH_SERVICE),
            self._region_name,
            AUTH_SERVICE,
            AUTH_SIGNING_VERSION,
            session.get_credentials(),
            session.get_component('event_emitter')
        )
        action_params='Action=' + AUTH_COMMAND + '&Version=' + AUTH_API_VERSION
        params = {
            'method': 'GET',
            'url': 'https://' + endpoint["hostname"] + '/?' + action_params,
            'body': {},
            'headers': {CLUSTER_NAME_HEADER: cluster_name},
            'context': {}
        }

        url=signer.generate_presigned_url(
            params,
            region_name=endpoint["credentialScope"]["region"],
            operation_name='',
            expires_in=URL_TIMEOUT
        )
        return url 
開發者ID:gkrizek,項目名稱:bash-lambda-layer,代碼行數:42,代碼來源:get_token.py

示例3: _get_credentials

# 需要導入模塊: from botocore import session [as 別名]
# 或者: from botocore.session import get_credentials [as 別名]
def _get_credentials():
    log.write("Refreshing credentials.")
    session = botocore.session.Session()
    credentials = session.get_credentials()
    return {
        "AWS_ACCESS_KEY_ID": credentials.access_key,
        "AWS_SECRET_ACCESS_KEY": credentials.secret_key,
        "AWS_SESSION_TOKEN": credentials.token,
        "AWS_DEFAULT_REGION": session.create_client("s3").meta.region_name
    } 
開發者ID:chanzuckerberg,項目名稱:idseq-dag,代碼行數:12,代碼來源:s3.py

示例4: load_aws_config

# 需要導入模塊: from botocore import session [as 別名]
# 或者: from botocore.session import get_credentials [as 別名]
def load_aws_config(access_key, secret_key, security_token, credentials_path, profile):
    # type: (str, str, str, str, str) -> Tuple[str, str, str]
    """
    Load aws credential configuration, by parsing credential file, then try to fall back to
    botocore, by checking (access_key,secret_key) are not (None,None)
    """
    if access_key is None or secret_key is None:
        try:
            exists = os.path.exists(credentials_path)
            __log('Credentials file \'{0}\' exists \'{1}\''.format(credentials_path, exists))

            config = configparser.ConfigParser()
            config.read(credentials_path)

            while True:
                if access_key is None and config.has_option(profile, "aws_access_key_id"):
                    access_key = config.get(profile, "aws_access_key_id")
                else:
                    break

                if secret_key is None and config.has_option(profile, "aws_secret_access_key"):
                    secret_key = config.get(profile, "aws_secret_access_key")
                else:
                    break

                if security_token is None and config.has_option(profile, "aws_session_token"):
                    security_token = config.get(profile, "aws_session_token")

                break

        except configparser.NoSectionError as exception:
            __log('AWS profile \'{0}\' not found'.format(exception.args))
            raise exception
        except configparser.NoOptionError as exception:
            __log('AWS profile \'{0}\' is missing \'{1}\''.format(profile, exception.args))
            raise exception
        except ValueError as exception:
            __log(exception)
            raise exception

    # try to load instance credentials using botocore
    if access_key is None or secret_key is None:
        try:
            __log("loading botocore package")
            import botocore
        except ImportError:
            __log("botocore package could not be loaded")
            botocore = None

        if botocore:
            import botocore.session
            session = botocore.session.get_session()
            cred = session.get_credentials()
            access_key, secret_key, security_token = cred.access_key, cred.secret_key, cred.token

    return access_key, secret_key, security_token 
開發者ID:okigan,項目名稱:awscurl,代碼行數:58,代碼來源:awscurl.py


注:本文中的botocore.session.get_credentials方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。