Index: cloud_sync.py =================================================================== diff -u -rcc7bbd932684e69aa456c114596625546630903e -re2b5bba1ace2613e8cd3ca6d997756b1b61d77a4 --- cloud_sync.py (.../cloud_sync.py) (revision cc7bbd932684e69aa456c114596625546630903e) +++ cloud_sync.py (.../cloud_sync.py) (revision e2b5bba1ace2613e8cd3ca6d997756b1b61d77a4) @@ -22,7 +22,7 @@ from cloudsync.utils.heartbeat import HeartBeatProvider from cloudsync.handlers.error import Error -VERSION = "0.4.3" +VERSION = "0.4.4" try: arguments = sys.argv @@ -138,9 +138,9 @@ if public_key is None: invalid_params.append("public_key") if len(invalid_params) > 0: - error = Error("{0},2,{1}, invalid credentials".format(OutboundMessageIDs.CS2UI_ERROR.value, - ErrorIDs.CS_SAVE_CREDENTIALS_ERROR.value, - invalid_params)) + error = Error("{0},2,{1}, invalid credentials: {2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + ErrorIDs.CS_SAVE_CREDENTIALS_ERROR.value, + invalid_params)) error_handler.enqueue_error(error=error) return {"invalidAttributes": invalid_params}, BAD_REQUEST Index: cloudsync/common/enums.py =================================================================== diff -u -rcc7bbd932684e69aa456c114596625546630903e -re2b5bba1ace2613e8cd3ca6d997756b1b61d77a4 --- cloudsync/common/enums.py (.../enums.py) (revision cc7bbd932684e69aa456c114596625546630903e) +++ cloudsync/common/enums.py (.../enums.py) (revision e2b5bba1ace2613e8cd3ca6d997756b1b61d77a4) @@ -13,17 +13,16 @@ def mapped_int_value(cls, value): try: return cls._value2member_map_[value] - except: + except Exception: return None @classmethod def mapped_str_value(cls, value): try: return cls._value2member_map_[int(value)] - except: + except Exception: return None - @unique class HDOpModes(RootEnum): MODE_FAUL = 0 # Fault mode Index: cloudsync/handlers/cs_mft_dcs_request_handler.py =================================================================== diff -u -rcc7bbd932684e69aa456c114596625546630903e -re2b5bba1ace2613e8cd3ca6d997756b1b61d77a4 --- cloudsync/handlers/cs_mft_dcs_request_handler.py (.../cs_mft_dcs_request_handler.py) (revision cc7bbd932684e69aa456c114596625546630903e) +++ cloudsync/handlers/cs_mft_dcs_request_handler.py (.../cs_mft_dcs_request_handler.py) (revision e2b5bba1ace2613e8cd3ca6d997756b1b61d77a4) @@ -17,6 +17,7 @@ from cloudsync.handlers.outgoing.handler_cs_to_dcs import * from cloudsync.handlers.incoming.handler_mft_to_cs import * +ERROR_STRING = "{0},2,{1},{2}" class NetworkRequestHandler: def __init__(self, logger: Logger, max_size, output_channel, reachability_provider, error_handler): @@ -79,9 +80,9 @@ error_handler=self.error_handler) self.logger.debug("DRT Request registration resp: {0}".format(response)) except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, - ErrorIDs.CS_REQ_REGISTRATION_ERROR.value, - e)) + error = Error(ERROR_STRING.format(OutboundMessageIDs.CS2UI_ERROR.value, + ErrorIDs.CS_REQ_REGISTRATION_ERROR.value, + e)) self.error_handler.enqueue_error(error=error) elif req.request_type == NetworkRequestType.MFT2CS_REQ_SET_CREDENTIALS: try: @@ -94,7 +95,7 @@ output_channel=self.output_channel, error_handler=self.error_handler) except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(ERROR_STRING.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_SAVE_CREDENTIALS_ERROR.value, e)) self.error_handler.enqueue_error(error=error) @@ -112,7 +113,7 @@ error_handler=self.error_handler ) except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(ERROR_STRING.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_VALIDATE_DEVICE_ERROR.value, e)) self.error_handler.enqueue_error(error=error) @@ -153,7 +154,7 @@ ErrorIDs.CS_SEND_DEVICE_STATE_ERROR.value)) self.error_handler.enqueue_error(error=error) except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(ERROR_STRING.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_SEND_DEVICE_STATE_ERROR.value, e)) self.error_handler.enqueue_error(error=error) @@ -268,7 +269,7 @@ message_body = str(OutboundMessageIDs.CS2UI_REQ_TX_CODE_DISPLAY.value) + ',1,' + treatment_id self.output_channel.enqueue_message(message_body) except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(ERROR_STRING.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_SEND_TREATMENT_REPORT_ERROR.value, e)) self.error_handler.enqueue_error(error=error) Index: cloudsync/handlers/outgoing/handler_cs_to_dcs.py =================================================================== diff -u -rcc7bbd932684e69aa456c114596625546630903e -re2b5bba1ace2613e8cd3ca6d997756b1b61d77a4 --- cloudsync/handlers/outgoing/handler_cs_to_dcs.py (.../handler_cs_to_dcs.py) (revision cc7bbd932684e69aa456c114596625546630903e) +++ cloudsync/handlers/outgoing/handler_cs_to_dcs.py (.../handler_cs_to_dcs.py) (revision e2b5bba1ace2613e8cd3ca6d997756b1b61d77a4) @@ -40,7 +40,7 @@ headers = { 'Content-Type': 'application/x-www-form-urlencoded', - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36' + 'User-Agent': USER_AGENT } cert_paths = (path_certificate, path_private_key) @@ -69,12 +69,12 @@ error_handler.enqueue_error(error=error) return None except requests.exceptions.TooManyRedirects: - error = Error("{0},2,{1},Too many redirects".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(TOO_MANY_REDIRECTS_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_GET_NEW_TOKEN_WITH_CERT_ERROR.value)) error_handler.enqueue_error(error=error) return None except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(GENERAL_EXCEPTION_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_GET_NEW_TOKEN_WITH_CERT_ERROR.value, str(e))) error_handler.enqueue_error(error=error) @@ -87,25 +87,25 @@ error_handler: ErrorHandler) -> requests.Response: try: headers = { - 'Authorization': "Bearer {0}".format(access_token), - 'Content-Type': 'application/json', + 'Authorization': BEARER_HOLDER.format(access_token), + 'Content-Type': CONTENT_TYPE, "X-OrganizationId" : '1', - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36' + 'User-Agent': USER_AGENT } resp = requests.get(url=url, headers=headers) return resp except requests.exceptions.Timeout: - error = Error("{0},2,{1},Registration timeout".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(REGISTRATION_TIMEOUT_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_VERIFY_TOKEN_ERROR.value)) error_handler.enqueue_error(error=error) except requests.exceptions.TooManyRedirects: - error = Error("{0},2,{1},Too many redirects".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(TOO_MANY_REDIRECTS_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_VERIFY_TOKEN_ERROR.value)) error_handler.enqueue_error(error=error) except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(GENERAL_EXCEPTION_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_VERIFY_TOKEN_ERROR.value, str(e))) error_handler.enqueue_error(error=error) @@ -131,26 +131,26 @@ }) headers = { - 'Authorization': "Bearer {0}".format(access_token), - 'Content-Type': 'application/json', - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36' + 'Authorization': BEARER_HOLDER.format(access_token), + 'Content-Type': CONTENT_TYPE, + 'User-Agent': USER_AGENT } response = requests.post(url=url, headers=headers, data=payload) except requests.exceptions.Timeout: - error = Error("{0},2,{1},Registration timeout".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(REGISTRATION_TIMEOUT_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_VALIDATE_DEVICE_ERROR.value)) error_handler.enqueue_error(error=error) return None except requests.exceptions.TooManyRedirects: - error = Error("{0},2,{1},Too many redirects".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(TOO_MANY_REDIRECTS_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_VALIDATE_DEVICE_ERROR.value)) error_handler.enqueue_error(error=error) return None except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(GENERAL_EXCEPTION_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_VALIDATE_DEVICE_ERROR.value, str(e))) error_handler.enqueue_error(error=error) @@ -167,7 +167,7 @@ error_handler.enqueue_error(error=error) return None except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(GENERAL_EXCEPTION_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_VALIDATE_DEVICE_ERROR.value, str(e))) error_handler.enqueue_error(error=error) @@ -188,25 +188,25 @@ """ try: headers = { - 'Authorization': "Bearer {0}".format(access_token), - 'Content-Type': 'application/json', - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36' + 'Authorization': BEARER_HOLDER.format(access_token), + 'Content-Type': CONTENT_TYPE, + 'User-Agent': USER_AGENT } payload = {} resp = requests.put(url=url, headers=headers, data=payload) return resp except requests.exceptions.Timeout: - error = Error("{0},2,{1},Registration timeout".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(REGISTRATION_TIMEOUT_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_SEND_DEVICE_STATE_ERROR.value)) error_handler.enqueue_error(error=error) except requests.exceptions.TooManyRedirects: - error = Error("{0},2,{1},Too many redirects".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(TOO_MANY_REDIRECTS_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_SEND_DEVICE_STATE_ERROR.value)) error_handler.enqueue_error(error=error) except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(GENERAL_EXCEPTION_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_SEND_DEVICE_STATE_ERROR.value, str(e))) error_handler.enqueue_error(error=error) @@ -218,25 +218,25 @@ error_handler: ErrorHandler) -> requests.Response: try: headers = { - 'Authorization': "Bearer {0}".format(access_token), - 'Content-Type': 'application/json', - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36' + 'Authorization': BEARER_HOLDER.format(access_token), + 'Content-Type': CONTENT_TYPE, + 'User-Agent': USER_AGENT } response = requests.get(url=url, headers=headers) except requests.exceptions.Timeout: - error = Error("{0},2,{1},Registration timeout".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(REGISTRATION_TIMEOUT_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_CHECK_IF_PATIENT_WITH_EMR_ID_EXISTS_ERROR.value)) error_handler.enqueue_error(error=error) return None except requests.exceptions.TooManyRedirects: - error = Error("{0},2,{1},Too many redirects".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(TOO_MANY_REDIRECTS_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_CHECK_IF_PATIENT_WITH_EMR_ID_EXISTS_ERROR.value)) error_handler.enqueue_error(error=error) return None except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(GENERAL_EXCEPTION_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_CHECK_IF_PATIENT_WITH_EMR_ID_EXISTS_ERROR.value, str(e))) error_handler.enqueue_error(error=error) @@ -253,7 +253,7 @@ error_handler.enqueue_error(error=error) return None except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(GENERAL_EXCEPTION_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_CHECK_IF_PATIENT_WITH_EMR_ID_EXISTS_ERROR.value, str(e))) error_handler.enqueue_error(error=error) @@ -262,12 +262,12 @@ @log_func def cmd_outgoing_create_temporary_patient(access_token: str, url: str, - error_handler: ErrorHandler) -> dict: + error_handler: ErrorHandler): try: headers = { - 'Authorization': "Bearer {0}".format(access_token), - 'Content-Type': 'application/json', - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36' + 'Authorization': BEARER_HOLDER.format(access_token), + 'Content-Type': CONTENT_TYPE, + 'User-Agent': USER_AGENT } payload = {} @@ -276,17 +276,17 @@ headers=headers, data=payload) except requests.exceptions.Timeout: - error = Error("{0},2,{1},Registration timeout".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(REGISTRATION_TIMEOUT_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_CREATE_TEMPORARY_PATIENT_ERROR.value)) error_handler.enqueue_error(error=error) return None except requests.exceptions.TooManyRedirects: - error = Error("{0},2,{1},Too many redirects".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(TOO_MANY_REDIRECTS_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_CREATE_TEMPORARY_PATIENT_ERROR.value)) error_handler.enqueue_error(error=error) return None except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(GENERAL_EXCEPTION_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_CREATE_TEMPORARY_PATIENT_ERROR.value, str(e))) error_handler.enqueue_error(error=error) @@ -303,7 +303,7 @@ error_handler.enqueue_error(error=error) return None except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(GENERAL_EXCEPTION_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_CREATE_TEMPORARY_PATIENT_ERROR.value, str(e))) error_handler.enqueue_error(error=error) @@ -324,9 +324,9 @@ """ try: headers = { - 'Authorization': "Bearer {0}".format(access_token), - 'Content-Type': 'application/json', - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36' + 'Authorization': BEARER_HOLDER.format(access_token), + 'Content-Type': CONTENT_TYPE, + 'User-Agent': USER_AGENT } payload = {} @@ -345,15 +345,15 @@ data=payload) return resp except requests.exceptions.Timeout: - error = Error("{0},2,{1},Registration timeout".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(REGISTRATION_TIMEOUT_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_SET_PATIENT_DEVICE_ASSOCIATION_ERROR.value)) error_handler.enqueue_error(error=error) except requests.exceptions.TooManyRedirects: - error = Error("{0},2,{1},Too many redirects".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(TOO_MANY_REDIRECTS_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_SET_PATIENT_DEVICE_ASSOCIATION_ERROR.value)) error_handler.enqueue_error(error=error) except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(GENERAL_EXCEPTION_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_SET_PATIENT_DEVICE_ASSOCIATION_ERROR.value, str(e))) error_handler.enqueue_error(error=error) @@ -374,35 +374,29 @@ """ try: headers = { - 'Authorization': "Bearer {0}".format(access_token), - 'Content-Type': 'application/json', - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36' + 'Authorization': BEARER_HOLDER.format(access_token), + 'Content-Type': CONTENT_TYPE, + 'User-Agent': USER_AGENT } payload = treatment_log - # print("paylod: {0}".format(payload)) - resp = requests.post(url=url, headers=headers, data=payload) - # if resp.status_code == BAD_REQUEST: - # if resp.json().get("code", None) == "bad_checksum": - # g_utils.logger.debug("Returned response") - return resp except requests.exceptions.Timeout: - error = Error("{0},2,{1},Registration timeout".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(REGISTRATION_TIMEOUT_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_SEND_TREATMENT_REPORT_ERROR.value)) error_handler.enqueue_error(error=error) return None except requests.exceptions.TooManyRedirects: - error = Error("{0},2,{1},Too many redirects".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(TOO_MANY_REDIRECTS_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_SEND_TREATMENT_REPORT_ERROR.value)) error_handler.enqueue_error(error=error) return None except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, + error = Error(GENERAL_EXCEPTION_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_SEND_TREATMENT_REPORT_ERROR.value, str(e))) error_handler.enqueue_error(error=error) Index: cloudsync/handlers/outgoing/handler_cs_to_mft.py =================================================================== diff -u -rcc7bbd932684e69aa456c114596625546630903e -re2b5bba1ace2613e8cd3ca6d997756b1b61d77a4 --- cloudsync/handlers/outgoing/handler_cs_to_mft.py (.../handler_cs_to_mft.py) (revision cc7bbd932684e69aa456c114596625546630903e) +++ cloudsync/handlers/outgoing/handler_cs_to_mft.py (.../handler_cs_to_mft.py) (revision e2b5bba1ace2613e8cd3ca6d997756b1b61d77a4) @@ -48,8 +48,7 @@ } resp = requests.post(url=url, data=data, - headers=headers, - verify=False) + headers=headers) return resp except requests.exceptions.Timeout: error = Error("{0},2,{1},Registration timeout".format(OutboundMessageIDs.CS2UI_ERROR.value, @@ -73,7 +72,7 @@ def cmd_outgoing_validation_result(invalid_attributes: List[str], hd_serial: str, g_config: dict, - error_handler: ErrorHandler) -> dict: + error_handler: ErrorHandler): """ Sends the validation POST to the manf tool :param invalid_attributes: The list of invalid attributes @@ -108,8 +107,7 @@ g_utils.logger.debug("data: {0}".format(data)) resp = requests.post(url=url, data=data, - headers=headers, - verify=False) + headers=headers) return resp.json() except requests.exceptions.Timeout: error = Error("{0},2,{1},Registration timeout".format(OutboundMessageIDs.CS2UI_ERROR.value, Index: cloudsync/handlers/ui_cs_request_handler.py =================================================================== diff -u -rcc7bbd932684e69aa456c114596625546630903e -re2b5bba1ace2613e8cd3ca6d997756b1b61d77a4 --- cloudsync/handlers/ui_cs_request_handler.py (.../ui_cs_request_handler.py) (revision cc7bbd932684e69aa456c114596625546630903e) +++ cloudsync/handlers/ui_cs_request_handler.py (.../ui_cs_request_handler.py) (revision e2b5bba1ace2613e8cd3ca6d997756b1b61d77a4) @@ -118,15 +118,15 @@ g_config=message.g_config, success_message='CS2MFT_REQ_REGISTRATION request added to network ' 'queue') - except IOError as er: + except IOError: error = Error( "{0},2,{1},Error updating device config file".format(OutboundMessageIDs.CS2UI_ERROR.value, ErrorIDs.CS_SAVE_CONFIG_ERROR.value)) self.error_handler.enqueue_error(error=error) except Exception as e: - error = Error("{0},2,{1},{2}".format(OutboundMessageIDs.CS2UI_ERROR.value, - ErrorIDs.CS_REQ_REGISTRATION_ERROR.value, - e)) + error = Error(GENERAL_EXCEPTION_HOLDER.format(OutboundMessageIDs.CS2UI_ERROR.value, + ErrorIDs.CS_REQ_REGISTRATION_ERROR.value, + e)) self.error_handler.enqueue_error(error=error) # OPERATION MODE @@ -142,7 +142,7 @@ device_state = helpers_device_state_to_cloud_state( HDOpModes.mapped_str_value(message.parameters[0]), HDOpSubModes.mapped_str_value(message.parameters[1])) - except: + except Exception: device_state = DeviceStates.UNKNOWN_STATE error = Error( "{0},2,{1},Unknown device state received from UI".format(OutboundMessageIDs.CS2UI_ERROR.value, Index: cloudsync/utils/globals.py =================================================================== diff -u -rcc7bbd932684e69aa456c114596625546630903e -re2b5bba1ace2613e8cd3ca6d997756b1b61d77a4 --- cloudsync/utils/globals.py (.../globals.py) (revision cc7bbd932684e69aa456c114596625546630903e) +++ cloudsync/utils/globals.py (.../globals.py) (revision e2b5bba1ace2613e8cd3ca6d997756b1b61d77a4) @@ -106,6 +106,14 @@ # TREATMENT TEMPLATE PATH TREATMENT_REPORT_TEMPLATE_PATH = "cloudsync/config/treatment_report_template.json" +# USER_AGENT +USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" +CONTENT_TYPE = "application/json" +BEARER_HOLDER = "Bearer {0}" +TOO_MANY_REDIRECTS_HOLDER = "{0},2,{1},Too many redirects" +GENERAL_EXCEPTION_HOLDER = "{0},2,{1},{2}" +REGISTRATION_TIMEOUT_HOLDER = "{0},2,{1},Registration timeout" + # HTTP CODES OK = 200 BAD_REQUEST = 400 Index: cloudsync/utils/helpers.py =================================================================== diff -u -rcc7bbd932684e69aa456c114596625546630903e -re2b5bba1ace2613e8cd3ca6d997756b1b61d77a4 --- cloudsync/utils/helpers.py (.../helpers.py) (revision cc7bbd932684e69aa456c114596625546630903e) +++ cloudsync/utils/helpers.py (.../helpers.py) (revision e2b5bba1ace2613e8cd3ca6d997756b1b61d77a4) @@ -221,19 +221,6 @@ json.dump(config, f, indent=4) -def helpers_update_config(path: str, config: dict, group: str, section: str, value: Any) -> None: - """ - Writes the configuration - :param path: the path to the configuration file - :param config: the json config - :return: None - """ - if not config.get(group, False): - config[group] = {} - config[group][section] = value - helpers_write_config(path, config) - - def helpers_read_access_token(path: str) -> dict: """ Reads the access token json file, returns it as a dict @@ -278,7 +265,7 @@ return _wrapper -def helpers_read_treatment_log_file(path: str) -> dict: +def helpers_read_treatment_log_file(path: str): treatment_data = helpers_read_treatment_report_template(TREATMENT_REPORT_TEMPLATE_PATH) try: @@ -291,8 +278,6 @@ while counter < len(treatment_log_lines): line = treatment_log_lines[counter].strip() - # print("line {0}: {1}".format(counter, line)) - # print("size of log: {0}".format(len(treatment_log_lines))) if line.startswith(SECTION_START_CHARACTER) and line.endswith(SECTION_STOP_CHARACTER) and counter < ( len(treatment_log_lines) - 2): Index: cloudsync/utils/reachability.py =================================================================== diff -u -rcc7bbd932684e69aa456c114596625546630903e -re2b5bba1ace2613e8cd3ca6d997756b1b61d77a4 --- cloudsync/utils/reachability.py (.../reachability.py) (revision cc7bbd932684e69aa456c114596625546630903e) +++ cloudsync/utils/reachability.py (.../reachability.py) (revision e2b5bba1ace2613e8cd3ca6d997756b1b61d77a4) @@ -34,7 +34,7 @@ try: response = requests.get(url=REACHABILITY_URL, headers=headers) status_code = response.status_code - except requests.exceptions.RequestException as er: + except requests.exceptions.RequestException: status_code = INTERNAL_SERVER_ERROR if status_code == OK: Index: cs.py =================================================================== diff -u -r4ebf654ab1b0d436ce7d171bfe06c6bdc46aca47 -re2b5bba1ace2613e8cd3ca6d997756b1b61d77a4 --- cs.py (.../cs.py) (revision 4ebf654ab1b0d436ce7d171bfe06c6bdc46aca47) +++ cs.py (.../cs.py) (revision e2b5bba1ace2613e8cd3ca6d997756b1b61d77a4) @@ -10,6 +10,7 @@ from subprocess import Popen DELAY = 0.5 +USAGE_FORMAT = "Usage: ./cs.py [debug|info|warning|error]" arguments = sys.argv logging_level = logging.INFO @@ -55,7 +56,7 @@ elif arguments[2] == "error": logging_level = logging.ERROR else: - print("Usage: ./cs.py [debug|info|warning|error]") + print(USAGE_FORMAT) if arguments[1] == "start": start() elif str(arguments[1]) == "stop": @@ -72,6 +73,6 @@ else: print("CloudSync app IS NOT running") else: - print("Usage: ./cs.py [debug|info|warning|error]") + print(USAGE_FORMAT) else: - print("Usage: ./cs.py [debug|info|warning|error]") + print(USAGE_FORMAT)