Skip to content

Commit

Permalink
zoweGH-211 Fixed issue for datasets with '#' in URL
Browse files Browse the repository at this point in the history
Signed-off-by: Uladzislau <[email protected]>
  • Loading branch information
KUGDev committed Sep 4, 2023
1 parent d974779 commit b827468
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions src/zos_files/zowe/zos_files_for_zowe_sdk/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ def __init__(self, connection):
self.default_headers["Accept-Encoding"] = "gzip"


def __adjust_for_url(self, str_to_adjust):
"""Adjust string to be correct in a URL
Returns
-------
adjusted_str
A string with special characters, acceptable for a URL
"""

return str_to_adjust.replace("#", "%23") if str_to_adjust is not None else None


def list_files(self, path):
"""Retrieve a list of USS files based on a given pattern.
Expand Down Expand Up @@ -149,7 +161,7 @@ def list_dsn_members(self, dataset_name, member_pattern=None,
for k,v in additional_parms.items():
url = "{}{}{}={}".format(url,separator,k,v)
separator = '&'
custom_args['url'] = url
custom_args['url'] = self.__adjust_for_url(url)
custom_args["headers"]["X-IBM-Max-Items"] = "{}".format(limit)
custom_args["headers"]["X-IBM-Attributes"] = attributes
response_json = self.request_handler.perform_request("GET", custom_args)
Expand Down Expand Up @@ -190,7 +202,7 @@ def copy_uss_to_dataset(self, from_filename, to_dataset_name, to_member_name=Non
path_to_member = f"{to_dataset_name}({to_member_name})" if to_member_name else to_dataset_name
custom_args = self._create_custom_request_arguments()
custom_args['json'] = data
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, path_to_member)
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(path_to_member))
response_json = self.request_handler.perform_request("PUT", custom_args, expected_code=[200])
return response_json

Expand Down Expand Up @@ -224,11 +236,11 @@ def copy_dataset_or_member(self,from_dataset_name,to_dataset_name,from_member_na

data={
"request":"copy",
"from-dataset":{
"dsn":from_dataset_name.strip(),
"from-dataset":{
"dsn":from_dataset_name.strip(),
"member":from_member_name
},
"replace":replace
},
"replace":replace
}


Expand All @@ -245,7 +257,7 @@ def copy_dataset_or_member(self,from_dataset_name,to_dataset_name,from_member_na

custom_args = self._create_custom_request_arguments()
custom_args['json'] = data
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, path_to_member)
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(path_to_member))
response_json = self.request_handler.perform_request("PUT", custom_args, expected_code=[200])
return response_json

Expand All @@ -258,7 +270,7 @@ def get_dsn_content(self, dataset_name):
A JSON with the contents of a given dataset
"""
custom_args = self._create_custom_request_arguments()
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, dataset_name)
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(dataset_name))
response_json = self.request_handler.perform_request("GET", custom_args)
return response_json

Expand Down Expand Up @@ -327,7 +339,7 @@ def create_data_set(self, dataset_name, options = {}):
options[opt] = options["lrecl"]

custom_args = self._create_custom_request_arguments()
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, dataset_name)
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(dataset_name))
custom_args["json"] = options
response_json = self.request_handler.perform_request("POST", custom_args, expected_code = [201])
return response_json
Expand Down Expand Up @@ -403,7 +415,7 @@ def create_default_data_set(self, dataset_name: str, default_type: str):
"dirblk": 25
}

custom_args["url"] = "{}ds/{}".format(self.request_endpoint, dataset_name)
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(dataset_name))
response_json = self.request_handler.perform_request("POST", custom_args, expected_code=[201])
return response_json

