← Back to team overview

txaws-dev team mailing list archive

[Merge] lp:~clint-fewbar/txaws/fix-s3-port into lp:txaws

 

Clint Byrum has proposed merging lp:~clint-fewbar/txaws/fix-s3-port into lp:txaws.

Requested reviews:
  txAWS Developers (txaws-dev)
Related bugs:
  Bug #824403 in txAWS: "fails when trying to use openstack or any other S3 service on a non default port as a provider"
  https://bugs.launchpad.net/txaws/+bug/824403

For more details, see:
https://code.launchpad.net/~clint-fewbar/txaws/fix-s3-port/+merge/71289

Always use port for S3 so OpenStack works
-- 
https://code.launchpad.net/~clint-fewbar/txaws/fix-s3-port/+merge/71289
Your team txAWS Developers is requested to review the proposed merge of lp:~clint-fewbar/txaws/fix-s3-port into lp:txaws.
=== modified file 'txaws/s3/client.py'
--- txaws/s3/client.py	2011-04-14 19:50:30 +0000
+++ txaws/s3/client.py	2011-08-29 19:06:23 +0000
@@ -57,8 +57,12 @@
         return path
 
     def get_url(self):
-        return "%s://%s%s" % (
-            self.endpoint.scheme, self.get_host(), self.get_path())
+        if self.endpoint.port is not None:
+            return "%s://%s:%d%s" % (
+                self.endpoint.scheme, self.get_host(), self.endpoint.port, self.get_path())
+        else:
+            return "%s://%s%s" % (
+                self.endpoint.scheme, self.get_host(), self.get_path())
 
 
 class S3Client(BaseClient):

=== modified file 'txaws/s3/tests/test_client.py'
--- txaws/s3/tests/test_client.py	2011-04-14 19:50:30 +0000
+++ txaws/s3/tests/test_client.py	2011-08-29 19:06:23 +0000
@@ -62,6 +62,29 @@
             url_context.get_url(),
             "http://localhost/mydocs/notes.txt";)
 
+    def test_custom_port_endpoint(self):
+        test_uri='http://0.0.0.0:12345/'
+        endpoint = AWSServiceEndpoint(uri=test_uri)
+        self.assertEquals(endpoint.port, 12345)
+        self.assertEquals(endpoint.scheme, 'http')
+        context = client.URLContext(service_endpoint=endpoint,
+                bucket="foo",
+                object_name="bar")
+        self.assertEquals(context.get_host(), '0.0.0.0')
+        self.assertEquals(context.get_url(), test_uri + 'foo/bar')
+
+    def test_custom_port_endpoint_https(self):
+        test_uri='https://0.0.0.0:12345/'
+        endpoint = AWSServiceEndpoint(uri=test_uri)
+        self.assertEquals(endpoint.port, 12345)
+        self.assertEquals(endpoint.scheme, 'https')
+        context = client.URLContext(service_endpoint=endpoint,
+                bucket="foo",
+                object_name="bar")
+        self.assertEquals(context.get_host(), '0.0.0.0')
+        self.assertEquals(context.get_url(), test_uri + 'foo/bar')
+
+
 URLContextTestCase.skip = s3clientSkip
 
 


References