Ejemplo n.º 1
0
    def add(self):

        if (self.obj.driver_name is None):
            print_error("Driver name is required")
            self.__logger.error("Driver name is required")
            return 1

        if (self.obj.driver_class_name is None):
            print_error("Driver class name is required")
            self.__logger.error("Driver class name is required")
            return 1

        try:
            self.__logger.debug("create driver input %s" % str(self))
            api_instance = self.__api(self.__engine.api_client)
            self.__logger.debug("API instance created")
            response = api_instance.create_jdbc_driver(body=self.obj)
            self.from_driver(response)

            self.__logger.debug("driver response %s" % str(response))

            print_message("Driver {} added".format(self.obj.driver_name))
            return 0
        except self.__apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 2
0
    def add(self):
        """
        Add application to Masking engine and print status message
        return a None if non error
        return 1 in case of error
        """

        if (self.application_name is None):
            print "Application name is required"
            self.__logger.error("Application name is required")
            return 1

        api_instance = ApplicationApi(self.__engine.api_client)

        try:
            self.__logger.debug("create application input %s" % str(self))
            response = api_instance.create_application(
                self, _request_timeout=self.__engine.get_timeout())
            self.__logger.debug("create application response %s" %
                                str(response))

            print_message("Application %s added" % self.application_name)
        except ApiException as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 3
0
def profile_export(p_engine, profilename, exportfile):
    """
    Export list of Profile sets into csv
    param1: p_engine: engine name from configuration
    param2: profilename: profile name to list
    param3: exportfile: file location
    return 0 if profile name found
    """
    data = DataFormatter()
    data_header = [("Profile name", 30), ("Expression name", 30)]

    data.create_header(data_header)
    data.format_type = "csv"
    ret = profile_worker(p_engine=p_engine,
                         profilename=profilename,
                         exportfile=exportfile,
                         function_to_call='do_profileexport',
                         data=data,
                         mapping=True)

    if ret == 0:
        output = data.data_output(False)
        try:
            exportfile.write(output)
            exportfile.close()
            print_message("Profile(s) saved to file %s" % exportfile.name)
            return 0
        except Exception as e:
            print_error("Problem with file %s Error: %s" %
                        (exportfile.name, str(e)))
            return 1

    else:
        return 1
Ejemplo n.º 4
0
    def wait_for_task(self):
        """
        """

        api_instance = self.__api(self.__engine.api_client)
        try:
            running = True
            while (running):
                self.__logger.debug("wait async input %s" % str(self))
                response = api_instance.get_async_task(
                    self.obj.async_task_id,
                    _request_timeout=self.__engine.get_timeout())
                self.__logger.debug("wait async response %s" % str(response))
                if response.status != "RUNNING":
                    running = False
                sleep(1)
                print_message("Waiting for task %s to complete " %
                              self.obj.async_task_id)

            if response.status == "SUCCEEDED":
                print_message("Task finished sucesfully")
                return 0
            else:
                print_error("Task finished with status %s" % response.status)
                return 1
        except self.__apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 5
0
    def update(self):
        """
        Update file field data to Masking engine and print status message
        return a None if non error
        return 1 in case of error
        """

        if (self.obj.file_field_metadata_id is None):
            print_error("file_field_metadata_id is required")
            self.__logger.error("file_field_metadata_id is required")
            return 1

        try:
            if self.obj.date_format == '':
                self.date_format = None

            self.__logger.debug("create field input %s" % str(self))
            api_instance = self.__api(self.__engine.api_client)
            response = api_instance.update_file_field_metadata(
                self.obj.file_field_metadata_id, self.obj)
            self.__logger.debug("field response %s" % str(response))

            print_message("Field %s updated" % self.obj.field_name)
            return None
        except self.__apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 6
0
    def add(self):
        """
        Add table to Masking engine and print status message
        return 0 if non error
        return 1 in case of error
        """

        if (self.table_name is None):
            print "Table name is required"
            self.__logger.error("Table name is required")
            return 1

        if (self.ruleset_id is None):
            print "ruleset_id is required"
            self.__logger.error("ruleset_id is required")
            return 1

        try:
            self.__logger.debug("create table input %s" % str(self))
            api_instance = TableMetadataApi(self.__engine.api_client)
            self.__logger.debug("API instance created")
            response = api_instance.create_table_metadata(self)
            self.table_metadata_id = response.table_metadata_id

            self.__logger.debug("table response %s" % str(response))

            print_message("Table %s added" % self.table_name)
            return 0
        except ApiException as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 7
