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


Python botocore.session方法代码示例

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


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

示例1: get_iam_username

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def get_iam_username(cls):
        if cls._default_iam_username is None:
            try:
                user = resources.iam.CurrentUser().user
                cls._default_iam_username = getattr(user, "name", ARN(user.arn).resource.split("/")[-1])
            except Exception as e:
                try:
                    if "Must specify userName" in str(e) or ("assumed-role" in str(e) and "botocore-session" in str(e)):
                        cur_session = boto3.Session()._session
                        src_profile = cur_session.full_config["profiles"][cur_session.profile]["source_profile"]
                        src_session = boto3.Session(profile_name=src_profile)
                        cls._default_iam_username = src_session.resource("iam").CurrentUser().user.name
                    else:
                        caller_arn = ARN(clients.sts.get_caller_identity()["Arn"])
                        cls._default_iam_username = caller_arn.resource.split("/")[-1]
                except Exception:
                    cls._default_iam_username = "unknown"
        return cls._default_iam_username 
开发者ID:kislyuk,项目名称:aegea,代码行数:20,代码来源:__init__.py

示例2: _get_botocore_session

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def _get_botocore_session():
    if _get_botocore_session.botocore_session is None:
        LOG.debug('Creating new Botocore Session')
        LOG.debug('Botocore version: {0}'.format(botocore.__version__))
        session = botocore.session.get_session({
            'profile': (None, _profile_env_var, _profile, None),
        })
        session.set_config_variable('region', _region_name)
        session.set_config_variable('profile', _profile)
        session.register_component('data_loader', _get_data_loader())
        _set_user_agent_for_session(session)
        _get_botocore_session.botocore_session = session
        if _debug:
            session.set_debug_logger()

    return _get_botocore_session.botocore_session 
开发者ID:QData,项目名称:deepWordBug,代码行数:18,代码来源:aws.py

示例3: handle_argquery

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def handle_argquery(parsed_args) -> int:
    """Processes the arguments for the argquery subcommand and executes related tasks"""
    session = _grab_session(parsed_args)
    graph = principalmapper.graphing.graph_actions.get_existing_graph(session, parsed_args.account, parsed_args.debug)

    # process condition args to generate input dict
    conditions = {}
    if parsed_args.condition is not None:
        for arg in parsed_args.condition:
            # split on equals-sign (=), assume first instance separates the key and value
            components = arg.split('=')
            if len(components) < 2:
                print('Format for condition args not matched: <key>=<value>')
                return 64
            key = components[0]
            value = '='.join(components[1:])
            conditions.update({key: value})

    query_actions.argquery(graph, parsed_args.principal, parsed_args.action, parsed_args.resource, conditions,
                           parsed_args.preset, parsed_args.skip_admin, sys.stdout, parsed_args.debug)

    return 0 
开发者ID:nccgroup,项目名称:PMapper,代码行数:24,代码来源:__main__.py

示例4: __init__

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def __init__(self, password_prompter, requests_session=None):
        """Retrieve SAML assertion using form based auth.

        This class can retrieve a SAML assertion by using form
        based auth.  The supported workflow is:

            * Make a GET request to ``saml_endpoint``
            * Parse the HTML to look for an HTML form
            * Fill in the form data with the username, password
            * Make a POST request to the URL indicated by the form
              action with the filled in form data.
            * Parse the HTML returned from the service and
              extract out the SAMLAssertion.

        :param password_prompter: A function that takes a prompt string and
            returns a password string.

        :param requests_session: A requests session object used to make
            requests to the saml provider.
        """
        if requests_session is None:
            requests_session = requests.Session()
        self._requests_session = requests_session
        self._password_prompter = password_prompter 
开发者ID:awslabs,项目名称:awsprocesscreds,代码行数:26,代码来源:saml.py

示例5: test_session

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def test_session(region_name, service_name, make_test_session):
    """Test Session creation."""
    localstack = make_test_session(region_name=region_name)

    ls_session = localstack.botocore.session()
    assert isinstance(ls_session, localstack_botocore.Session)

    if hasattr(localstack, "_container"):
        with pytest.raises(exceptions.ContainerNotStartedError):
            # Can't create clients until the container is started,
            # because the client needs to know what port its
            # target service is running on.
            bc_client = ls_session.create_client(service_name, localstack.region_name)

    with localstack:  # Start container.
        bc_client = ls_session.create_client(service_name, localstack.region_name)
        assert isinstance(bc_client, botocore.client.BaseClient)
        assert "127.0.0.1" in bc_client._endpoint.host 
开发者ID:mintel,项目名称:pytest-localstack,代码行数:20,代码来源:test_botocore.py

