当前位置: 首页>>代码示例>>Python>>正文


Python botocore.credentials方法代码示例

本文整理汇总了Python中botocore.credentials方法的典型用法代码示例。如果您正苦于以下问题:Python botocore.credentials方法的具体用法?Python botocore.credentials怎么用?Python botocore.credentials使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在botocore的用法示例。


在下文中一共展示了botocore.credentials方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mock_session

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import credentials [as 别名]
def mock_session(region = None, available_profiles = None, credentials = DEFAULT_CREDS, resolver = mock_resolver):

  def decorator(func):
    session = Mock()
    session.get_config_variable.return_value = region
    session.available_profiles = available_profiles
    session.get_credentials.return_value = credentials
    session.get_available_partitions.return_value = get_available_partitions()
    session.get_available_regions.side_effect = get_available_regions
    session.get_component.return_value = resolver


    @functools.wraps(func)
    def wrapped(*args, **kwargs):
      with patch('botocore.session.Session', Mock(return_value = session)):
        with patch('awscli.plugin.load_plugins', Mock()):
          func(*args, **kwargs)

    return wrapped

  return decorator 
开发者ID:aws,项目名称:git-remote-codecommit,代码行数:23,代码来源:context_test.py

示例2: set_credentials

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import credentials [as 别名]
def set_credentials(self, access_key, secret_key, token=None):
        """
        Manually create credentials for this session.  If you would
        prefer to use botocore without a config file, environment variables,
        or IAM roles, you can pass explicit credentials into this
        method to establish credentials for this session.

        :type access_key: str
        :param access_key: The access key part of the credentials.

        :type secret_key: str
        :param secret_key: The secret key part of the credentials.

        :type token: str
        :param token: An option session token used by STS session
            credentials.
        """
        self._credentials = botocore.credentials.Credentials(access_key,
                                                             secret_key,
                                                             token) 
开发者ID:skarlekar,项目名称:faces,代码行数:22,代码来源:session.py

示例3: _register_credential_provider

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import credentials [as 别名]
def _register_credential_provider(self):
        self._components.lazy_register_component(
            'credential_provider',
            lambda:  botocore.credentials.create_credential_resolver(self)) 
开发者ID:skarlekar,项目名称:faces,代码行数:6,代码来源:session.py

示例4: full_config

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import credentials [as 别名]
def full_config(self):
        """Return the parsed config file.

        The ``get_config`` method returns the config associated with the
        specified profile.  This property returns the contents of the
        **entire** config file.

        :rtype: dict
        """
        if self._config is None:
            try:
                config_file = self.get_config_variable('config_file')
                self._config = botocore.configloader.load_config(config_file)
            except ConfigNotFound:
                self._config = {'profiles': {}}
            try:
                # Now we need to inject the profiles from the
                # credentials file.  We don't actually need the values
                # in the creds file, only the profile names so that we
                # can validate the user is not referring to a nonexistent
                # profile.
                cred_file = self.get_config_variable('credentials_file')
                cred_profiles = botocore.configloader.raw_config_parse(
                    cred_file)
                for profile in cred_profiles:
                    cred_vars = cred_profiles[profile]
                    if profile not in self._config['profiles']:
                        self._config['profiles'][profile] = cred_vars
                    else:
                        self._config['profiles'][profile].update(cred_vars)
            except ConfigNotFound:
                pass
        return self._config 
开发者ID:skarlekar,项目名称:faces,代码行数:35,代码来源:session.py

示例5: get_credentials

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import credentials [as 别名]
def get_credentials(self):
        """
        Return the :class:`botocore.credential.Credential` object
        associated with this session.  If the credentials have not
        yet been loaded, this will attempt to load them.  If they
        have already been loaded, this will return the cached
        credentials.

        """
        if self._credentials is None:
            self._credentials = self._components.get_component(
                'credential_provider').load_credentials()
        return self._credentials 
开发者ID:skarlekar,项目名称:faces,代码行数:15,代码来源:session.py