0
    def add(self):
        """
        Add File type to Masking engine and print status message
        return a None if non error
        return 1 in case of error
        """

        if (self.obj.file_format_name is None):
            print_error("File format name is required")
            self.__logger.error("File format name is required")
            return 1

        if (self.obj.file_format_type is None):
            print_error("File format type is required")
            self.__logger.error("File format type is required")
            return 1

        try:
            self.__logger.debug("create filetype input %s" % str(self))
            api_instance = self.__api(self.__engine.api_client)
            self.__logger.debug("API instance created")
            response = api_instance.create_file_format(self.obj.file_format_name,
                                                       self.obj.file_format_type)
            self.from_filetype(response)

            self.__logger.debug("filetype response %s"
                                % str(response))

            print_message("Filetype %s added" % self.obj.file_format_name)
            return 0
        except self.__apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 8
0
    def add(self):
        """
        Add connector to engine
        Return 0 if OK
        """
        payload_dict = self.get_properties()
        if payload_dict is None:
            print_error('Some required property not found')
            return 1

        try:
            self.__logger.debug("create connector input %s" % str(self))
            api_instance = DatabaseConnectorApi(self.__engine.api_client)
            response = api_instance.create_database_connector(
                self, _request_timeout=self.__engine.get_timeout())
            self.database_connector_id = response.database_connector_id

            self.__logger.debug("connector response %s" % str(response))

            print_message("Connector %s added" % self.connector_name)
            return 0
        except ApiException as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 9
0
def update_algorithm(**kwargs):
    """
    Update algorithm
    """

    colobj = kwargs.get('colobj')
    algname = kwargs.get('algname')
    domainname = kwargs.get('domainname')
    ruleobj = kwargs.get('ruleobj')
    metaobj = kwargs.get('metaobj')
    is_masked = kwargs.get('is_masked')

    colobj.is_masked = is_masked

    if algname == 'None':
        algname = None
        domainname = None
        colobj.is_masked = False

    colobj.algorithm_name = algname
    colobj.domain_name = domainname
    if colobj.update():
        print_error(
            "Problem with updating column for "
            "ruleset %s meta %s column %s" %
            (ruleobj.ruleset_name, metaobj.meta_name, colobj.cf_meta_name))
        return 1
    else:
        print_message("Algorithm %s domain %s updated for "
                      "ruleset %s meta %s column %s" %
                      (algname, domainname, ruleobj.ruleset_name,
                       metaobj.meta_name, colobj.cf_meta_name))
        return 0
Ejemplo n.º 10
0
    def add(self):
        """
        Add ruleset to Masking engine and print status message
        return a None if non error
        return 1 in case of error
        """

        if (self.ruleset_name is None):
            print "Ruleset name is required"
            self.__logger.error("Ruleset name is required")
            return 1

        if (self.database_connector_id is None):
            print "Database connector Id is required"
            self.__logger.error("Database connector ID is required")
            return 1

        try:
            self.__logger.debug("create database ruleset input %s" % str(self))

            api_instance = DatabaseRulesetApi(self.__engine.api_client)
            response = api_instance.create_database_ruleset(
                self, _request_timeout=self.__engine.get_timeout())
            self.database_ruleset_id = response.database_ruleset_id

            self.__logger.debug("ruleset response %s" % str(response))

            print_message("Ruleset %s added" % self.ruleset_name)
            return None
        except ApiException as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 11
0
    def update(self):
        """
        Update connector on engine
        Return None if OK
        """

        api_instance = DatabaseConnectorApi(self.__engine.api_client)
        body = DatabaseConnector()

        for k in self.attribute_map.keys():
            if getattr(self, k) is not None:
                setattr(body, k, getattr(self, k))

        try:
            self.__logger.debug("update connector input %s" % str(self))
            response = api_instance.update_database_connector(
                self.database_connector_id,
                body,
                _request_timeout=self.__engine.get_timeout())
            self.__logger.debug("update connector response %s" % str(response))

            self.database_connector_id = response.database_connector_id
            print_message("Connector %s updated" % self.connector_name)
        except ApiException as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 12