示例6: make_session

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def make_session(identity_profile):
    session = botocore.session.Session(profile=identity_profile)
    try:
        session3 = boto3.session.Session(botocore_session=session)
    except botocore.exceptions.ProfileNotFound as err:
        print(str(err), file=sys.stderr)
        if session.available_profiles:
            print("Available profiles: %s" %
                  ", ".join(sorted(session.available_profiles)),
                  file=sys.stderr)
            print("You can specify a profile by passing it with the -i "
                  "command line flag.", file=sys.stderr)
        else:
            print("You have no AWS profiles configured. Please run 'aws "
                  "configure --profile identity' to get started.",
                  file=sys.stderr)
        return None, None, USER_RECOVERABLE_ERROR
    return session, session3, None 
开发者ID:dcoker,项目名称:awsmfa,代码行数:20,代码来源:__main__.py

示例7: __init__

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def __init__(self, session=None, api_policy_actions=None,
                 custom_policy_actions=None):
        # type: (Any, APIPolicyT, CustomPolicyT) -> None
        if session is None:
            session = botocore.session.get_session()
        # The difference between api_policy_actions and custom_policy_actions
        # is that api_policy_actions correspond to the 1-1 method to API calls
        # exposed in boto3/botocore clients whereas custom_policy_actions
        # correspond to method names that represent high level abstractions
        # that are typically hand written (e.g s3.download_file()).  These
        # are kept as separate files because we manage these files
        # separately.
        if api_policy_actions is None:
            api_policy_actions = load_api_policy_actions()
        if custom_policy_actions is None:
            custom_policy_actions = load_custom_policy_actions()
        self._session = session
        self._api_policy_actions = api_policy_actions
        self._custom_policy_actions = custom_policy_actions 
开发者ID:aws,项目名称:chalice,代码行数:21,代码来源:policy.py

示例8: get_region

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def get_region(cls):
        if cls._default_region is None:
            cls._default_region = botocore.session.Session().get_config_variable("region")
        return cls._default_region

    # TODO: for these two methods, introspect instance metadata without hanging if API not available 
开发者ID:kislyuk,项目名称:aegea,代码行数:8,代码来源:__init__.py

示例9: test_set_status_code

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def test_set_status_code():
    resp = ClientResponseProxy(
        'GET', URL('http://foo/bar'),
        loop=asyncio.get_event_loop(),
        writer=None, continue100=None, timer=None,
        request_info=None,
        traces=None,
        session=None)
    resp.status_code = 500
    assert resp.status_code == 500 
开发者ID:aio-libs,项目名称:aiobotocore,代码行数:12,代码来源:test_patches.py

示例10: __init__

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
                 aws_session_token=None, region_name=None,
                 botocore_session=None, profile_name=None):
        if botocore_session is not None:
            self._session = botocore_session
        else:
            # Create a new default session
            self._session = botocore.session.get_session()

        # Setup custom user-agent string if it isn't already customized
        if self._session.user_agent_name == 'Botocore':
            botocore_info = 'Botocore/{0}'.format(
                self._session.user_agent_version)
            if self._session.user_agent_extra:
                self._session.user_agent_extra += ' ' + botocore_info
            else:
                self._session.user_agent_extra = botocore_info
            self._session.user_agent_name = 'Boto3'
            self._session.user_agent_version = boto3.__version__

        if profile_name is not None:
            self._session.set_config_variable('profile', profile_name)

        if aws_access_key_id or aws_secret_access_key or aws_session_token:
            self._session.set_credentials(
                aws_access_key_id, aws_secret_access_key, aws_session_token)

        if region_name is not None:
            self._session.set_config_variable('region', region_name)

        self.resource_factory = ResourceFactory(
            self._session.get_component('event_emitter'))
        self._setup_loader()
        self._register_default_handlers() 
开发者ID:skarlekar,项目名称:faces,代码行数:36,代码来源:session.py

示例11: events

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def events(self):
        """
        The event emitter for a session
        """
        return self._session.get_component('event_emitter') 
开发者ID:skarlekar,项目名称:faces,代码行数:7,代码来源:session.py

示例12: available_profiles

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def available_profiles(self):
        """
        The profiles available to the session credentials
        """
        return self._session.available_profiles 
开发者ID:skarlekar,项目名称:faces,代码行数:7,代码来源:session.py

示例13: get_credentials

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [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.
        """
        return self._session.get_credentials() 
开发者ID:skarlekar,项目名称:faces,代码行数:11,代码来源:session.py

示例14: set_profile

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def set_profile(profile):
    global _profile, _api_clients
    _profile = profile

    # Invalidate session and old clients
    _get_botocore_session.botocore_session = None
    _api_clients = {} 
开发者ID:QData,项目名称:deepWordBug,代码行数:9,代码来源:aws.py

示例15: set_region

# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import session [as 别名]
def set_region(region_name):
    global _region_name
    _region_name = region_name

    # Invalidate session and old clients
    _get_botocore_session.botocore_session = None 
开发者ID:QData,项目名称:deepWordBug,代码行数:8,代码来源:aws.py


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