We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Using botocore without config files, env vars or IAM roles
It's desirable to be able to use botocore entirely standalone - no reliance on configuration files, environment variables or IAM roles.

Currently, it's necessary to do something hacky like this:

```
session = botocore.session.get_session()
service = session.get_service('ec2')

# HACK manually set the botocore credentials object
session._credentials = botocore.credentials.Credentials(
    access_key=__opts__['AWS.id'],
    secret_key=__opts__['AWS.key'],
    )

endpoint = service.get_endpoint(region)
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `botocore/session.py`
Content:
```
1 # Copyright (c) 2012 Mitch Garnaat http://garnaat.org/
2 # Copyright 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining a
5 # copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish, dis-
8 # tribute, sublicense, and/or sell copies of the Software, and to permit
9 # persons to whom the Software is furnished to do so, subject to the fol-
10 # lowing conditions:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 # IN THE SOFTWARE.
22 #
23 """
24 This module contains the main interface to the botocore package, the
25 Session object.
26 """
27 
28 import logging
29 import platform
30 import os
31 import copy
32 import botocore.config
33 import botocore.credentials
34 import botocore.base
35 import botocore.service
36 from . import __version__
37 
38 
39 EnvironmentVariables = {
40     'profile': 'BOTO_DEFAULT_PROFILE',
41     'region': 'BOTO_DEFAULT_REGION',
42     'data_path': 'BOTO_DATA_PATH',
43     'config_file': 'AWS_CONFIG_FILE',
44     'access_key': 'AWS_ACCESS_KEY_ID',
45     'secret_key': 'AWS_SECRET_ACCESS_KEY'
46     }
47 """
48 A dictionary mapping logical names to specific environment variable
49 names.  When creating a new Session object, you can pass in your own
50 dictionary to remap the logical names to the environment variable names
51 you want to use for your application.  The logical variable names are:
52 
53 * profile - Default profile name you want to use.
54 * region - Default region name to use, if not otherwise specified.
55 * data_path - Additional directories to search for data files.
56 * config_file - Location of a Boto config file.
57 * access_key - The AWS access key part of your credentials.
58 * secret_key - The AWS secret key part of your credentials.
59 """
60 
61 
62 class Session(object):
63     """
64     The Session object collects together useful functionality
65     from `botocore` as well as important data such as configuration
66     information and credentials into a single, easy-to-use object.
67 
68     :ivar available_profiles: A list of profiles defined in the config
69         file associated with this session.
70     :ivar profile: The current profile.
71     """
72 
73     FmtString = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
74 
75     def __init__(self, env_vars=None):
76         """
77         Create a new Session object.
78 
79         :type env_vars: dict
80         :param env_vars: A dictionary that is used to override some or all
81             of the environment variables associated with this session.  The
82             key/value pairs defined in this dictionary will override the
83             corresponding variables defined in `EnvironmentVariables`.
84         """
85         self.env_vars = copy.copy(EnvironmentVariables)
86         if env_vars:
87             self.env_vars.update(env_vars)
88         self.user_agent_name = 'Boto'
89         self.user_agent_version = __version__
90         self._profile = os.environ.get(self.env_vars['profile'], 'default')
91         self._config = None
92         self._credentials = None
93 
94     @property
95     def available_profiles(self):
96         profiles = []
97         self.get_config()
98         for key in self._config.keys():
99             if not key.startswith('_'):
100                 profiles.append(key)
101         return profiles
102 
103     @property
104     def profile(self):
105         return self._profile
106 
107     @profile.setter
108     def profile(self, profile):
109         if profile != self._profile:
110             self._credentials = None
111         self._profile = profile
112 
113     def get_envvar(self, logical_name):
114         """
115         Retrieve the value associated with the specified logical_name
116         from the environment.
117 
118         :type logical_name: str
119         :param logical_name: The logical name of the environment variable
120             you want to retrieve.  This name will be mapped to the
121             appropriate environment variable name for this session.
122 
123             * profile - Default profile name you want to use.
124             * region - Default region name to use, if not otherwise specified.
125             * data_path - Additional directories to search for data files.
126             * config_file - Location of a Boto config file.
127             * access_key - The AWS access key part of your credentials.
128             * secret_key - The AWS secret key part of your credentials.
129 
130         :returns: str value of variable of None if not defined.
131         """
132         value = None
133         if logical_name in self.env_vars:
134             value = os.environ.get(self.env_vars[logical_name], None)
135         return value
136 
137     def get_config(self):
138         """
139         Returns the configuration associated with this session.  If
140         the configuration has not yet been loaded, it will be loaded
141         using the current `profile` attribute value.  If it has already been
142         loaded, the cached configuration will be returned.
143 
144         :raises: ConfigNotFound, ConfigParseError
145         """
146         if self._config is None:
147             self._config = botocore.config.get_config(self)
148         return self._config.get(self._profile, None)
149 
150     def get_credentials(self, metadata=None):
151         """
152         Return the :class:`botocore.credential.Credential` object
153         associated with this session.  If the credentials have not
154         yet been loaded, this will attempt to load them.  If they
155         have already been loaded, this will return the cached
156         credentials.
157 
158         :type metadata: dict
159         :param metadata: This parameter allows you to pass in
160             EC2 instance metadata containing IAM Role credentials.
161             This metadata will be used rather than retrieving the
162             metadata from the metadata service.  This is mainly used
163             for unit testing.
164         """
165         if self._credentials is None:
166             cfg = self.get_config()
167             self._credentials = botocore.credentials.get_credentials(cfg,
168                                                                      metadata)
169         return self._credentials
170 
171     def user_agent(self):
172         """
173         Return a string suitable for use as a User-Agent header.
174         The string will be of the form:
175 
176         <agent_name>/<agent_version> Python/<py_ver> <plat_name>/<plat_ver>
177 
178         Where:
179 
180          - agent_name is the value of the `user_agent_name` attribute
181            of the session object (`Boto` by default).
182          - agent_version is the value of the `user_agent_version`
183            attribute of the session object (the botocore version by default).
184            by default.
185          - py_ver is the version of the Python interpreter beng used.
186          - plat_name is the name of the platform (e.g. Darwin)
187          - plat_ver is the version of the platform
188 
189         """
190         return '%s/%s Python/%s %s/%s' % (self.user_agent_name,
191                                           self.user_agent_version,
192                                           platform.python_version(),
193                                           platform.system(),
194                                           platform.release())
195 
196     def get_data(self, data_path):
197         """
198         Retrieve the data associated with `data_path`.
199 
200         :type data_path: str
201         :param data_path: The path to the data you wish to retrieve.
202         """
203         return botocore.base.get_data(self, data_path)
204 
205     def get_service_data(self, service_name, provider_name='aws'):
206         """
207         Retrieve the fully merged data associated with a service.
208         """
209         return botocore.base.get_service_data(self, service_name,
210                                               provider_name)
211 
212     def get_service(self, service_name, provider_name='aws'):
213         """
214         Get information about a service.
215 
216         :type service_name: str
217         :param service_name: The name of the service (e.g. 'ec2')
218 
219         :type provider_name: str
220         :param provider_name: The name of the provider.  Defaults
221             to 'aws'.
222 
223         :returns: :class:`botocore.service.Service`
224         """
225         return botocore.service.get_service(self, service_name, provider_name)
226 
227     def set_debug_logger(self):
228         """
229         Convenience function to quickly configure full debug output
230         to go to the console.
231         """
232         log = logging.getLogger('botocore')
233         log.setLevel(logging.DEBUG)
234 
235         # create console handler and set level to debug
236         ch = logging.StreamHandler()
237         ch.setLevel(logging.DEBUG)
238 
239         # create formatter
240         formatter = logging.Formatter(self.FmtString)
241 
242         # add formatter to ch
243         ch.setFormatter(formatter)
244 
245         # add ch to logger
246         log.addHandler(ch)
247 
248     def set_file_logger(self, log_level, path):
249         """
250         Convenience function to quickly configure any level of logging
251         to a file.
252 
253         :type log_level: int
254         :param log_level: A log level as specified in the `logging` module
255 
256         :type path: string
257         :param path: Path to the log file.  The file will be created
258             if it doesn't already exist.
259         """
260         log = logging.getLogger('botocore')
261         log.setLevel(log_level)
262 
263         # create console handler and set level to debug
264         ch = logging.FileHandler(path)
265         ch.setLevel(log_level)
266 
267         # create formatter
268         formatter = logging.Formatter(self.FmtString)
269 
270         # add formatter to ch
271         ch.setFormatter(formatter)
272 
273         # add ch to logger
274         log.addHandler(ch)
275 
276 
277 def get_session(env_vars=None):
278     """
279     Return a new session  object.
280     """
281     return Session(env_vars)
282
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/botocore/session.py b/botocore/session.py
--- a/botocore/session.py
+++ b/botocore/session.py
@@ -147,6 +147,20 @@
             self._config = botocore.config.get_config(self)
         return self._config.get(self._profile, None)
 
+    def set_credentials(self, access_key, secret_key):
+        """
+        Create the :class:`botocore.credential.Credential` object
+        associated with this session using the supplied AccessKey and SecretKey
+
+        :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.
+        """
+        self._credentials = botocore.credentials.Credentials(access_key,
+                                                             secret_key)
+
     def get_credentials(self, metadata=None):
         """
         Return the :class:`botocore.credential.Credential` object

{"golden_diff": "diff --git a/botocore/session.py b/botocore/session.py\n--- a/botocore/session.py\n+++ b/botocore/session.py\n@@ -147,6 +147,20 @@\n             self._config = botocore.config.get_config(self)\n         return self._config.get(self._profile, None)\n \n+    def set_credentials(self, access_key, secret_key):\n+        \"\"\"\n+        Create the :class:`botocore.credential.Credential` object\n+        associated with this session using the supplied AccessKey and SecretKey\n+\n+        :type access_key: str\n+        :param access_key: The access key part of the credentials.\n+\n+        :type secret_key: str\n+        :param secret_key: The secret key part of the credentials.\n+        \"\"\"\n+        self._credentials = botocore.credentials.Credentials(access_key,\n+                                                             secret_key)\n+\n     def get_credentials(self, metadata=None):\n         \"\"\"\n         Return the :class:`botocore.credential.Credential` object\n", "issue": "Using botocore without config files, env vars or IAM roles\nIt's desirable to be able to use botocore entirely standalone - no reliance on configuration files, environment variables or IAM roles.\n\nCurrently, it's necessary to do something hacky like this:\n\n```\nsession = botocore.session.get_session()\nservice = session.get_service('ec2')\n\n# HACK manually set the botocore credentials object\nsession._credentials = botocore.credentials.Credentials(\n    access_key=__opts__['AWS.id'],\n    secret_key=__opts__['AWS.key'],\n    )\n\nendpoint = service.get_endpoint(region)\n```\n\n", "before_files": [{"content": "# Copyright (c) 2012 Mitch Garnaat http://garnaat.org/\n# Copyright 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n#\n# Permission is hereby granted, free of charge, to any person obtaining a\n# copy of this software and associated documentation files (the\n# \"Software\"), to deal in the Software without restriction, including\n# without limitation the rights to use, copy, modify, merge, publish, dis-\n# tribute, sublicense, and/or sell copies of the Software, and to permit\n# persons to whom the Software is furnished to do so, subject to the fol-\n# lowing conditions:\n#\n# The above copyright notice and this permission notice shall be included\n# in all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-\n# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT\n# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n# IN THE SOFTWARE.\n#\n\"\"\"\nThis module contains the main interface to the botocore package, the\nSession object.\n\"\"\"\n\nimport logging\nimport platform\nimport os\nimport copy\nimport botocore.config\nimport botocore.credentials\nimport botocore.base\nimport botocore.service\nfrom . import __version__\n\n\nEnvironmentVariables = {\n    'profile': 'BOTO_DEFAULT_PROFILE',\n    'region': 'BOTO_DEFAULT_REGION',\n    'data_path': 'BOTO_DATA_PATH',\n    'config_file': 'AWS_CONFIG_FILE',\n    'access_key': 'AWS_ACCESS_KEY_ID',\n    'secret_key': 'AWS_SECRET_ACCESS_KEY'\n    }\n\"\"\"\nA dictionary mapping logical names to specific environment variable\nnames.  When creating a new Session object, you can pass in your own\ndictionary to remap the logical names to the environment variable names\nyou want to use for your application.  The logical variable names are:\n\n* profile - Default profile name you want to use.\n* region - Default region name to use, if not otherwise specified.\n* data_path - Additional directories to search for data files.\n* config_file - Location of a Boto config file.\n* access_key - The AWS access key part of your credentials.\n* secret_key - The AWS secret key part of your credentials.\n\"\"\"\n\n\nclass Session(object):\n    \"\"\"\n    The Session object collects together useful functionality\n    from `botocore` as well as important data such as configuration\n    information and credentials into a single, easy-to-use object.\n\n    :ivar available_profiles: A list of profiles defined in the config\n        file associated with this session.\n    :ivar profile: The current profile.\n    \"\"\"\n\n    FmtString = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'\n\n    def __init__(self, env_vars=None):\n        \"\"\"\n        Create a new Session object.\n\n        :type env_vars: dict\n        :param env_vars: A dictionary that is used to override some or all\n            of the environment variables associated with this session.  The\n            key/value pairs defined in this dictionary will override the\n            corresponding variables defined in `EnvironmentVariables`.\n        \"\"\"\n        self.env_vars = copy.copy(EnvironmentVariables)\n        if env_vars:\n            self.env_vars.update(env_vars)\n        self.user_agent_name = 'Boto'\n        self.user_agent_version = __version__\n        self._profile = os.environ.get(self.env_vars['profile'], 'default')\n        self._config = None\n        self._credentials = None\n\n    @property\n    def available_profiles(self):\n        profiles = []\n        self.get_config()\n        for key in self._config.keys():\n            if not key.startswith('_'):\n                profiles.append(key)\n        return profiles\n\n    @property\n    def profile(self):\n        return self._profile\n\n    @profile.setter\n    def profile(self, profile):\n        if profile != self._profile:\n            self._credentials = None\n        self._profile = profile\n\n    def get_envvar(self, logical_name):\n        \"\"\"\n        Retrieve the value associated with the specified logical_name\n        from the environment.\n\n        :type logical_name: str\n        :param logical_name: The logical name of the environment variable\n            you want to retrieve.  This name will be mapped to the\n            appropriate environment variable name for this session.\n\n            * profile - Default profile name you want to use.\n            * region - Default region name to use, if not otherwise specified.\n            * data_path - Additional directories to search for data files.\n            * config_file - Location of a Boto config file.\n            * access_key - The AWS access key part of your credentials.\n            * secret_key - The AWS secret key part of your credentials.\n\n        :returns: str value of variable of None if not defined.\n        \"\"\"\n        value = None\n        if logical_name in self.env_vars:\n            value = os.environ.get(self.env_vars[logical_name], None)\n        return value\n\n    def get_config(self):\n        \"\"\"\n        Returns the configuration associated with this session.  If\n        the configuration has not yet been loaded, it will be loaded\n        using the current `profile` attribute value.  If it has already been\n        loaded, the cached configuration will be returned.\n\n        :raises: ConfigNotFound, ConfigParseError\n        \"\"\"\n        if self._config is None:\n            self._config = botocore.config.get_config(self)\n        return self._config.get(self._profile, None)\n\n    def get_credentials(self, metadata=None):\n        \"\"\"\n        Return the :class:`botocore.credential.Credential` object\n        associated with this session.  If the credentials have not\n        yet been loaded, this will attempt to load them.  If they\n        have already been loaded, this will return the cached\n        credentials.\n\n        :type metadata: dict\n        :param metadata: This parameter allows you to pass in\n            EC2 instance metadata containing IAM Role credentials.\n            This metadata will be used rather than retrieving the\n            metadata from the metadata service.  This is mainly used\n            for unit testing.\n        \"\"\"\n        if self._credentials is None:\n            cfg = self.get_config()\n            self._credentials = botocore.credentials.get_credentials(cfg,\n                                                                     metadata)\n        return self._credentials\n\n    def user_agent(self):\n        \"\"\"\n        Return a string suitable for use as a User-Agent header.\n        The string will be of the form:\n\n        <agent_name>/<agent_version> Python/<py_ver> <plat_name>/<plat_ver>\n\n        Where:\n\n         - agent_name is the value of the `user_agent_name` attribute\n           of the session object (`Boto` by default).\n         - agent_version is the value of the `user_agent_version`\n           attribute of the session object (the botocore version by default).\n           by default.\n         - py_ver is the version of the Python interpreter beng used.\n         - plat_name is the name of the platform (e.g. Darwin)\n         - plat_ver is the version of the platform\n\n        \"\"\"\n        return '%s/%s Python/%s %s/%s' % (self.user_agent_name,\n                                          self.user_agent_version,\n                                          platform.python_version(),\n                                          platform.system(),\n                                          platform.release())\n\n    def get_data(self, data_path):\n        \"\"\"\n        Retrieve the data associated with `data_path`.\n\n        :type data_path: str\n        :param data_path: The path to the data you wish to retrieve.\n        \"\"\"\n        return botocore.base.get_data(self, data_path)\n\n    def get_service_data(self, service_name, provider_name='aws'):\n        \"\"\"\n        Retrieve the fully merged data associated with a service.\n        \"\"\"\n        return botocore.base.get_service_data(self, service_name,\n                                              provider_name)\n\n    def get_service(self, service_name, provider_name='aws'):\n        \"\"\"\n        Get information about a service.\n\n        :type service_name: str\n        :param service_name: The name of the service (e.g. 'ec2')\n\n        :type provider_name: str\n        :param provider_name: The name of the provider.  Defaults\n            to 'aws'.\n\n        :returns: :class:`botocore.service.Service`\n        \"\"\"\n        return botocore.service.get_service(self, service_name, provider_name)\n\n    def set_debug_logger(self):\n        \"\"\"\n        Convenience function to quickly configure full debug output\n        to go to the console.\n        \"\"\"\n        log = logging.getLogger('botocore')\n        log.setLevel(logging.DEBUG)\n\n        # create console handler and set level to debug\n        ch = logging.StreamHandler()\n        ch.setLevel(logging.DEBUG)\n\n        # create formatter\n        formatter = logging.Formatter(self.FmtString)\n\n        # add formatter to ch\n        ch.setFormatter(formatter)\n\n        # add ch to logger\n        log.addHandler(ch)\n\n    def set_file_logger(self, log_level, path):\n        \"\"\"\n        Convenience function to quickly configure any level of logging\n        to a file.\n\n        :type log_level: int\n        :param log_level: A log level as specified in the `logging` module\n\n        :type path: string\n        :param path: Path to the log file.  The file will be created\n            if it doesn't already exist.\n        \"\"\"\n        log = logging.getLogger('botocore')\n        log.setLevel(log_level)\n\n        # create console handler and set level to debug\n        ch = logging.FileHandler(path)\n        ch.setLevel(log_level)\n\n        # create formatter\n        formatter = logging.Formatter(self.FmtString)\n\n        # add formatter to ch\n        ch.setFormatter(formatter)\n\n        # add ch to logger\n        log.addHandler(ch)\n\n\ndef get_session(env_vars=None):\n    \"\"\"\n    Return a new session  object.\n    \"\"\"\n    return Session(env_vars)\n", "path": "botocore/session.py"}], "after_files": [{"content": "# Copyright (c) 2012 Mitch Garnaat http://garnaat.org/\n# Copyright 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n#\n# Permission is hereby granted, free of charge, to any person obtaining a\n# copy of this software and associated documentation files (the\n# \"Software\"), to deal in the Software without restriction, including\n# without limitation the rights to use, copy, modify, merge, publish, dis-\n# tribute, sublicense, and/or sell copies of the Software, and to permit\n# persons to whom the Software is furnished to do so, subject to the fol-\n# lowing conditions:\n#\n# The above copyright notice and this permission notice shall be included\n# in all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-\n# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT\n# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n# IN THE SOFTWARE.\n#\n\"\"\"\nThis module contains the main interface to the botocore package, the\nSession object.\n\"\"\"\n\nimport logging\nimport platform\nimport os\nimport copy\nimport botocore.config\nimport botocore.credentials\nimport botocore.base\nimport botocore.service\nfrom . import __version__\n\n\nEnvironmentVariables = {\n    'profile': 'BOTO_DEFAULT_PROFILE',\n    'region': 'BOTO_DEFAULT_REGION',\n    'data_path': 'BOTO_DATA_PATH',\n    'config_file': 'AWS_CONFIG_FILE',\n    'access_key': 'AWS_ACCESS_KEY_ID',\n    'secret_key': 'AWS_SECRET_ACCESS_KEY'\n    }\n\"\"\"\nA dictionary mapping logical names to specific environment variable\nnames.  When creating a new Session object, you can pass in your own\ndictionary to remap the logical names to the environment variable names\nyou want to use for your application.  The logical variable names are:\n\n* profile - Default profile name you want to use.\n* region - Default region name to use, if not otherwise specified.\n* data_path - Additional directories to search for data files.\n* config_file - Location of a Boto config file.\n* access_key - The AWS access key part of your credentials.\n* secret_key - The AWS secret key part of your credentials.\n\"\"\"\n\n\nclass Session(object):\n    \"\"\"\n    The Session object collects together useful functionality\n    from `botocore` as well as important data such as configuration\n    information and credentials into a single, easy-to-use object.\n\n    :ivar available_profiles: A list of profiles defined in the config\n        file associated with this session.\n    :ivar profile: The current profile.\n    \"\"\"\n\n    FmtString = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'\n\n    def __init__(self, env_vars=None):\n        \"\"\"\n        Create a new Session object.\n\n        :type env_vars: dict\n        :param env_vars: A dictionary that is used to override some or all\n            of the environment variables associated with this session.  The\n            key/value pairs defined in this dictionary will override the\n            corresponding variables defined in `EnvironmentVariables`.\n        \"\"\"\n        self.env_vars = copy.copy(EnvironmentVariables)\n        if env_vars:\n            self.env_vars.update(env_vars)\n        self.user_agent_name = 'Boto'\n        self.user_agent_version = __version__\n        self._profile = os.environ.get(self.env_vars['profile'], 'default')\n        self._config = None\n        self._credentials = None\n\n    @property\n    def available_profiles(self):\n        profiles = []\n        self.get_config()\n        for key in self._config.keys():\n            if not key.startswith('_'):\n                profiles.append(key)\n        return profiles\n\n    @property\n    def profile(self):\n        return self._profile\n\n    @profile.setter\n    def profile(self, profile):\n        if profile != self._profile:\n            self._credentials = None\n        self._profile = profile\n\n    def get_envvar(self, logical_name):\n        \"\"\"\n        Retrieve the value associated with the specified logical_name\n        from the environment.\n\n        :type logical_name: str\n        :param logical_name: The logical name of the environment variable\n            you want to retrieve.  This name will be mapped to the\n            appropriate environment variable name for this session.\n\n            * profile - Default profile name you want to use.\n            * region - Default region name to use, if not otherwise specified.\n            * data_path - Additional directories to search for data files.\n            * config_file - Location of a Boto config file.\n            * access_key - The AWS access key part of your credentials.\n            * secret_key - The AWS secret key part of your credentials.\n\n        :returns: str value of variable of None if not defined.\n        \"\"\"\n        value = None\n        if logical_name in self.env_vars:\n            value = os.environ.get(self.env_vars[logical_name], None)\n        return value\n\n    def get_config(self):\n        \"\"\"\n        Returns the configuration associated with this session.  If\n        the configuration has not yet been loaded, it will be loaded\n        using the current `profile` attribute value.  If it has already been\n        loaded, the cached configuration will be returned.\n\n        :raises: ConfigNotFound, ConfigParseError\n        \"\"\"\n        if self._config is None:\n            self._config = botocore.config.get_config(self)\n        return self._config.get(self._profile, None)\n\n    def set_credentials(self, access_key, secret_key):\n        \"\"\"\n        Create the :class:`botocore.credential.Credential` object\n        associated with this session using the supplied AccessKey and SecretKey\n\n        :type access_key: str\n        :param access_key: The access key part of the credentials.\n\n        :type secret_key: str\n        :param secret_key: The secret key part of the credentials.\n        \"\"\"\n        self._credentials = botocore.credentials.Credentials(access_key,\n                                                             secret_key)\n\n    def get_credentials(self, metadata=None):\n        \"\"\"\n        Return the :class:`botocore.credential.Credential` object\n        associated with this session.  If the credentials have not\n        yet been loaded, this will attempt to load them.  If they\n        have already been loaded, this will return the cached\n        credentials.\n\n        :type metadata: dict\n        :param metadata: This parameter allows you to pass in\n            EC2 instance metadata containing IAM Role credentials.\n            This metadata will be used rather than retrieving the\n            metadata from the metadata service.  This is mainly used\n            for unit testing.\n        \"\"\"\n        if self._credentials is None:\n            cfg = self.get_config()\n            self._credentials = botocore.credentials.get_credentials(cfg,\n                                                                     metadata)\n        return self._credentials\n\n    def user_agent(self):\n        \"\"\"\n        Return a string suitable for use as a User-Agent header.\n        The string will be of the form:\n\n        <agent_name>/<agent_version> Python/<py_ver> <plat_name>/<plat_ver>\n\n        Where:\n\n         - agent_name is the value of the `user_agent_name` attribute\n           of the session object (`Boto` by default).\n         - agent_version is the value of the `user_agent_version`\n           attribute of the session object (the botocore version by default).\n           by default.\n         - py_ver is the version of the Python interpreter beng used.\n         - plat_name is the name of the platform (e.g. Darwin)\n         - plat_ver is the version of the platform\n\n        \"\"\"\n        return '%s/%s Python/%s %s/%s' % (self.user_agent_name,\n                                          self.user_agent_version,\n                                          platform.python_version(),\n                                          platform.system(),\n                                          platform.release())\n\n    def get_data(self, data_path):\n        \"\"\"\n        Retrieve the data associated with `data_path`.\n\n        :type data_path: str\n        :param data_path: The path to the data you wish to retrieve.\n        \"\"\"\n        return botocore.base.get_data(self, data_path)\n\n    def get_service_data(self, service_name, provider_name='aws'):\n        \"\"\"\n        Retrieve the fully merged data associated with a service.\n        \"\"\"\n        return botocore.base.get_service_data(self, service_name,\n                                              provider_name)\n\n    def get_service(self, service_name, provider_name='aws'):\n        \"\"\"\n        Get information about a service.\n\n        :type service_name: str\n        :param service_name: The name of the service (e.g. 'ec2')\n\n        :type provider_name: str\n        :param provider_name: The name of the provider.  Defaults\n            to 'aws'.\n\n        :returns: :class:`botocore.service.Service`\n        \"\"\"\n        return botocore.service.get_service(self, service_name, provider_name)\n\n    def set_debug_logger(self):\n        \"\"\"\n        Convenience function to quickly configure full debug output\n        to go to the console.\n        \"\"\"\n        log = logging.getLogger('botocore')\n        log.setLevel(logging.DEBUG)\n\n        # create console handler and set level to debug\n        ch = logging.StreamHandler()\n        ch.setLevel(logging.DEBUG)\n\n        # create formatter\n        formatter = logging.Formatter(self.FmtString)\n\n        # add formatter to ch\n        ch.setFormatter(formatter)\n\n        # add ch to logger\n        log.addHandler(ch)\n\n    def set_file_logger(self, log_level, path):\n        \"\"\"\n        Convenience function to quickly configure any level of logging\n        to a file.\n\n        :type log_level: int\n        :param log_level: A log level as specified in the `logging` module\n\n        :type path: string\n        :param path: Path to the log file.  The file will be created\n            if it doesn't already exist.\n        \"\"\"\n        log = logging.getLogger('botocore')\n        log.setLevel(log_level)\n\n        # create console handler and set level to debug\n        ch = logging.FileHandler(path)\n        ch.setLevel(log_level)\n\n        # create formatter\n        formatter = logging.Formatter(self.FmtString)\n\n        # add formatter to ch\n        ch.setFormatter(formatter)\n\n        # add ch to logger\n        log.addHandler(ch)\n\n\ndef get_session(env_vars=None):\n    \"\"\"\n    Return a new session  object.\n    \"\"\"\n    return Session(env_vars)\n", "path": "botocore/session.py"}]}