Skip to content

Commit

Permalink
[raz] Refactoring URL splitting to be cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
romainr committed May 19, 2021
1 parent fb671b3 commit ca0270a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions desktop/core/src/desktop/lib/raz/raz_client.py
Expand Up @@ -83,16 +83,16 @@ def __init__(self, raz_url, raz_token, username, service='s3', service_name='cm_
self.requestid = str(uuid.uuid4())

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 {}
headers = headers if headers is not None else {}

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()])
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(
"Preparing sign request with http_method: {%s}, header: {%s}, parameters: {%s}, endpoint: {%s}, resource_path: {%s}" %
Expand Down
2 changes: 1 addition & 1 deletion desktop/libs/aws/src/aws/client.py
Expand Up @@ -172,7 +172,7 @@ def get_s3_connection(self):
try:
# Use V4 signature support by default
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})
connection = boto.s3.connection.S3Connection(**kwargs)
elif self._region:
Expand Down
7 changes: 6 additions & 1 deletion desktop/libs/aws/src/aws/s3/s3connection.py
Expand Up @@ -186,7 +186,7 @@ def make_request(self, method, bucket='', key='', headers=None, data='',

# http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.connection.S3Connection.generate_url
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], '')
p, h = http_request.path.split('?')
Expand Down Expand Up @@ -288,6 +288,7 @@ def get_url_request(self, action='GET', **kwargs):
try:
# http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.key.Key.generate_url
signed_url = self.generate_url(self.expiration, action, **kwargs)
LOG.debug('Generated url: %s' % signed_url)
except BotoClientError as e:
LOG.error(e)
if signed_url is None:
Expand All @@ -314,6 +315,7 @@ def get_key(self, key_name, headers=None, version_id=None, response_headers=None
# TODO: if GET --> max length to add

signed_url = self.connection.generate_url(3000, action, **kwargs)
LOG.debug('Generated url: %s' % signed_url)

if action == 'HEAD':
response = requests.head(signed_url)
Expand Down Expand Up @@ -367,6 +369,7 @@ def get_all_keys(self, headers=None, **params):
kwargs = {'bucket': self.name, 'key': '', 'response_headers': params}

signed_url = self.connection.generate_url(3000, 'GET', **kwargs)
LOG.debug('Generated url: %s' % signed_url)

response = requests.get(signed_url)

Expand All @@ -390,6 +393,7 @@ def get_url_request(self, action='GET', **kwargs):
try:
# http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.bucket.Bucket.generate_url
signed_url = self.generate_url(self.expiration, action, **kwargs)
LOG.debug('Generated url: %s' % signed_url)
except BotoClientError as e:
LOG.error(e)
if signed_url is None:
Expand All @@ -415,6 +419,7 @@ def get_url_request(self, action='GET', **kwargs):
try:
# 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)
LOG.debug('Generated url: %s' % signed_url)
except BotoClientError as e:
LOG.error(e)
if signed_url is None:
Expand Down

0 comments on commit ca0270a

Please sign in to comment.