def copy(self, ruleset_id, newname): """ Add an Ruleset to a list and Engine :param ruleset: Ruleset id of the existing ruleset :param newname: Name of the new ruleset return new ruleset_id if OK, None if failure """ ruleset = self.get_by_ref(ruleset_id) if ruleset.type == 'Database': newruleset = DxDatabaseRuleset(self.__engine) newruleset.from_ruleset(ruleset) newruleset.ruleset_name = newname elif ruleset.type == 'File': newruleset = DxFileRuleset(self.__engine) newruleset.from_ruleset(ruleset) newruleset.ruleset_name = newname if (newruleset.add() is None): self.__logger.debug("Adding ruleset %s to list" % newruleset) self.__rulesetList[newruleset.ruleset_id] = newruleset return newruleset.ruleset_id else: return None
def ruleset_add(p_engine, p_username, rulesetname, connectorname, envname): """ Add ruleset to Masking engine param1: p_engine: engine name from configuration param2: rulesetname: ruleset name param3: connectorname: connectorname name param4: envname: environment name return 0 if added, non 0 for error """ ret = 0 logger = logging.getLogger() enginelist = get_list_of_engines(p_engine, p_username) if enginelist is None: return 1 for engine_tuple in enginelist: engine_obj = DxMaskingEngine(engine_tuple) if engine_obj.get_session(): continue envlist = DxEnvironmentList() envlist.LoadEnvironments() rulelist = DxRulesetList() connlist = DxConnectorsList(envname) #connlist.LoadConnectors() logger.debug("Connector is %s" % connectorname) connref = connlist.get_connectorId_by_name(connectorname) connobj = connlist.get_by_ref(connref) if connobj: if connobj.is_database: ruleset = DxDatabaseRuleset(engine_obj) ruleset.create_database_ruleset( ruleset_name=rulesetname, database_connector_id=connobj.connectorId, refresh_drops_tables=None) else: ruleset = DxFileRuleset(engine_obj) ruleset.create_file_ruleset( ruleset_name=rulesetname, file_connector_id=connobj.connectorId) if rulelist.add(ruleset): ret = ret + 1 else: ret = ret + 1 return ret
def LoadRulesets_worker(self, environment_name, env_id): """ Load list of rule sets Return None if OK """ self.__rulesetList.clear() DxConnectorsList(environment_name) self.__api = DatabaseRulesetApi self.__fileapi = FileRulesetApi self.__apiexc = ApiException try: api_instance = self.__api(self.__engine.api_client) if environment_name: environment_id = DxEnvironmentList.get_environmentId_by_name( environment_name) if environment_id: database_rulesets = paginator( api_instance, "get_all_database_rulesets", environment_id=environment_id, _request_timeout=self.__engine.get_timeout()) else: return 1 else: if env_id: environment_id = env_id database_rulesets = paginator( api_instance, "get_all_database_rulesets", environment_id=environment_id, _request_timeout=self.__engine.get_timeout()) else: environment_id = None database_rulesets = paginator( api_instance, "get_all_database_rulesets") if database_rulesets.response_list: for c in database_rulesets.response_list: ruleset = DxDatabaseRuleset(self.__engine) ruleset.from_ruleset(c) self.__rulesetList[c.database_ruleset_id] = ruleset else: if environment_id: self.__logger.error("No database ruleset found for " "environment name %s" % environment_name) else: self.__logger.error("No database ruleset found") api_instance = self.__fileapi(self.__engine.api_client) if environment_id: file_rulesets = paginator( api_instance, "get_all_file_rulesets", environment_id=environment_id) else: file_rulesets = paginator( api_instance, "get_all_file_rulesets") if file_rulesets.response_list: for c in file_rulesets.response_list: ruleset = DxFileRuleset(self.__engine) ruleset.from_ruleset(c) self.__rulesetList[c.file_ruleset_id] = ruleset else: if environment_id: self.__logger.error("No file ruleset found for " "environment name %s" % environment_name) else: self.__logger.error("No file ruleset found") except self.__apiexc as e: print_error("Can't load ruleset %s" % e.body) return 1
def LoadRulesets_worker(self, environment_name, env_id): """ Load list of rule sets Return None if OK """ if self.__loaded_engine is None: self.__loaded_engine = self.__engine.get_name() #if self.__loaded_engine == self.__engine.get_name() and self.__rulesetList != {}: # return None #else: # delete a list as we can have multi engines self.__rulesetList.clear() self.__loaded_engine = self.__engine.get_name() DxConnectorsList(environment_name) if (self.__engine.version_ge('6.0.0')): from masking_api_60.api.database_ruleset_api import DatabaseRulesetApi from masking_api_60.api.file_ruleset_api import FileRulesetApi from masking_api_60.rest import ApiException else: from masking_api_53.api.database_ruleset_api import DatabaseRulesetApi from masking_api_53.api.file_ruleset_api import FileRulesetApi from masking_api_53.rest import ApiException self.__api = DatabaseRulesetApi self.__fileapi = FileRulesetApi self.__apiexc = ApiException try: api_instance = self.__api(self.__engine.api_client) if environment_name: environment_id = DxEnvironmentList.get_environmentId_by_name( environment_name) if environment_id: database_rulesets = paginator( api_instance, "get_all_database_rulesets", environment_id=environment_id, _request_timeout=self.__engine.get_timeout()) else: return 1 else: if env_id: environment_id = env_id database_rulesets = paginator( api_instance, "get_all_database_rulesets", environment_id=environment_id, _request_timeout=self.__engine.get_timeout()) else: environment_id = None database_rulesets = paginator(api_instance, "get_all_database_rulesets") if database_rulesets.response_list: for c in database_rulesets.response_list: ruleset = DxDatabaseRuleset(self.__engine) ruleset.from_ruleset(c) self.__rulesetList[c.database_ruleset_id] = ruleset else: if environment_id: self.__logger.error("No database ruleset found for " "environment name %s" % environment_name) else: self.__logger.error("No database ruleset found") api_instance = self.__fileapi(self.__engine.api_client) if environment_id: file_rulesets = paginator(api_instance, "get_all_file_rulesets", environment_id=environment_id) else: file_rulesets = paginator(api_instance, "get_all_file_rulesets") if file_rulesets.response_list: for c in file_rulesets.response_list: ruleset = DxFileRuleset(self.__engine) ruleset.from_ruleset(c) self.__rulesetList[c.file_ruleset_id] = ruleset else: if environment_id: self.__logger.error("No file ruleset found for " "environment name %s" % environment_name) else: self.__logger.error("No file ruleset found") except self.__apiexc as e: print_error("Can't load ruleset %s" % e.body) return 1