示例6: __init__

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import credentials [as 别名]
def __init__(self, service, operation, region_name, endpoint_url=None, session=None,
                 connect_timeout=None, request_timeout=None):
        # set credentials manually
        session = session or botocore.session.get_session()
        # get_session accepts access_key, secret_key
        self.client = session.create_client(
            service,
            region_name=region_name,
            endpoint_url=endpoint_url
        )
        try:
            self.endpoint = self.client.endpoint
        except AttributeError:
            self.endpoint = self.client._endpoint

        self.operation = operation
        self.http_client = AsyncHTTPClient()

        self.proxy_host = None
        self.proxy_port = None
        https_proxy = getproxies_environment().get('https')
        if https_proxy:
            self._enable_curl_httpclient()

            proxy_parts = https_proxy.split(':')
            if len(proxy_parts) == 2 and proxy_parts[-1].isdigit():
                self.proxy_host, self.proxy_port = proxy_parts
                self.proxy_port = int(self.proxy_port)
            else:
                proxy = urlparse(https_proxy)
                self.proxy_host = proxy.hostname
                self.proxy_port = proxy.port

        self.request_timeout = request_timeout
        self.connect_timeout = connect_timeout 
开发者ID:nanvel,项目名称:tornado-botocore,代码行数:37,代码来源:base.py

示例7: _aws_credentials_available_in_metadata_service

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import credentials [as 别名]
def _aws_credentials_available_in_metadata_service():
    """Placeholder docstring"""
    import botocore
    from botocore.credentials import InstanceMetadataProvider
    from botocore.utils import InstanceMetadataFetcher

    session = botocore.session.Session()
    instance_metadata_provider = InstanceMetadataProvider(
        iam_role_fetcher=InstanceMetadataFetcher(
            timeout=session.get_config_variable("metadata_service_timeout"),
            num_attempts=session.get_config_variable("metadata_service_num_attempts"),
            user_agent=session.user_agent(),
        )
    )
    return not instance_metadata_provider.load() is None 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:17,代码来源:image.py

示例8: _get_credentials

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import credentials [as 别名]
def _get_credentials(self):
        kwargs = self._get_assume_role_kwargs()
        client = self._create_client()
        logger.info(
            'Retrieving credentials with STS.AssumeRoleWithSaml() using the '
            'following parameters: %s', kwargs
        )
        response = deepcopy(client.assume_role_with_saml(**kwargs))
        expiration = response['Credentials']['Expiration'].isoformat()
        response['Credentials']['Expiration'] = expiration
        return response 
开发者ID:awslabs,项目名称:awsprocesscreds,代码行数:13,代码来源:saml.py

示例9: __init__

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import credentials [as 别名]
def __init__(self, settings, aws_access_key_id=None, aws_secret_access_key=None, \
            httpdownloadhandler=HTTPDownloadHandler, **kw):

        if not aws_access_key_id:
            aws_access_key_id = settings['AWS_ACCESS_KEY_ID']
        if not aws_secret_access_key:
            aws_secret_access_key = settings['AWS_SECRET_ACCESS_KEY']

        # If no credentials could be found anywhere,
        # consider this an anonymous connection request by default;
        # unless 'anon' was set explicitly (True/False).
        anon = kw.get('anon')
        if anon is None and not aws_access_key_id and not aws_secret_access_key:
            kw['anon'] = True
        self.anon = kw.get('anon')

        self._signer = None
        if is_botocore():
            import botocore.auth
            import botocore.credentials
            kw.pop('anon', None)
            if kw:
                raise TypeError('Unexpected keyword arguments: %s' % kw)
            if not self.anon:
                SignerCls = botocore.auth.AUTH_TYPE_MAPS['s3']
                self._signer = SignerCls(botocore.credentials.Credentials(
                    aws_access_key_id, aws_secret_access_key))
        else:
            _S3Connection = _get_boto_connection()
            try:
                self.conn = _S3Connection(
                    aws_access_key_id, aws_secret_access_key, **kw)
            except Exception as ex:
                raise NotConfigured(str(ex))

        self._download_http = httpdownloadhandler(settings).download_request 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:38,代码来源:s3.py


注:本文中的botocore.credentials方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。