0
    def cancel(self):
        """
        Cancel running job in Engine
        return a 0 if non error
        return 1 in case of error
        """

        try:
            execid = self.__lastExec.execution_id
            exec_api = self.__apiexec(self.__engine.api_client)
            self.__logger.debug("Stopping execution %s" % str(execid))
            execjob = exec_api.cancel_execution(execid)
            self.__logger.debug("Stopping execution response %s" %
                                str(execjob))
            while execjob.status == 'RUNNING':
                time.sleep(1)
                execjob = exec_api.get_execution_by_id(execid)

            print_message(execjob)
            return 0

        except self.__apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 13
0
def do_check(**kwargs):
    """
    Compare
    """

    ruleref = kwargs.get('ruleref')
    rulelist = kwargs.get('rulelist')
    envlist = DxEnvironmentList
    envname = kwargs.get('envname')
    ruleset = kwargs.get('ruleset')
    rulesetname = kwargs.get('rulesetname')
    p_engine = kwargs.get('p_engine')

    connname = ruleset["Connector name"]

    ruleobj = rulelist.get_by_ref(ruleref)
    connobj = DxConnectorsList.get_by_ref(ruleobj.connectorId)

    if connobj:
        envobj = envlist.get_by_ref(connobj.environment_id)
        connector_name = connobj.connector_name
        environment_name = envobj.environment_name
    else:
        connector_name = 'N/A'
        environment_name = 'N/A'

    retcol = 0

    metalist = DxMetaList()
    metalist.LoadMeta(ruleobj.ruleset_id)

    rettab = 0

    for meta in ruleset["Metadata"]:
        metalist_ref = metalist.get_MetadataId_by_name(meta["meta_name"], 1)
        if metalist_ref:
            rettab = rettab + 1
        else:
            print_error("Missing meta %s" % meta["meta_name"])

    for col in ruleset["Columns"]:
        count = [
            x for x in ruleset["Columns"]
            if col["Metadata name"] == x["Metadata name"]
        ]
        rc = column_check(p_engine, rulesetname, envname, col, len(count))
        if rc != 0:
            retcol = retcol + 1


    if (ruleobj.ruleset_name == rulesetname) and \
       (connector_name == connname) and \
       (environment_name == envname) and \
       (retcol == 0) and \
       (rettab == len(ruleset["Metadata"])):
        print_message("Ruleset definition in engine is matching import file")
        return 0
    else:
        print_error("There are difference between engine and import file")
        return 1
Ejemplo n.º 14
0
    def add(self):
        """
        Add job to Masking engine and print status message
        return a None if non error
        return 1 in case of error
        """

        if (self.obj.job_name is None):
            print_error("Job name is required")
            self.__logger.error("Job name is required")
            return 1

        if (self.ruleset_id is None):
            print_error("ruleset_id is required")
            self.__logger.error("ruleset_id is required")
            return 1

        try:
            self.__logger.debug("create job input %s" % str(self.obj))
            api_instance = self.__api(self.__engine.api_client)
            self.__logger.debug("API instance created")
            response = api_instance.create_masking_job(self.obj)
            self.from_job(response)

            self.__logger.debug("job response %s" % str(response))

            print_message("Job %s added" % self.job_name)
            return 0
        except self.__apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 15
0
    def test(self):
        """
        Test connector connection to database
        Return None if OK
        """

        api_instance = self.__api(self.__engine.api_client)

        try:
            self.__logger.debug("test connector id %s" % self.connectorId)

            if (self.__engine.version_ge('6.0.0')):
                response = api_instance.test_file_connector(
                    self.connectorId,
                    body=self.obj,
                    _request_timeout=self.__engine.get_timeout())
            else:
                response = api_instance.test_file_connector(
                    self.connectorId,
                    _request_timeout=self.__engine.get_timeout())
            if response.response == "Connection Failed":
                print_error("Connector test %s failed" % self.connector_name)
                return 1
            else:
                print_message("Connector test %s succeeded" %
                              self.connector_name)
                return 0
        except self.__apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 16
0
    def test(self):
        """
        Test connector connection to database
        Return None if OK
        """

        api_instance = self.__api(self.__engine.api_client)

        try:
            self.__logger.debug("test connector id %s" %
                                self.database_connector_id)
            # body added to workaround an issue with API
            response = api_instance.test_database_connector(
                self.database_connector_id,
                body=self.obj,
                _request_timeout=self.__engine.get_timeout())

            if "Connection Failed" in response.response:
                print_error(
                    "Connector test {} failed. Error message is: {}".format(
                        self.connector_name, response.response))
                return 1
            else:
                print_message("Connector test {} succeeded".format(
                    self.connector_name))
                return 0
        except self.__apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 17
0
    def add(self):
        """
        Add File type to Masking engine and print status message
        return a None if non error
        return 1 in case of error
        """

        if (self.obj.domain_name is None):
            print_error("Domain name is required")
            self.__logger.error("Domain name is required")
            return 1

        if (self.obj.default_algorithm_code is None):
            print_error("Domain default algorithm is required")
            self.__logger.error("Domain default algorithm is required")
            return 1

        try:
            self.__logger.debug("create domain input %s" % str(self))
            api_instance = self.__api(self.__engine.api_client)
            self.__logger.debug("API instance created")
            response = api_instance.create_domain(
                self.obj,
                _request_timeout=self.__engine.get_timeout()
            )
            self.from_domain(response)
            self.__logger.debug("domain response %s"
                                % str(response))

            print_message("Domain %s added" % self.obj.domain_name)
            return 0
        except self.__apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 18
0
    def addmetafromfile(self, inputfile, bulk):
        """
        Add tables from file to ruleset
        :param inputfile: file with tables
        return a 0 if non error
        return 1 in case of error
        """
        ret = 0
        table_list = []
        for line in inputfile:
            if line.startswith('#'):
                continue
            columns = line.strip().split(',')
            params = {
                "metaname": columns[0],
                "custom_sql": columns[1],
                "where_clause": columns[2],
                "having_clause": columns[3],
                "key_column": columns[4]
            }
            if bulk:
                table_list.append(params)
            else:
                ret = ret + self.addmeta(params)

        if bulk:
            print_message(table_list)
            ret = self.addmeta_bulk(table_list)

        return ret
Ejemplo n.º 19
0
    def update(self):
        """
        Update column data to Masking engine and print status message
        return a None if non error
        return 1 in case of error
        """

        if (self.column_metadata_id is None):
            print "column_metadata_id is required"
            self.__logger.error("column_metadata_id is required")
            return 1

        try:
            if self.date_format == '':
                self.date_format = None

            self.__logger.debug("create column input %s" % str(self))
            api_instance = ColumnMetadataApi(self.__engine.api_client)
            response = api_instance.update_column_metadata(
                self.column_metadata_id, self)
            self.__logger.debug("column response %s" % str(response))

            print_message("Column %s updated" % self.column_name)
            return None
        except ApiException as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 20
0
    def add(self):
        """
        Add ruleset to Masking engine and print status message
        return a None if non error
        return 1 in case of error
        """

        if (self.obj.ruleset_name is None):
            print_error("Ruleset name is required")
            self.__logger.error("Ruleset name is required")
            return 1

        if (self.obj.file_connector_id is None):
            print_error("File connector Id is required")
            self.__logger.error("File connector ID is required")
            return 1

        try:
            self.__logger.debug("create database ruleset input %s" % str(self))

            api_instance = self.__api(self.__engine.api_client)
            response = api_instance.create_file_ruleset(self.obj)
            self.__obj = response

            self.__logger.debug("ruleset response %s" % str(response))

            print_message("Ruleset %s added" % self.ruleset_name)
        except self.__apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 21
0
    def add(self):
        """
        Add profile job to Masking engine and print status message
        return a None if non error
        return 1 in case of error
        """

        if (self.job_name is None):
            print_error("Job name is required")
            self.__logger.error("Profile job name is required")
            return 1

        if (self.ruleset_id is None):
            print_error("ruleset_id is required")
            self.__logger.error("ruleset_id is required")
            return 1

        try:
            self.__logger.debug("create profile job input %s" % str(self))
            api_instance = ProfileJobApi(self.__engine.api_client)
            response = api_instance.create_profile_job(
                self, _request_timeout=self.__engine.get_timeout())
            self.from_job(response)

            self.__logger.debug("profile job response %s" % str(response))

            print_message("Profile job %s added" % self.job_name)
            return None
        except ApiException as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 22
