Skip to content

Commit

Permalink
Merge pull request #20 from slaclab/client_fixes
Browse files Browse the repository at this point in the history
Python 3 fixes and fixes to client
  • Loading branch information
brianv0 authored May 17, 2019
2 parents 82f1891 + 4588f26 commit 0753d86
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions client/python/datacat/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, key_id, secret_key, header_name, signature_format, url=None):
if url:
self.resource_base_url = url
self.key_id = str(key_id)
self.secret_key = base64.b64decode(str(secret_key))
self.secret_key = base64.b64decode(str(secret_key).encode())
self.header_name = header_name
self.sig_fmt = signature_format

Expand All @@ -34,8 +34,8 @@ def __call__(self, request):

def get_signature(self, r):
canonical_string = self.get_canonical_string(r.url, r.headers, r.method)
h = hmac.new(self.secret_key, canonical_string, digestmod=hashlib.sha1)
return base64.encodestring(h.digest()).strip()
h = hmac.new(self.secret_key, canonical_string.encode(), digestmod=hashlib.sha1)
return base64.encodestring(h.digest()).strip().decode()

def get_canonical_string(self, url, headers, method):
parsedurl = urlparse(url)
Expand Down
3 changes: 1 addition & 2 deletions client/python/datacat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ def mkloc(self, path, site, resource, versionId="current", **kwargs):
:param kwargs: Additional location attributes
:return: A representation of the dataset that was just created.
"""
# We piggy back off of build_dataset
location = {site: site, resource: resource}
location = dict(site=site, resource=resource)
location.update(**kwargs)
ds = build_dataset(location=location)
resp = self.http_client.mkds(path, pack(ds), versionId=versionId)
Expand Down
8 changes: 4 additions & 4 deletions client/python/datacat/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def children(self, path, versionId=None, site=None, stat=None, offset=None, max_
endpoint = "path"
param_list = "offset:offset max_num:max stat:stat".split(" ")
param_map = dict([tuple(i.split(":")) for i in param_list])
params = {param_map[k]: v for k, v in locals().items() if k in param_map and v is not None}
params = {param_map[k]: v for k, v in list(locals().items()) if k in param_map and v is not None}
target = self._target(endpoint, path, versionId, site) + ";children"
return self._req("get", target, params, **kwargs)

Expand Down Expand Up @@ -169,7 +169,7 @@ def search(self, target, versionId=None, site=None, query=None, sort=None, show=
endpoint = "search"
param_list = "query:filter sort:sort show:show offset:offset max_num:max".split(" ")
param_map = dict([tuple(i.split(":")) for i in param_list])
params = {param_map[k]: v for k, v in locals().items() if k in param_map and v is not None}
params = {param_map[k]: v for k, v in list(locals().items()) if k in param_map and v is not None}
return self._req("get", self._target(endpoint, target, versionId, site), params, **kwargs)

def permissions(self, path, group=None):
Expand Down Expand Up @@ -215,7 +215,7 @@ def _log_request(self, request):

_logger.debug("Request: %s %s" % (http_method, url))
if headers:
for header in headers.items():
for header in list(headers.items()):
_logger.debug("Request Header: %s" % ": ".join(header))

if data:
Expand All @@ -228,7 +228,7 @@ def _log_response(self, response):
_logger.debug("Response: (%s)", response.status_code)

if headers:
for header in headers.items():
for header in list(headers.items()):
_logger.debug("Response Header: %s" % ": ".join(header))

if response.content:
Expand Down

0 comments on commit 0753d86

Please sign in to comment.