def profilejob_add(p_engine, params): """ Add profile job to Masking engine param1: p_engine: engine name from configuration param2: params: job parameters return 0 if added, non 0 for error """ ret = 0 enginelist = get_list_of_engines(p_engine) logger = logging.getLogger() envname = params['envname'] jobname = params['jobname'] rulesetname = params['rulesetname'] profilename = params['profilename'] if enginelist is None: return 1 for engine_tuple in enginelist: engine_obj = DxMaskingEngine(engine_tuple) if engine_obj.get_session(): continue joblist = DxProfileJobsList() envlist = DxEnvironmentList() rulesetlist = DxRulesetList() profilesetlist = DxProfilesList() profileref = profilesetlist.get_profileSetId_by_name(profilename) envlist.LoadEnvironments() logger.debug("Envname is %s, job name is %s" % (envname, jobname)) rulesetlist.LoadRulesets(envname) rulesetref = rulesetlist.get_rulesetId_by_name(rulesetname) job = DxProfileJob(engine_obj, None) job.ruleset_id = rulesetref job.job_name = jobname job.profile_set_id = profileref for p in masking_params_list: if params[p] is not None: if params[p] == 'Y': value = True elif params[p] == 'N': value = False else: value = params[p] setattr(job, p, value) if joblist.add(job): ret = ret + 1 return ret
def profile_add(p_engine, p_username, profilename, expname, description): """ Add profile to engine param1: p_engine: engine name from configuration param2: profilename: profile name param3: expname: expression list names param4: description: profile description return 0 if profile was added """ 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 # load all objects profilelist = DxProfilesList() probj = DxProfile() explist = probj.set_expressions_using_names(expname) if explist: probj.create_profile( profile_set_name = profilename, created_by = engine_obj.get_username(), description = description, profile_expression_ids=explist ) if profilelist.add(probj): ret = ret + 1 else: ret = ret + 1 return ret
def do_update(**kwargs): jobref = kwargs.get('jobref') joblist = kwargs.get('joblist') params = kwargs.get('params') jobobj = joblist.get_by_ref(jobref) update = False logger = logging.getLogger() if "rulesetname" in params and params['rulesetname'] != None: rulesetname = params['rulesetname'] # as job is in particular environment # new ruleset need to be search in same environment # job metadata doesn't return environment id so it has to be # found by linking old ruleset via connector id to environment rulesetlist = DxRulesetList() #rulesetlist.LoadRulesets(None) connlist = DxConnectorsList() connlist.LoadConnectors(None) oldrulesetref = jobobj.ruleset_id logger.debug("old ruleset %s" % oldrulesetref) oldruleobj = rulesetlist.get_by_ref(oldrulesetref) oldconnobj = connlist.get_by_ref(oldruleobj.connectorId) rulesetlist.LoadRulesetsbyId(oldconnobj.environment_id) rulesetref = rulesetlist.get_rulesetId_by_name(rulesetname) logger.debug("new ruleset %s" % rulesetref) if rulesetref != oldrulesetref: update = True jobobj.ruleset_id = rulesetref if type(jobobj) == dxm.lib.DxJobs.DxJob.DxJob: for p in optional_params_list: if params[p] is not None: update = True if params[p] == 'Y': value = True elif params[p] == 'N': value = False else: value = params[p] setattr(jobobj.obj, p, value) dmo = jobobj.database_masking_options for p in optional_options_list: if params[p] is not None: update = True if params[p] == 'Y': value = True elif params[p] == 'N': value = False else: value = params[p] setattr(dmo, p, value) if params["prescript"]=='': dmo.prescript = None elif params["prescript"]: scriptname = os.path.basename(params["prescript"].name) prescript = DxMaskingScriptJob(name=scriptname, contents=''.join(params["prescript"].readlines())) dmo.prescript = prescript if params["postscript"]=='': dmo.postscript = None if params["postscript"]: scriptname = os.path.basename(params["postscript"].name) postscript = DxMaskingScriptJob(name=scriptname, contents = ''.join(params["postscript"].readlines())) dmo.postscript = postscript else: if "profilename" in params and params['rulesetname'] != None: profilename = params['profilename'] oldprofile = jobobj.profile_set_id logger.debug("old profile %s" % oldprofile) profilelist = DxProfilesList() profileref = profilelist.get_profileSetId_by_name(profilename) logger.debug("new profile %s" % profileref) if profileref != oldprofile: update = True jobobj.profile_set_id = profileref for p in masking_params_list: if params[p] is not None: update = True if params[p] == 'Y': value = True elif params[p] == 'N': value = False else: value = params[p] setattr(jobobj.obj, p, value) if update: return jobobj.update() else: print_message('Nothing to update') return 1
def profile_worker(**kwargs): """ Profile worker - run a dynamic action on profile object p_engine: engine name from configuration profilename: profile name to list expname: expression name to list mapping: print expression name with profile function_to_call: function name to call for every profile object kwargs: passed to dynamic action return sum of return codes of dynamic action run on all selected expressions """ p_engine = kwargs.get('p_engine') p_username = kwargs.get('p_username') profilename = kwargs.get('profilename') expname = kwargs.get('expname') function_to_call = kwargs.get('function_to_call') mapping = kwargs.get('mapping') ret = 0 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 # load all objects profilesetlist = DxProfilesList() profileexplist = DxProfileExpList() profiles = [] if profilename is None: profiles = profilesetlist.get_allref() else: profile = profilesetlist.get_profileSetId_by_name(profilename) profiles.append(profile) if profile is None: ret = ret + 1 continue for profileref in profiles: profobj = profilesetlist.get_by_ref(profileref) if not mapping: dynfunc = globals()[function_to_call] dynfunc(profobj=profobj, engine_obj=engine_obj, profilesetlist=profilesetlist, **kwargs) else: expression_list = [] if expname: exp = profileexplist.get_profileExpId_by_name(expname) if exp is None: ret = ret + 1 continue else: if exp in profobj.profile_expression_ids: expression_list.append(exp) else: expression_list = profobj.profile_expression_ids for pe in expression_list: proexpobj = profileexplist.get_by_ref(pe) dynfunc = globals()[function_to_call] dynfunc( profobj=profobj, proexpobj=proexpobj, engine_obj=engine_obj, **kwargs) return ret