0
def engine_add(p_engine, p_ip, p_username, p_password, p_protocol, p_port,
               p_default, p_proxyurl, p_proxyuser, p_proxypassword):
    """
    Add engine to a configuration
    param1: p_engine: name of Masking engine
    param2: p_ip: IP of Masking engine
    param3: p_username: username
    param4: p_password: password
    param5: p_protocol: protocol (http/https)
    param6: p_port: port
    param7: p_default: is engine default - Y/N - default value N
    param8: p_proxyurl: Proxy URL
    param9: p_proxyuser: proxy username
    param10: p_proxypassword: proxy password

    return None if OK or integer with error
    """
    config = DxConfig()
    config.init_metadata()
    if config.insert_engine_info(p_engine, p_ip, p_username, p_password,
                                 p_protocol, p_port, p_default, p_proxyurl,
                                 p_proxyuser, p_proxypassword):
        print_error("Problem with adding engine to database")
        config.close()
        return -1
    else:
        print_message("Engine added to configuration")
        config.close()
        return None
Ejemplo n.º 23
0
    def add(self):
        """
        Add profile to Masking engine and print status message
        return a None if non error
        return 1 in case of error
        """

        if (self.obj.profile_set_name is None):
            print_error("Profile name is required")
            self.__logger.error("Profile name is required")
            return 1

        if (self.obj.profile_expression_ids is None):
            print_error("expression list is required")
            self.__logger.error("expression list is required")
            return 1

        try:
            self.__logger.debug("create profile input %s" % str(self))
            api_instance = self.__api(self.__engine.api_client)
            response = api_instance.create_profile_set(self.obj)
            self.from_profileset(response)
            self.__logger.debug("profile response %s" % str(response))
            print_message("Profile %s added" % self.obj.profile_set_name)
            return 0
        except self.__apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 24
0
def ruleset_export(p_engine, rulesetname, envname, outputfile, exportmeta,
                   metaname):
    """
    Delete ruleset from Masking engine
    param1: p_engine: engine name from configuration
    param2: rulesetname: ruleset name
    param3: envname: environment name
    param4: exportmeta: export metadata with ruleset
    param5: metaname: limit export to single meta object
    return 0 if added, non 0 for error
    """

    exp = []

    ret = ruleset_worker(p_engine=p_engine,
                         rulesetname=rulesetname,
                         envname=envname,
                         function_to_call="do_export",
                         exportout=exp,
                         exportmeta=exportmeta,
                         metaname=metaname)

    if ret == 0:
        try:
            json.dump(exp, outputfile, indent=4)
            outputfile.close()
            print_message("Ruleset exported to file %s" % outputfile.name)
            return 0
        except Exception as e:
            print_error("Problem with file %s Error: %s" %
                        (outputfile.name, str(e)))
            return 1

    else:
        return 1
Ejemplo n.º 25
0
    def add(self):
        """
        Add table to Masking engine and print status message
        return 0 if non error
        return 1 in case of error
        """

        if (self.obj.file_name is None):
            print_error("File name is required")
            self.__logger.error("File name is required")
            return 1

        if (self.obj.ruleset_id is None):
            print_error("ruleset_id is required")
            self.__logger.error("ruleset_id is required")
            return 1

        try:
            self.__logger.debug("create file input %s" % str(self.obj))
            api_instance = self.__api(self.__engine.api_client)
            response = api_instance.create_file_metadata(self.obj)
            self.__obj = response

            self.__logger.debug("file response %s"
                                % str(response))

            print_message("File %s added" % self.obj.file_name)
            return 0
        except self._apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 26
