Exemplo n.º 1
0
def columns_copy(engine_obj, meta_id, new_meta_id):
    """
    Copy columns from one meta object to other one
    :param1 engine_obj: Masking engine
    :param2 meta_id: source meta id
    :param3 new_meta_id: destination meta id
    return 0 if OK
    """

    ret = 0

    logger = logging.getLogger()

    collist = DxColumnList()
    if collist.LoadColumns(metadata_id=meta_id, is_masked=True) == 1:
        logger.debug("Problem with loading masked columns for meta %s" %
                     meta_id)
        return 1

    newcollist = DxColumnList()
    if newcollist.LoadColumns(metadata_id=new_meta_id) == 1:
        logger.debug("Problem with loading columns for new meta %s" %
                     new_meta_id)
        return 1

    for colref in collist.get_allref():
        colobj = collist.get_by_ref(colref)
        newcolref = newcollist.get_column_id_by_name(colobj.cf_meta_name)
        newcol = newcollist.get_by_ref(newcolref)
        if type(newcol) == DxDBColumn:
            newcol.from_column(colobj)
            newcol.table_metadata_id = new_meta_id
            newcol.column_metadata_id = newcolref
        else:
            newcol.from_file(colobj)
            newcol.file_field_metadata_id = newcolref
            newcol.file_format_id = new_meta_id
        if newcol.update():
            ret = ret + 1

    return ret
Exemplo n.º 2
0
def column_worker(p_engine,
                  sortby,
                  rulesetname,
                  envname,
                  metaname,
                  columnname,
                  filter_algname,
                  filter_is_masked,
                  algname,
                  is_masked,
                  domainname,
                  function_to_call,
                  data=None,
                  inventory=None,
                  **kwargs):
    """
    Select a column using all filter parameters
    and run action defined in function_to_call

    param1: p_engine: engine name from configuration
    param2: sortby: sort by output if needed
    param3: rulesetname: ruleset name
    param4: envname: environment name
    param5: metaname: meta name (table or file)
    param6: columnname: column name (column or field)
    param7: filter_algname: algorithm name to filter
    param8: filter_is_masked: is masked fileter
    param9: algname: new algorithm to set
    param10: is_masked: set masking False/True
    param11: domainname: new domain to set
    param12: function_to_call: function name to call
    param13: data: output object
    return 0 action is processed without issues
    """

    ret = 0

    logger = logging.getLogger()

    enginelist = get_list_of_engines(p_engine)

    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(envname)
        connlist = DxConnectorsList(envname)
        metalist = DxMetaList()

        rulesetref_list = []

        if rulesetname:
            ruleref = rulelist.get_rulesetId_by_name(rulesetname)
            if ruleref:
                rulesetref_list.append(ruleref)
        else:
            rulesetref_list = rulelist.get_allref()

        for ruleref in rulesetref_list:
            ruleobj = rulelist.get_by_ref(ruleref)
            connobj = connlist.get_by_ref(ruleobj.connectorId)

            if connobj:
                envobj = envlist.get_by_ref(connobj.environment_id)
            else:
                envobj = None

            metalist.LoadMeta(ruleobj.ruleset_id)

            metasetref_list = []

            if metaname:
                metaref = metalist.get_MetadataId_by_name(metaname, 1)
                if metaref:
                    metasetref_list.append(metaref)
            else:
                metasetref_list = metalist.get_allref()

            for metaid in metasetref_list:
                metaobj = metalist.get_by_ref(metaid)
                collist = DxColumnList()
                collist.LoadColumns(metadata_id=metaid,
                                    is_masked=filter_is_masked)

                colsetref_list = []

                colcount = kwargs.get("colcount")
                if colcount is not None:
                    colcount.extend(collist.get_allref())

                if columnname:
                    colref = collist.get_column_id_by_name(columnname)
                    logger.debug("Column ref with name %s : %s" %
                                 (columnname, colref))
                    if colref:
                        colsetref_list.append(colref)
                else:
                    colsetref_list = collist.get_allref()

                logger.debug("List of columns to process : %s" %
                             colsetref_list)

                if filter_algname:
                    colsetref_masked = collist.get_column_id_by_algorithm(
                        filter_algname)
                    logger.debug("List of columns with algorithm %s : %s" %
                                 (filter_algname, colsetref_masked))
                    colsetref_list = list(
                        set(colsetref_list)
                        & set(colsetref_masked))
                    logger.debug("Intersection with column name filter %s" %
                                 colsetref_masked)

                for colref in colsetref_list:
                    colobj = collist.get_by_ref(colref)

                    dynfunc = globals()[function_to_call]
                    ret = ret + dynfunc(data=data,
                                        engine=engine_tuple,
                                        envobj=envobj,
                                        ruleobj=ruleobj,
                                        metaobj=metaobj,
                                        colobj=colobj,
                                        algname=algname,
                                        is_masked=is_masked,
                                        domainname=domainname,
                                        inventory=inventory,
                                        **kwargs)
    return ret