def LoadAlgorithms(self): """ Load list of algorithms Return None if OK """ if (self.__engine.version_ge('6.0.0')): from masking_api_60.api.algorithm_api import AlgorithmApi from masking_api_60.rest import ApiException else: from masking_api_53.api.algorithm_api import AlgorithmApi from masking_api_53.rest import ApiException self.__api = AlgorithmApi self.__apiexc = ApiException domainlist = DxDomainList() try: api_instance = self.__api(self.__engine.api_client) api_response = api_instance.get_all_algorithms() synclist = DxSyncList() sync = synclist.get_all_algorithms() if api_response.response_list: for c in api_response.response_list: alg = DxAlgorithm(self.__engine) alg.from_alg(c) dom = DxDomainList.get_domain_by_algorithm( c.algorithm_name) if dom: alg.domain_name = dom else: alg.domain_name = '' if c.algorithm_name in sync: alg.sync = 1 self.__algorithmList[c.algorithm_name] = alg else: print_error("No algorithm found") self.__logger.error("No algorithm found") return 1 return None except self.__apiexc as e: print_error(e.body) self.__logger.error(e.body) return 1
def LoadAlgorithms(self): """ Load list of algorithms Return None if OK """ try: api_instance = AlgorithmApi(self.__engine.api_client) api_response = api_instance.get_all_algorithms() synclist = DxSyncList() sync = synclist.get_all_algorithms() # print "DUPKA" # # sys.exit(1) # # api_sync = SyncApi(self.__engine.api_client) # api_sync_response = api_sync.get_all_syncable_objects() # sync = dict([x.object_identifier['algorithmName'], x] # for x in api_sync_response.response_list # if 'algorithmName' in x.object_identifier) if api_response.response_list: for c in api_response.response_list: alg = DxAlgorithm(self.__engine) alg.from_alg(c) dom = DxDomainList.get_domain_by_algorithm( c.algorithm_name) if dom: alg.domain_name = dom else: alg.domain_name = '' if c.algorithm_name in sync: alg.sync = 1 self.__algorithmList[c.algorithm_name] = alg else: print_error("No algorithm found") self.__logger.error("No algorithm found") return 1 return None except ApiException as e: print_error(e.body) self.__logger.error(e.body) return 1
def LoadAlgorithms(self): """ Load list of algorithms Return None if OK """ try: api_instance = AlgorithmApi(self.__engine.api_client) api_response = api_instance.get_all_algorithms() synclist = DxSyncList() sync = synclist.get_all_algorithms() if api_response.response_list: for c in api_response.response_list: alg = DxAlgorithm(self.__engine) alg.from_alg(c) dom = DxDomainList.get_domain_by_algorithm( c.algorithm_name) if dom: alg.domain_name = dom else: alg.domain_name = '' if c.algorithm_name in sync: alg.sync = 1 self.__algorithmList[c.algorithm_name] = alg else: print_error("No algorithm found") self.__logger.error("No algorithm found") return 1 return None except ApiException as e: print_error(e.body) self.__logger.error(e.body) return 1
def sync_worker(p_engine, objecttype, objectname, envname, function_to_call, **kwargs): """ Run an action for list of syncable objects param1: p_engine: engine name from configuration param2: objecttype: objecttype to list, all if None param3: objectname: objectname to list_table_details param4: function_to_call return 0 if objecttype found """ ret = 0 enginelist = get_list_of_engines(p_engine) # objectname = "RandomValueLookup" # objectname = None ret = 0 if enginelist is None: return 1 for engine_tuple in enginelist: engine_obj = DxMaskingEngine(engine_tuple) if engine_obj.get_session(): continue synclist = DxSyncList(objecttype) if (objecttype is None or objecttype == "algorithm") \ and envname is None: if objectname: alglist = [objectname] else: alglist = synclist.get_all_algorithms() for syncref in alglist: syncobj = synclist.get_object_by_type_name( "algorithm", syncref) if syncobj: dynfunc = globals()[function_to_call] ret = ret + dynfunc( object=syncobj, engine_obj=engine_obj, envname='global', name=syncref, **kwargs) if objecttype is None or objecttype == "database_connector" \ or objecttype == "file_connector": envlist = DxEnvironmentList() connlist = DxConnectorsList(envname) if objecttype is None: objtypelist = ["database_connector", "file_connector"] else: objtypelist = [objecttype] for objtype in objtypelist: if objectname: connbynameref = connlist.get_connectorId_by_name( objectname, False) if connbynameref: syncconnref = int(connbynameref[1:]) if synclist.get_object_by_type_name( objtype, syncconnref): connrefs = [syncconnref] else: connrefs = [] else: connrefs = [] else: connrefs = synclist.get_all_object_by_type(objtype) for syncref in connrefs: syncobj = synclist.get_object_by_type_name( objtype, syncref) if syncobj.object_type == 'DATABASE_CONNECTOR': connobj = connlist.get_by_ref("d" + str(syncref)) else: connobj = connlist.get_by_ref("f" + str(syncref)) if connobj is None: # limited by env continue envobj = envlist.get_by_ref(connobj.environment_id) dynfunc = globals()[function_to_call] ret = ret + dynfunc( object=syncobj, engine_obj=engine_obj, envname=envobj.environment_name, name=connobj.connector_name, **kwargs) if objecttype is None or objecttype == "database_ruleset" \ or objecttype == "file_ruleset": envlist = DxEnvironmentList() connlist = DxConnectorsList(envname) rulesetList = DxRulesetList(envname) if objecttype is None: objtypelist = ["database_ruleset", "file_ruleset"] else: objtypelist = [objecttype] for objtype in objtypelist: if objectname: rulesetrefs = [] rulesetref = rulesetList.get_all_rulesetId_by_name( objectname) if rulesetref: for rsref in rulesetref: if synclist.get_object_by_type_name( objtype, rsref): rulesetrefs.append(rsref) else: rulesetrefs = [] else: rulesetrefs = [] else: rulesetrefs = synclist.get_all_object_by_type(objtype) for syncref in rulesetrefs: syncobj = synclist.get_object_by_type_name(objtype, syncref) rulesetobj = rulesetList.get_by_ref(syncref) if rulesetobj is None: # limited by env continue connobj = connlist.get_by_ref(rulesetobj.connectorId) envobj = envlist.get_by_ref(connobj.environment_id) dynfunc = globals()[function_to_call] ret = ret + dynfunc( object=syncobj, engine_obj=engine_obj, envname=envobj.environment_name, name=rulesetobj.ruleset_name, **kwargs) if (objecttype is None or objecttype == "global_object" or objecttype == "key" or objecttype == "domain") \ and envname is None: if objecttype is None: objtypelist = ["global_object", "key", "domain"] else: objtypelist = [objecttype] for objtype in objtypelist: if objectname: objlist = [objectname] else: objlist = synclist.get_all_object_by_type(objtype) for syncref in objlist: syncobj = synclist.get_object_by_type_name(objtype, syncref) if syncobj: dynfunc = globals()[function_to_call] ret = ret + dynfunc( object=syncobj, engine_obj=engine_obj, envname='global', name=syncref, **kwargs) if objecttype is None or objecttype == "masking_job": envlist = DxEnvironmentList() joblist = DxJobsList() joblist.LoadJobs(envname) connlist = DxConnectorsList(envname) rulesetlist = DxRulesetList(envname) if objectname: jobref = joblist.get_jobId_by_name(objectname) if synclist.get_object_by_type_name("masking_job", jobref): jobrefs = [jobref] else: jobrefs = [] else: jobrefs = synclist.get_all_object_by_type("masking_job") for syncref in jobrefs: syncobj = synclist.get_object_by_type_name("masking_job", syncref) jobobj = joblist.get_by_ref(syncref) if envname and jobobj is None: # limited by env continue rulesetobj = rulesetlist.get_by_ref(jobobj.ruleset_id) connectorobj = connlist.get_by_ref(rulesetobj.connectorId) envobj = envlist.get_by_ref(connectorobj.environment_id) dynfunc = globals()[function_to_call] ret = ret + dynfunc( object=syncobj, engine_obj=engine_obj, envname=envobj.environment_name, name=jobobj.job_name, **kwargs) return ret