~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to txaws/s3/client.py

  • Committer: kapil.thangavelu at canonical
  • Date: 2011-09-22 20:17:22 UTC
  • mfrom: (91.2.10 fix-s3-port)
  • mto: This revision was merged to the branch mainline in revision 99.
  • Revision ID: kapil.thangavelu@canonical.com-20110922201722-l4plcnk5wrr7eten
merge fix-s3-port-and-bucket-op [a=hazmat,jimbaker,spampas][r=therve][f=829609,824403]

Openstack compatibiity fixes.

 - S3 bucket operations use a trailing slash.
 - S3 Host and port are now configurable.
 - Security group parsing is now more forgiving.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
            if not self.object_name.startswith("/"):
55
55
                path += "/"
56
56
            path += self.object_name
 
57
        elif self.bucket is not None and not path.endswith("/"):
 
58
            path += "/"
57
59
        return path
58
60
 
59
61
    def get_url(self):
60
 
        return "%s://%s%s" % (
61
 
            self.endpoint.scheme, self.get_host(), self.get_path())
 
62
        if self.endpoint.port is not None:
 
63
            return "%s://%s:%d%s" % (
 
64
                self.endpoint.scheme, self.get_host(), self.endpoint.port, self.get_path())
 
65
        else:
 
66
            return "%s://%s%s" % (
 
67
                self.endpoint.scheme, self.get_host(), self.get_path())
62
68
 
63
69
 
64
70
class S3Client(BaseClient):
389
395
        """
390
396
        Get an S3 resource path.
391
397
        """
392
 
        resource = "/"
393
 
        if self.bucket:
394
 
            resource += self.bucket
395
 
            if self.object_name:
396
 
                resource += "/%s" % self.object_name
397
 
        return resource
 
398
        path = "/"
 
399
        if self.bucket is not None:
 
400
            path += self.bucket
 
401
        if self.bucket is not None and self.object_name:
 
402
            if not self.object_name.startswith("/"):
 
403
                path += "/"
 
404
            path += self.object_name
 
405
        elif self.bucket is not None and not path.endswith("/"):
 
406
            path += "/"
 
407
        return path
398
408
 
399
409
    def sign(self, headers):
400
410
        """Sign this query using its built in credentials."""