Repository: boto/botocore
Pull request #489 (2015-03-12 00:42:41)

Add endpoint_url to client meta
I think eventually we'll move all the client args into the
client meta, but for now, we only need endpoint_url.

cc @kyleknap @danielgtaylor


Patch:
diff --git a/botocore/client.py b/botocore/client.py
index eac169d90..0dcb107da 100644
--- a/botocore/client.py
+++ b/botocore/client.py
@@ -210,7 +210,7 @@ class BaseClient(object):
         self._cache = {}
         self._loader = loader
         self.meta = ClientMeta(event_emitter, endpoint.region_name,
-                               service_model)
+                               endpoint.host, service_model)
 
         # Register request signing, but only if we have an event
         # emitter. When a client is cloned this is ignored, because
@@ -376,9 +376,10 @@ class ClientMeta(object):
 
     """
 
-    def __init__(self, events, region_name, service_model):
+    def __init__(self, events, region_name, endpoint_url, service_model):
         self.events = events
         self._region_name = region_name
+        self._endpoint_url = endpoint_url
         self._service_model = service_model
 
     @property
@@ -389,6 +390,10 @@ class ClientMeta(object):
     def region_name(self):
         return self._region_name
 
+    @property
+    def endpoint_url(self):
+        return self._endpoint_url
+
 
 class Config(object):
     """Advanced configuration for Botocore clients.


Test patch:
diff --git a/tests/integration/test_client.py b/tests/integration/test_client.py
index 2f94bac01..ec58337cd 100644
--- a/tests/integration/test_client.py
+++ b/tests/integration/test_client.py
@@ -157,3 +157,17 @@ class TestClientErrorMessages(unittest.TestCase):
         with self.assertRaisesRegexp(EndpointConnectionError,
                                      'Could not connect to the endpoint URL'):
             client.list_stacks()
+
+
+class TestClientMeta(unittest.TestCase):
+    def setUp(self):
+        self.session = botocore.session.get_session()
+
+    def test_region_name_on_meta(self):
+        client = self.session.create_client('s3', 'us-west-2')
+        self.assertEqual(client.meta.region_name, 'us-west-2')
+
+    def test_endpoint_url_on_meta(self):
+        client = self.session.create_client('s3', 'us-west-2',
+                                            endpoint_url='https://foo')
+        self.assertEqual(client.meta.endpoint_url, 'https://foo')
diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py
index 89e5faa43..4314de28b 100644
--- a/tests/unit/test_client.py
+++ b/tests/unit/test_client.py
@@ -129,6 +129,14 @@ class TestAutoGeneratedClient(unittest.TestCase):
             'myservice', region_name, credentials=self.credentials)
         self.assertEqual(service_client.meta.region_name, region_name)
 
+    def test_client_has_endpoint_url_on_meta(self):
+        creator = self.create_client_creator()
+        self.endpoint.host = 'https://foo.bar'
+        service_client = creator.create_client(
+            'myservice', 'us-west-2', credentials=self.credentials)
+        self.assertEqual(service_client.meta.endpoint_url,
+                         'https://foo.bar')
+
     @mock.patch('botocore.client.RequestSigner')
     def test_client_signature_no_override(self, request_signer):
         creator = self.create_client_creator()