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

Proposed by Clint Byrum
Status: Merged
Approved by: Thomas Herve
Approved revision: 95
Merged at revision: 99
Proposed branch: lp:~clint-fewbar/txaws/fix-s3-port
Merge into: lp:txaws
Diff against target: 50 lines (+29/-2)
2 files modified
txaws/s3/client.py (+6/-2)
txaws/s3/tests/test_client.py (+23/-0)
To merge this branch: bzr merge lp:~clint-fewbar/txaws/fix-s3-port
Reviewer Review Type Date Requested Status
Free Ekanayaka (community) Approve
Review via email: mp+71289@code.launchpad.net

Description of the change

Always use port for S3 so OpenStack works

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

Two things:

 - only include :port if the port is not the default port for the
protocol. This (may) matter for signing with ec2 etc.
 - a test or two would be massively preferred.

-Rob

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Any news on this?

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

This is sitting idle for more than two weeks. Clint, what is the plan on it? Are we getting this merged, or should we push it back?

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Actually, I'll move it to Work In Progress for the moment.

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

If I could..

Revision history for this message
Clint Byrum (clint-fewbar) wrote :

Pushed up a commit adding two tests to verify that the port is added into the url, should cover all changed lines and a few others. :)

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Rob, any comments on the new changeset?

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Looks good, I don't have much to add to what Robert pointed, except for the two minor comments below ([1] is automatically resolved if [2] is adopted).

+1!

[1]

+ self.endpoint.scheme, self.get_host(), self.endpoint.port, self.get_path())

This line is too long, it makes pyflakes/pep8 unhappy.

[2]

+ 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())

You can save a tiny bit of logic duplication by doing:

    def get_port(self):
        if self.endpoint.port is not None:
            return ":%d" % self.endpoint.port
        else:
            return ""

    def get_url(self):
        return "%s://%s%s%s" % (self.endpoint.scheme,
                                self.get_host(),
                                self.get_port(),
                                self.get_path())

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'txaws/s3/client.py'
2--- txaws/s3/client.py 2011-04-14 19:50:30 +0000
3+++ txaws/s3/client.py 2011-08-29 19:06:23 +0000
4@@ -57,8 +57,12 @@
5 return path
6
7 def get_url(self):
8- return "%s://%s%s" % (
9- self.endpoint.scheme, self.get_host(), self.get_path())
10+ if self.endpoint.port is not None:
11+ return "%s://%s:%d%s" % (
12+ self.endpoint.scheme, self.get_host(), self.endpoint.port, self.get_path())
13+ else:
14+ return "%s://%s%s" % (
15+ self.endpoint.scheme, self.get_host(), self.get_path())
16
17
18 class S3Client(BaseClient):
19
20=== modified file 'txaws/s3/tests/test_client.py'
21--- txaws/s3/tests/test_client.py 2011-04-14 19:50:30 +0000
22+++ txaws/s3/tests/test_client.py 2011-08-29 19:06:23 +0000
23@@ -62,6 +62,29 @@
24 url_context.get_url(),
25 "http://localhost/mydocs/notes.txt")
26
27+ def test_custom_port_endpoint(self):
28+ test_uri='http://0.0.0.0:12345/'
29+ endpoint = AWSServiceEndpoint(uri=test_uri)
30+ self.assertEquals(endpoint.port, 12345)
31+ self.assertEquals(endpoint.scheme, 'http')
32+ context = client.URLContext(service_endpoint=endpoint,
33+ bucket="foo",
34+ object_name="bar")
35+ self.assertEquals(context.get_host(), '0.0.0.0')
36+ self.assertEquals(context.get_url(), test_uri + 'foo/bar')
37+
38+ def test_custom_port_endpoint_https(self):
39+ test_uri='https://0.0.0.0:12345/'
40+ endpoint = AWSServiceEndpoint(uri=test_uri)
41+ self.assertEquals(endpoint.port, 12345)
42+ self.assertEquals(endpoint.scheme, 'https')
43+ context = client.URLContext(service_endpoint=endpoint,
44+ bucket="foo",
45+ object_name="bar")
46+ self.assertEquals(context.get_host(), '0.0.0.0')
47+ self.assertEquals(context.get_url(), test_uri + 'foo/bar')
48+
49+
50 URLContextTestCase.skip = s3clientSkip
51
52

Subscribers

People subscribed via source and target branches

to all changes: