当前位置: 首页>>代码示例>>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;未经允许,请勿转载。