Skip to content

Commit

Permalink
Avoid casting to json on file upload & fix file list function
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderBrandborg committed Aug 15, 2022
1 parent 30adce1 commit ffdcf7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/humiolib/HumioClient.py
Expand Up @@ -509,8 +509,8 @@ def _upload_file(self, filepath):
:param filepath: Path to file.
:type filepath: string
:return: Response to web request as json string
:rtype: str
:return: Response to web request
:rtype: Response
"""

endpoint = "dataspaces/{}/files".format(self.repository)
Expand All @@ -519,7 +519,9 @@ def _upload_file(self, filepath):
return self.webcaller.call_rest("post", endpoint, files={"file": f}, headers=headers)

# Wrap method to be pythonic
upload_file = WebCaller.response_as_json(_upload_file)
# The uploaded files endpoint currently doesn't return JSON, thus this function doesn't attempt to cast to json.
def upload_file(self, filepath):
return self._upload_file(filepath)

def _list_files(self):
"""
Expand All @@ -531,7 +533,7 @@ def _list_files(self):

headers = self._default_user_headers
request = {
"query": "query {{listUploadedFiles(name: {})}}".format(
"query": "query {{searchDomain(name: {}){{files {{nameAndPath {{path, name}} }} }} }}".format(
json.dumps(self.repository)
),
"variables": None,
Expand All @@ -540,7 +542,7 @@ def _list_files(self):

def list_files(self):
resp = self._list_files()
return resp.json()["data"]["listUploadedFiles"]
return resp.json()["data"]["searchDomain"]["files"]

def _get_file(self, file_name):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/humiolib/WebCaller.py
Expand Up @@ -105,7 +105,7 @@ def response_as_json(func):
:param func: Function to be wrapped.
:type func: Function
:return: Result of function, parsed into python objects from jso
:return: Result of function, parsed into python objects from json
:rtype: dict
"""
@functools.wraps(func)
Expand Down

0 comments on commit ffdcf7d

Please sign in to comment.