0
    def delete(self, force):
        """
        Delete user from Masking engine and print status message
        :param force: if True, change user to non-admin and delete
        return a None if non error
        return 1 in case of error
        """

        if self.is_admin and force:
            self.is_admin = False
            nap = self.__modelnap(environment_ids=[], role_id=1)
            self.non_admin_properties = nap
            if self.update() != 0:
                print_error("Can't switch to non-admin in force mode")
                self.__logger.debug("Can't switch to non-admin in force mode")
                return 1

        api_instance = self.__api(self.__engine.api_client)

        try:
            self.__logger.debug("delete user id %s" % self.user_id)
            response = api_instance.delete_user_by_id(
                self.user_id, _request_timeout=self.__engine.get_timeout())
            self.__logger.debug("delete user response %s" % str(response))
            print_message("User %s deleted" % self.user_name)
            return 0
        except self.__apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 27
0
    def add(self):
        """
        Add user to Masking engine and print status message
        return a None if non error
        return 1 in case of error
        """

        if self.user_name is None:
            print_error("User name is required")
            self.__logger.error("User name is required")
            return 1

        if self.first_name is None:
            print_error("User first name is required")
            self.__logger.error("User first name is required")
            return 1

        if self.last_name is None:
            print_error("User last name is required")
            self.__logger.error("User last name is required")
            return 1

        if self.email is None:
            print_error("User email is required")
            self.__logger.error("User email is required")
            return 1

        if self.is_admin is None:
            print_error("User type (admin/non-admin) is required")
            self.__logger.error("User type (admin/non-admin) is required")
            return 1

        if not self.is_admin and self.non_admin_properties is None:
            print_error("Non admin user requires a non admin properties")
            self.__logger.error(
                "Non admin user requires a non admin properties")
            return 1

        if self.password is None:
            print_error("User password is required")
            self.__logger.error("User password is required")
            return 1

        api_instance = self.__api(self.__engine.api_client)

        try:
            self.__logger.debug("create user input %s" % str(self))
            response = api_instance.create_user(
                self.obj, _request_timeout=self.__engine.get_timeout())
            self.__logger.debug("create user response %s" % str(response))

            self.user_id = response.user_id
            print_message("User %s added" % self.user_name)
            return 0
        except self.__apiexc as e:
            print_error(e.body)
            self.__logger.error(e)
            return 1
Ejemplo n.º 28
0
def engine_logout(p_engine, p_engineuser):
    """
    logout engine in configuration
    param1: p_engine: name of Masking engine
    return None if OK or integer with error
    """
    config = DxConfig()
    config.init_metadata()
    if config.check_uniqness(p_engine, p_engineuser) == -1:
        return -1
    config.set_key(p_engine, p_engineuser, '')
    print_message("Session logged out - auth key deleted")
    return 0
Ejemplo n.º 29
0
    def delete_engine_info(self, engine_name, user_name):
        """
        Delete engine data from sqllist database for database name
        and user
        :param engine_name: Engine name
        :param user_name: User name
        return None if OK or integer is error
        """
        if self.__conn:
            try:
                sql = "DELETE from dxm_engine_info " \
                      "where engine_name = ?"

                data = []

                if engine_name is None:
                    print_error("Engine name has to be specify")
                    return -1

                if (str(engine_name).lower() == 'all'):
                    print_error("Engine name can't be all. Sorry")
                    return -1

                data.append(engine_name)

                if (user_name is not None):
                    sql = sql + "and username like ?"
                    data.append(user_name)

                self.__logger.debug(sql)
                self.__logger.debug(tuple(data))
                ret = self.__cursor.execute(sql, tuple(data))
                if ret.rowcount == 0:
                    self.__logger.debug("Engine %s not found"
                                        % engine_name)
                    print_error("Engine %s not found" % engine_name)
                    return 1
                else:
                    self.__conn.commit()
                    self.__logger.debug("Engine %s deleted" % engine_name)
                    print_message("Engine %s deleted" % engine_name)
                    return None
            except lite.Error as e:
                self.__logger.debug("Error %s:" % e.args)
                return -1
        else:
            print_error("No connection to local sqllist database")
            sys.exit(-1)
Ejemplo n.º 30
0
def engine_delete(p_engine, p_username):
    """
    Delete Masking engines from configuration file
    param1: p_engine: name of Masking engine
    param2: p_username: username
    return None if OK or integer with error, ex. no rows found
    """
    config = DxConfig()
    config.init_metadata()
    if config.delete_engine_info(p_engine, p_username):
        print_error("Problem with deleting engine from database")
        config.close()
        return -1
    else:
        print_message("Engine deleted from configuration")
        config.close()
        return None