Expand Down Expand Up @@ -438,7 +450,7 @@ def get_dsn_content_streamed(self, dataset_name):
A raw socket response
"""
custom_args = self._create_custom_request_arguments()
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, dataset_name)
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(dataset_name))
raw_response = self.request_handler.perform_streamed_request("GET", custom_args)
return raw_response

Expand All @@ -457,7 +469,7 @@ def get_dsn_binary_content(self, dataset_name, with_prefixes=False):
The contents of the dataset with no transformation
"""
custom_args = self._create_custom_request_arguments()
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, dataset_name)
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(dataset_name))
custom_args["headers"]["Accept"] = "application/octet-stream"
if with_prefixes:
custom_args["headers"]["X-IBM-Data-Type"] = 'record'
Expand All @@ -481,7 +493,7 @@ def get_dsn_binary_content_streamed(self, dataset_name, with_prefixes=False):
The raw socket response
"""
custom_args = self._create_custom_request_arguments()
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, dataset_name)
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(dataset_name))
custom_args["headers"]["Accept"] = "application/octet-stream"
if with_prefixes:
custom_args["headers"]["X-IBM-Data-Type"] = 'record'
Expand All @@ -499,7 +511,7 @@ def write_to_dsn(self, dataset_name, data, encoding=_ZOWE_FILES_DEFAULT_ENCODING
A JSON containing the result of the operation
"""
custom_args = self._create_custom_request_arguments()
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, dataset_name)
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(dataset_name))
custom_args["data"] = data
custom_args['headers']['Content-Type'] = 'text/plain; charset={}'.format(encoding)
response_json = self.request_handler.perform_request(
Expand Down Expand Up @@ -573,7 +585,7 @@ def delete_data_set(self, dataset_name, volume=None, member_name=None):
url = "{}ds/{}".format(self.request_endpoint, dataset_name)
if volume is not None:
url = "{}ds/-{}/{}".format(self.request_endpoint, volume, dataset_name)
custom_args["url"] = url
custom_args["url"] = self.__adjust_for_url(url)
response_json = self.request_handler.perform_request(
"DELETE", custom_args, expected_code=[200, 202, 204])
return response_json
Expand Down Expand Up @@ -700,7 +712,7 @@ def recall_migrated_dataset(self, dataset_name: str, wait=False):

custom_args = self._create_custom_request_arguments()
custom_args["json"] = data
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, dataset_name)
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(dataset_name))

response_json = self.request_handler.perform_request("PUT", custom_args, expected_code=[200])
return response_json
Expand Down Expand Up @@ -733,7 +745,7 @@ def delete_migrated_data_set(self, dataset_name: str, purge=False, wait=False):

custom_args = self._create_custom_request_arguments()
custom_args["json"] = data
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, dataset_name)
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(dataset_name))

response_json = self.request_handler.perform_request("PUT", custom_args, expected_code=[200])
return response_json
Expand Down Expand Up @@ -762,7 +774,7 @@ def migrate_data_set(self, dataset_name: str, wait=False):

custom_args = self._create_custom_request_arguments()
custom_args["json"] = data
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, dataset_name)
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(dataset_name))

response_json = self.request_handler.perform_request("PUT", custom_args, expected_code=[200])
return response_json
Expand Down Expand Up @@ -793,7 +805,7 @@ def rename_dataset(self, before_dataset_name: str, after_dataset_name: str):

custom_args = self._create_custom_request_arguments()
custom_args["json"] = data
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, after_dataset_name.strip())
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(after_dataset_name).strip())

response_json = self.request_handler.perform_request("PUT", custom_args, expected_code=[200])
return response_json
Expand Down Expand Up @@ -839,7 +851,7 @@ def rename_dataset_member(self, dataset_name: str, before_member_name: str, afte

custom_args = self._create_custom_request_arguments()
custom_args['json'] = data
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, path_to_member)
custom_args["url"] = "{}ds/{}".format(self.request_endpoint, self.__adjust_for_url(path_to_member))

response_json = self.request_handler.perform_request("PUT", custom_args, expected_code=[200])
return response_json

0 comments on commit b827468

Please sign in to comment.