瀏覽代碼

[raz] Refactoring URL splitting to be cleaner

Romain Rigaux 4 年之前
父節點
當前提交
ca0270a21c

+ 4 - 4
desktop/core/src/desktop/lib/raz/raz_client.py

@@ -83,16 +83,16 @@ class RazClient(object):
     self.requestid = str(uuid.uuid4())
     self.requestid = str(uuid.uuid4())
 
 
   def check_access(self, method, url, params=None, headers=None):
   def check_access(self, method, url, params=None, headers=None):
-    o = lib_urlparse(url)
-    url_params = dict([p.split('=') for p in o.query.split('&') if o.query])
+    path = lib_urlparse(url)
+    url_params = dict([p.split('=') for p in path.query.split('&') if path.query])
     params = params if params is not None else {}
     params = params if params is not None else {}
     headers = headers if headers is not None else {}
     headers = headers if headers is not None else {}
 
 
     allparams = [raz_signer.StringListStringMapProto(key=key, value=val) for key, val in url_params.items()]
     allparams = [raz_signer.StringListStringMapProto(key=key, value=val) for key, val in url_params.items()]
     allparams.extend([raz_signer.StringListStringMapProto(key=key, value=val) for key, val in params.items()])
     allparams.extend([raz_signer.StringListStringMapProto(key=key, value=val) for key, val in params.items()])
     headers = [raz_signer.StringStringMapProto(key=key, value=val) for key, val in headers.items()]
     headers = [raz_signer.StringStringMapProto(key=key, value=val) for key, val in headers.items()]
-    endpoint = "%s://%s" % (o.scheme, o.netloc)
-    resource_path = o.path.lstrip("/")
+    endpoint = "%s://%s" % (path.scheme, path.netloc)
+    resource_path = path.path.lstrip("/")
 
 
     LOG.debug(
     LOG.debug(
       "Preparing sign request with http_method: {%s}, header: {%s}, parameters: {%s}, endpoint: {%s}, resource_path: {%s}" %
       "Preparing sign request with http_method: {%s}, header: {%s}, parameters: {%s}, endpoint: {%s}, resource_path: {%s}" %

+ 1 - 1
desktop/libs/aws/src/aws/client.py

@@ -172,7 +172,7 @@ class Client(object):
     try:
     try:
       # Use V4 signature support by default
       # Use V4 signature support by default
       os.environ['S3_USE_SIGV4'] = 'True'
       os.environ['S3_USE_SIGV4'] = 'True'
-      if self._host is not None:
+      if self._host is not None and not aws_conf.IS_SELF_SIGNING_ENABLED.get():
         kwargs.update({'host': self._host})
         kwargs.update({'host': self._host})
         connection = boto.s3.connection.S3Connection(**kwargs)
         connection = boto.s3.connection.S3Connection(**kwargs)
       elif self._region:
       elif self._region:

+ 6 - 1
desktop/libs/aws/src/aws/s3/s3connection.py

@@ -186,7 +186,7 @@ class SelfSignedUrlS3Connection(SignedUrlS3Connection):
 
 
     # http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.connection.S3Connection.generate_url
     # http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.connection.S3Connection.generate_url
     signed_url = self.generate_url(1000, method, **kwargs)
     signed_url = self.generate_url(1000, method, **kwargs)
-    LOG.debug(signed_url)
+    LOG.debug('Generated url: %s' % signed_url)
 
 
     http_request.path = signed_url.replace(http_request.protocol + '://' + http_request.host.split(':')[0], '')
     http_request.path = signed_url.replace(http_request.protocol + '://' + http_request.host.split(':')[0], '')
     p, h = http_request.path.split('?')
     p, h = http_request.path.split('?')
@@ -288,6 +288,7 @@ class UrlKey(Key):
     try:
     try:
       # http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.key.Key.generate_url
       # http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.key.Key.generate_url
       signed_url = self.generate_url(self.expiration, action, **kwargs)
       signed_url = self.generate_url(self.expiration, action, **kwargs)
+      LOG.debug('Generated url: %s' % signed_url)
     except BotoClientError as e:
     except BotoClientError as e:
       LOG.error(e)
       LOG.error(e)
       if signed_url is None:
       if signed_url is None:
@@ -314,6 +315,7 @@ class UrlBucket(Bucket):
     # TODO: if GET --> max length to add
     # TODO: if GET --> max length to add
 
 
     signed_url = self.connection.generate_url(3000, action, **kwargs)
     signed_url = self.connection.generate_url(3000, action, **kwargs)
+    LOG.debug('Generated url: %s' % signed_url)
 
 
     if action == 'HEAD':
     if action == 'HEAD':
       response = requests.head(signed_url)
       response = requests.head(signed_url)
@@ -367,6 +369,7 @@ class UrlBucket(Bucket):
     kwargs = {'bucket': self.name, 'key': '', 'response_headers': params}
     kwargs = {'bucket': self.name, 'key': '', 'response_headers': params}
 
 
     signed_url = self.connection.generate_url(3000, 'GET', **kwargs)
     signed_url = self.connection.generate_url(3000, 'GET', **kwargs)
+    LOG.debug('Generated url: %s' % signed_url)
 
 
     response = requests.get(signed_url)
     response = requests.get(signed_url)
 
 
@@ -390,6 +393,7 @@ class UrlBucket(Bucket):
     try:
     try:
       # http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.bucket.Bucket.generate_url
       # http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.bucket.Bucket.generate_url
       signed_url = self.generate_url(self.expiration, action, **kwargs)
       signed_url = self.generate_url(self.expiration, action, **kwargs)
+      LOG.debug('Generated url: %s' % signed_url)
     except BotoClientError as e:
     except BotoClientError as e:
       LOG.error(e)
       LOG.error(e)
       if signed_url is None:
       if signed_url is None:
@@ -415,6 +419,7 @@ class SelfSignedUrlClient(SignedUrlClient):
     try:
     try:
       # http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.connection.S3Connection.generate_url
       # http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.connection.S3Connection.generate_url
       signed_url = self.connection.generate_url(self.expiration, action, **kwargs)
       signed_url = self.connection.generate_url(self.expiration, action, **kwargs)
+      LOG.debug('Generated url: %s' % signed_url)
     except BotoClientError as e:
     except BotoClientError as e:
       LOG.error(e)
       LOG.error(e)
       if signed_url is None:
       if signed_url is None: