From a93de21cc8b4fd338eec4fbba62e32dab2f06ace Mon Sep 17 00:00:00 2001 From: rongzhus Date: Sun, 11 Jun 2023 17:48:32 +0800 Subject: [PATCH 1/5] change no location to N/A --- synctl | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/synctl b/synctl index 40ecf11..f7ed608 100755 --- a/synctl +++ b/synctl @@ -54,6 +54,8 @@ SYN_APP = "app" # short for application POSITION_PARAMS = "commands" OPTIONS_PARAMS = "options" +NOT_APPLICABLE = "N/A" + def show_version(): """show synctl version""" @@ -1269,7 +1271,7 @@ class SyntheticTest(Base): active_length = 6 success_rate_length = 12 response_time_length = 12 - location_str = "no locations" + location_str = NOT_APPLICABLE test_type = "" if test_type is None else test_type # show title @@ -1301,7 +1303,7 @@ class SyntheticTest(Base): # locations, location_str = ','.join(t['locationDisplayLabels']) else: - location_str = "no locations" + location_str = NOT_APPLICABLE if test_type == "" or (test_type != "" and current_type == test_type): print(self.fill_space(t["id"], id_length), self.fill_space(t['label'], max_label_length), @@ -1321,7 +1323,7 @@ class SyntheticTest(Base): if len(t['locations']) > 0: location_str = ','.join(t['locationDisplayLabels']) else: - location_str = "no locations" + location_str = NOT_APPLICABLE if test_type == "" or (test_type != "" and current_type == test_type): print(self.fill_space(t["id"], id_length), self.fill_space(t['label'], max_label_length), @@ -2096,7 +2098,7 @@ class ParseParameter: # set auth self.parser_create.add_argument( - '--use-env', type=str, default=None, help='use a specified configuration') + '--use-env', '-e', type=str, default=None, help='use a specified configuration') self.parser_create.add_argument( '--host', type=str, help='set hostname') self.parser_create.add_argument( @@ -2109,7 +2111,7 @@ class ParseParameter: # parser_get.add_argument('type_id', type=str, # required=False, help='test id or location id') self.parser_get.add_argument( - '--type', '-t', type=int, metavar='synthetic type', help='specify synthetic type') + '--type', '-t', type=int, choices=[0, 1, 2, 3], metavar='synthetic type', help='specify synthetic type') self.parser_get.add_argument( 'id', type=str, nargs="?", help='synthetic id') self.parser_get.add_argument( @@ -2143,7 +2145,7 @@ class ParseParameter: # self.parser_get.add_argument( # '--token', type=str, help='set token') host_token_group.add_argument( - '--use-env', type=str, default=None, help='use a specified config') + '--use-env', '-e', type=str, default=None, help='use a specified config') host_token_group.add_argument( '--host', type=str, help='set hostname') host_token_group.add_argument( @@ -2182,7 +2184,7 @@ class ParseParameter: # parser_patch.add_mutually_exclusive_group self.parser_patch.add_argument( - '--use-env', type=str, default=None, help='use a config hostname') + '--use-env', '-e', type=str, default=None, help='use a config hostname') self.parser_patch.add_argument( '--host', type=str, help='set hostname') self.parser_patch.add_argument( @@ -2200,7 +2202,7 @@ class ParseParameter: '--from-data', type=str, help='new json payload') self.parser_update.add_argument( - '--use-env', type=str, default=None, help='use a config hostname') + '--use-env', '-e', type=str, default=None, help='use a config hostname') self.parser_update.add_argument( '--host', type=str, help='set hostname') self.parser_update.add_argument( @@ -2223,7 +2225,7 @@ class ParseParameter: '--no-locations', action="store_true", help="delete test with no locations") self.parser_delete.add_argument( - '--use-env', type=str, default=None, help='use a config hostname') + '--use-env', '-e', type=str, default=None, help='use a config hostname') self.parser_delete.add_argument( '--host', type=str, help='set hostname') self.parser_delete.add_argument( @@ -2335,7 +2337,10 @@ def main(): syn_type_t = None syn_window_size = get_args.window_size if get_args.type is not None: - syn_type_t = synthetic_type[get_args.type] + try: + syn_type_t = synthetic_type[get_args.type] + except IndexError: + print("synthetic type only support 0 1 2 3", syn_type_t) if get_args.id is None: out_list = syn_instance.retrieve_all_synthetic_tests( From 1f8c3bf0cf3f744a8e72ac027f50b2944ce2d370 Mon Sep 17 00:00:00 2001 From: rongzhus Date: Mon, 12 Jun 2023 18:21:41 +0800 Subject: [PATCH 2/5] remove right / --- synctl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/synctl b/synctl index f7ed608..68fcb16 100755 --- a/synctl +++ b/synctl @@ -183,7 +183,7 @@ class Base: def set_host_token(self, new_host=None, new_token=None): if new_host is not None and new_token is not None: - self.auth["host"] = new_host + self.auth["host"] = new_host.rstrip('/') self.auth["token"] = new_token else: print("both --host and --token are required") @@ -308,6 +308,10 @@ class ConfigurationFile(Base): return False + def __remove_right_slash(self, host_name): + """remove right slash of a host""" + return host_name.rstrip('/') + def add_an_item_to_config(self, name, host, token, set_default=False): """add a new config""" if name is None or host is None or token is None: @@ -316,11 +320,12 @@ class ConfigurationFile(Base): print("name, host, and token must not be none") elif self.__check_if_already_in_config(name): # update it - self.update_an_item(name, host, token, set_default=set_default) + self.update_an_item(name, self.__remove_right_slash( + host), token, set_default=set_default) else: self.config_json.append({ "name": name, - "host": host, + "host": self.__remove_right_slash(host), "token": token, "default": False }) @@ -378,12 +383,12 @@ class ConfigurationFile(Base): for item in self.config_json: if item["default"] is True: return { - "host": item["host"], + "host": self.__remove_right_slash(item["host"]), "token": item["token"] } if len(self.config_json) > 0: return { - "host": self.config_json[0]["host"], + "host": self.__remove_right_slash(self.config_json[0]["host"]), "token": self.config_json[0]["token"] } else: @@ -395,7 +400,7 @@ class ConfigurationFile(Base): for item in self.config_json: if item["name"] == name: return { - "host": item["host"], + "host": self.__remove_right_slash(item["host"]), "token": item["token"] } raise ValueError(f"no config named {name}") From c32057bef10b785a5bad7dc47f355fd8c1c25ad1 Mon Sep 17 00:00:00 2001 From: rongzhus Date: Tue, 13 Jun 2023 20:16:56 +0800 Subject: [PATCH 3/5] remove --- synctl | 1 - 1 file changed, 1 deletion(-) diff --git a/synctl b/synctl index 68fcb16..76c36d9 100755 --- a/synctl +++ b/synctl @@ -1725,7 +1725,6 @@ class SyntheticResult(Base): if summary_res.status_code == 200: # extracting data in json format data = summary_res.json() - # print("summary data:", data) return data elif summary_res.status_code == 400: print(f'Bad Request: status code: {summary_res.status_code}') From a3007a1e2456251ec79f0f0a48cfe9a7e0ae64b2 Mon Sep 17 00:00:00 2001 From: rongzhus Date: Thu, 15 Jun 2023 11:55:01 +0800 Subject: [PATCH 4/5] support zip file --- synctl | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/synctl b/synctl index 76c36d9..817bc67 100755 --- a/synctl +++ b/synctl @@ -106,13 +106,15 @@ synctl create test -t 0 --label simple-ping-test --url --location --f synctl create test -t 1 --label script-test --from-file script-name.js --location # create an API script bundle type +synctl create test -t 1 --label script-bundle-test --bundle file.zip --script-file index.js --location synctl create test -t 1 --label script-bundle-test --bundle --script-file index.js --location # create browserscript synctl create test -t 2 --label browserscript-test --from-file api-sample.js --browser firefox --location # create browserscript bundle -synctl create test -t 2 --label "browserscript-bundle-test" --bundle "base64" --script-file mytest.js --browser chrome --location +synctl create test -t 2 --label "browserscript-bundle-test" --bundle "file.zip" --script-file mytest.js --browser chrome --location +synctl create test -t 2 --label "browserscript-bundle-test" --bundle "" --script-file mytest.js --browser chrome --location # create webpagescript synctl create test -t 3 --label "webpagescript-test" --from-file side/browser.side --browser chrome --location """ @@ -809,12 +811,19 @@ class SyntheticConfiguration(Base): print(not_found_e) sys.exit(-1) - def read_zip_file(self, file_name): + def is_zip_file(self, file_name): + """check zip file name""" + if file_name is not None and isinstance(file_name, str): + return file_name.endswith('.zip') + + def read_zip_file_to_base64(self, file_name): + """read zip file and encode with base64""" with open(file_name, 'rb') as file1: zip_content_byte = file1.read() zip_content_byte_base64 = b64encode(zip_content_byte) - self.set_api_bundle_script(zip_content_byte_base64) - return zip_content_byte_base64 + zip_content_base64_str = zip_content_byte_base64.decode('utf-8') + # self.set_api_bundle_script(zip_content_base64_str) + return zip_content_base64_str def get_json(self): """return payload as json""" @@ -2061,7 +2070,7 @@ class ParseParameter: # options for bundle script self.parser_create.add_argument( - '--bundle', type=str, help='synthetic script encoded with base64') + '--bundle', type=str, help='specify a zip file or use synthetic script encoded with base64') self.parser_create.add_argument( '--script-file', type=str, help='bundle script entry file, e.g, myscript.js') # [0, 2] @@ -2468,13 +2477,18 @@ def main(): syn_type_t = synthetic_type[get_args.type] payload = SyntheticConfiguration(syn_type_t, bundle_type=True) + if payload.is_zip_file(get_args.bundle): + bundle_base64_str = payload.read_zip_file_to_base64( + get_args.bundle) + else: + bundle_base64_str = get_args.bundle # entry file if get_args.script_file is not None: payload.set_api_bundle_script( - get_args.bundle, script_file=get_args.script_file) + bundle_base64_str, script_file=get_args.script_file) else: # script file use index.js - payload.set_api_bundle_script(get_args.bundle) + payload.set_api_bundle_script(bundle_base64_str) # BrowserScript 2, WebpageScript 3 if get_args.type in (2, 3): payload.set_browser_type(get_args.browser) From a886a18493e7f57807915e456875dcde17f68ebc Mon Sep 17 00:00:00 2001 From: rongzhus Date: Fri, 16 Jun 2023 16:09:59 +0800 Subject: [PATCH 5/5] update README --- README.md | 95 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 1ab289c..7416f1d 100644 --- a/README.md +++ b/README.md @@ -110,45 +110,36 @@ synctl get test --show-json ## Create a synthetic test ``` -synctl create test -t --label