示例#1
0
def domain_add(p_engine, domain_name, classification, default_algname):
    """
    Add the domain to the Masking Engine
    param1: p_engine: engine name from configuration
    param2: domain_name: domain name
    param3: classification: domain classification
    param4: default_algname: default algorithm name
    return 0 if added, non 0 for error
    """

    ret = 0

    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

        domainlist = DxDomainList()
        domobj = DxDomain(engine_obj)
        # set required properties
        domobj.create_domain(domain_name = domain_name, domain_classification=classification, default_algorithm_code = default_algname)
        
        if domainlist.add(domobj):
            ret = ret + 1

    return ret
示例#2
0
def domain_delete(p_engine, domain_name):
    """
    Delete the domain from the Masking Engine
    param1: p_engine: engine name from configuration
    param2: domain_name: domain name
    return 0 if added, non 0 for error
    """

    ret = 0

    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

        domainlist = DxDomainList()
        if domainlist.delete(domain_name):
            ret = ret + 1

    return ret
示例#3
0
def domain_list(p_engine, format, domainname):
    """
    Print list of algorithms
    param1: p_engine: engine name from configuration
    param2: domainname: domain name to list, all if None
    return 0 if domain name found
    """

    ret = 0

    logger = logging.getLogger()

    data = DataFormatter()
    data_header = [
                    ("Engine name", 30),
                    ("Domain name", 32)
                  ]
    data.format_type = format
    data.create_header(data_header)

    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


        domainlist = DxDomainList()
        domainref_list = []

        if domainname:
            domobj = domainlist.get_by_ref(domainname)
            if domobj:
                domainref_list.append(domobj.domain_name)
            else:
                print_error("Domain {} not found".format(domainname))
                return 1
        else:
            domainref_list = domainlist.get_allref()

        for domainref in domainref_list:
            domobj = domainlist.get_by_ref(domainref)
            data.data_insert(
                              engine_tuple[0],
                              domobj.domain_name,
                            )


        print("")
        print (data.data_output(False))
        print("")

    return ret
示例#4
0
    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
示例#5
0
def algorithm_worker(p_engine, algname, **kwargs):
    """
    Select an algorithm and run action on it
    param1: p_engine: engine name from configuration
    param2: algname: algorithm name
    kwargs: parameters to pass including function name to call
    return 0 if algname found
    """

    ret = 0

    function_to_call = kwargs.get('function_to_call')

    enginelist = get_list_of_engines(p_engine)

    if enginelist is None:
        return 1

    for engine_tuple in enginelist:
        engine_obj = DxMaskingEngine(engine_tuple[0], engine_tuple[1],
                                     engine_tuple[2], engine_tuple[3])

        if engine_obj.get_session():
            continue

        domainlist = DxDomainList()
        domainlist.LoadDomains()

        alglist = DxAlgorithmList()

        algref_list = []

        algobj = alglist.get_by_ref(algname)
        if algobj is None:
            ret = ret + 1
            continue

        dynfunc = globals()[function_to_call]
        if dynfunc(algobj=algobj, engine_obj=engine_obj, **kwargs):
            ret = ret + 1

    return ret
示例#6
0
def domain_update(p_engine, p_username, domain_name, classification,
                  default_algname):
    """
    Update the domain to the Masking Engine
    param1: p_engine: engine name from configuration
    param2: domain_name: domain name
    param3: classification: domain classification
    param4: default_algname: default algorithm name
    return 0 if added, non 0 for error
    """

    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

        domainlist = DxDomainList()
        domobj = domainlist.get_domain_by_name(domain_name)

        if not domobj:
            print_error("Domain {} not found".format(domain_name))
            return 1

        # set required properties
        if classification:
            domobj.classification = classification

        if default_algname:
            domobj.default_algorithm_code = default_algname

        if domobj.update():
            ret = ret + 1

    return ret
示例#7
0
    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
示例#8
0
    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
示例#9
0
def algorithm_list(p_engine, format, algname):
    """
    Print list of algorithms
    param1: p_engine: engine name from configuration
    param2: format: output format
    param2: algname: algname name to list, all if None
    return 0 if algname found
    """

    ret = 0

    data = DataFormatter()
    data_header = [
        ("Engine name", 30),
        ("Algorithm name", 30),
        ("Domain name", 32),
        ("Syncable", 9),
        ("Algorithm type", 30),
    ]
    data.create_header(data_header)
    data.format_type = format
    enginelist = get_list_of_engines(p_engine)

    if enginelist is None:
        return 1

    for engine_tuple in enginelist:
        engine_obj = DxMaskingEngine(engine_tuple[0], engine_tuple[1],
                                     engine_tuple[2], engine_tuple[3])

        if engine_obj.get_session():
            continue

        domainlist = DxDomainList()
        domainlist.LoadDomains()

        alglist = DxAlgorithmList()
        alglist.LoadAlgorithms()

        algref_list = []

        if algname:
            algobj = alglist.get_by_ref(algname)
            if algobj:
                algref_list.append(algobj.algorithm_name)
        else:
            algref_list = alglist.get_allref()

        for algref in algref_list:
            algobj = alglist.get_by_ref(algref)

            if algobj.sync:
                syncable = 'Y'
            else:
                syncable = 'N'

            data.data_insert(engine_tuple[0], algobj.algorithm_name,
                             algobj.domain_name, syncable,
                             algobj.algorithm_type)

            #algobj.export()

        print("")
        print(data.data_output(False))
        print("")

    return ret