def LoadConnectors(self, environment_name): """ Load all connectors :param1 environment_name: Limit load to particular environment name """ self.__logger.debug("load connector !!!") if self.__loaded_engine is None: self.__loaded_engine = self.__engine.get_name() if self.__loaded_engine == self.__engine.get_name() and self.__connectorsList != {} \ and self.__loaded_env == environment_name: return None else: # delete a list as we can have multi engines self.__connectorsList.clear() self.__loaded_engine = self.__engine.get_name() if (self.__engine.version_ge('6.0.0')): from masking_api_60.api.database_connector_api import DatabaseConnectorApi from masking_api_60.api.file_connector_api import FileConnectorApi from masking_api_60.rest import ApiException else: from masking_api_53.api.database_connector_api import DatabaseConnectorApi from masking_api_53.api.file_connector_api import FileConnectorApi from masking_api_53.rest import ApiException self.__api = DatabaseConnectorApi self.__fileapi = FileConnectorApi self.__loaded_env = environment_name 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: dbconnectors = paginator( api_instance, "get_all_database_connectors", environment_id=environment_id, _request_timeout=self.__engine.get_timeout()) else: return 1 else: environment_id = None dbconnectors = paginator( api_instance, "get_all_database_connectors", _request_timeout=self.__engine.get_timeout()) if dbconnectors.response_list: for c in dbconnectors.response_list: if (c.database_type == 'ORACLE'): connector = OracleConnector(self.__engine) elif (c.database_type == 'MSSQL'): connector = MSSQLConnector(self.__engine) elif (c.database_type == 'SYBASE'): connector = SybaseConnector(self.__engine) else: connector = DxConnector(self.__engine) connector.from_connector(c) connector.is_database = True self.__connectorsList['d' + str(c.database_connector_id)] \ = connector else: self.__logger.debug("No database connectors found") api_instance = self.__fileapi(self.__engine.api_client) if environment_id: file_connectors = paginator( api_instance, "get_all_file_connectors", environment_id=environment_id, _request_timeout=self.__engine.get_timeout()) else: file_connectors = paginator( api_instance, "get_all_file_connectors", _request_timeout=self.__engine.get_timeout()) if file_connectors.response_list: for f in file_connectors.response_list: connector = DxFileConnector(self.__engine) connector.from_connector(f) connector.is_database = False self.__connectorsList['f' + str(f.file_connector_id)] \ = connector else: self.__logger.debug("No file connectors found") if len(self.__connectorsList) < 1: print_error("No connectors found") self.__logger.error("No connectors found") return 1 return None except self.__apiexc as e: print_error(e.body) self.__logger.error(e.body) return 1
def LoadConnectors(self, environment_name): """ Load all connectors :param1 environment_name: Limit load to particular environment name """ # delete a list as we can have multi engines self.__connectorsList.clear() try: api_instance = DatabaseConnectorApi(self.__engine.api_client) if environment_name: environment_id = DxEnvironmentList.get_environmentId_by_name( environment_name) if environment_id: dbconnectors = paginator( api_instance, "get_all_database_connectors", environment_id=environment_id, _request_timeout=self.__engine.get_timeout()) else: return 1 else: environment_id = None dbconnectors = paginator( api_instance, "get_all_database_connectors", _request_timeout=self.__engine.get_timeout()) if dbconnectors.response_list: for c in dbconnectors.response_list: if (c.database_type == 'ORACLE'): connector = OracleConnector(self.__engine) elif (c.database_type == 'MSSQL'): connector = MSSQLConnector(self.__engine) elif (c.database_type == 'SYBASE'): connector = SybaseConnector(self.__engine) else: connector = DxConnector(self.__engine) connector.from_connector(c) connector.is_database = True self.__connectorsList['d' + str(c.database_connector_id)] \ = connector else: self.__logger.debug("No database connectors found") api_instance = FileConnectorApi(self.__engine.api_client) if environment_id: file_connectors = paginator( api_instance, "get_all_file_connectors", environment_id=environment_id, _request_timeout=self.__engine.get_timeout()) else: file_connectors = paginator( api_instance, "get_all_file_connectors", _request_timeout=self.__engine.get_timeout()) if file_connectors.response_list: for f in file_connectors.response_list: connector = DxFileConnector(self.__engine) connector.from_connector(f) connector.is_database = False self.__connectorsList['f' + str(f.file_connector_id)] \ = connector else: self.__logger.debug("No file connectors found") if len(self.__connectorsList) < 1: print_error("No connectors found") self.__logger.error("No connectors found") return 1 return None except ApiException as e: print_error(e.body) self.__logger.error(e.body) return 1
def connector_add(p_engine, params): """ Add application to Masking engine param1: p_engine: engine name from configuration param2: params: dict of parameters needed for connector to add return 0 if added, non 0 for error """ ret = 0 logger = logging.getLogger() enginelist = get_list_of_engines(p_engine) if enginelist is None: return 1 envname = params['envname'] schemaName = params['schemaName'] host = params['host'] port = params['port'] password = params['password'] username = params['username'] connname = params['connname'] for engine_tuple in enginelist: engine_obj = DxMaskingEngine(engine_tuple) if engine_obj.get_session(): continue envlist = DxEnvironmentList() envlist.LoadEnvironments() logger.debug("Envname is %s" % envname) envref = envlist.get_environmentId_by_name(envname) if envref is None: ret = ret + 1 continue connlist = DxConnectorsList() if params['type'] in database_types: if params['type'] == 'oracle': connobj = OracleConnector(engine_obj) elif params['type'] == 'mssql': connobj = MSSQLConnector(engine_obj) elif params['type'] == 'sybase': connobj = SybaseConnector(engine_obj) else: connobj = DxConnector(engine_obj) connobj.database_type = params['type'].upper() connobj.connector_name = connname connobj.schema_name = schemaName connobj.username = username connobj.password = password connobj.host = host if port: connobj.port = port + 0 connobj.sid = params['sid'] connobj.jdbc = params['jdbc'] connobj.environment_id = envref connobj.instance_name = params['instancename'] connobj.database_name = params['databasename'] elif params['type'] in file_types: path = params['path'] connmode = params['servertype'] connobj = DxFileConnector(engine_obj) connobj.is_database = False connobj.connector_name = connname connobj.environment_id = envref connobj.file_type = params['type'].upper() ci = ConnectionInfo() ci.host = host ci.port = port ci.login_name = username ci.password = password ci.path = path ci.connection_mode = connmode.upper() connobj.connection_info = ci else: print_error('Wrong connector type %s' % params['type']) logger.error('Wrong connector type %s' % params['type']) return 1 if connlist.add(connobj): ret = ret + 1 return ret
def connector_add(p_engine, p_username, params): """ Add application to Masking engine param1: p_engine: engine name from configuration param2: params: dict of parameters needed for connector to add 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 envname = params['envname'] schemaName = params['schemaName'] host = params['host'] port = params['port'] password = params['password'] username = params['username'] connname = params['connname'] for engine_tuple in enginelist: engine_obj = DxMaskingEngine(engine_tuple) if engine_obj.get_session(): continue envlist = DxEnvironmentList() envlist.LoadEnvironments() logger.debug("Envname is %s" % envname) envref = envlist.get_environmentId_by_name(envname) if envref is None: ret = ret + 1 continue connlist = DxConnectorsList() if params['type'] in database_types: if params['type'] == 'oracle': connobj = OracleConnector(engine_obj) dbtype = 'ORACLE' elif params['type'] == 'mssql': connobj = MSSQLConnector(engine_obj) dbtype = 'MSSQL' elif params['type'] == 'sybase': connobj = SybaseConnector(engine_obj) dbtype = 'SYBASE' elif params['type'] == 'extended': connobj = ExtendedConnector(engine_obj) dbtype = 'EXTENDED' else: connobj = DxConnector(engine_obj) dbtype = params['type'].upper() connobj.create_connector( connector_name = connname, database_type = dbtype, environment_id = envref ) connobj.schema_name = schemaName connobj.username = username connobj.password = password connobj.host = host if port: connobj.port = int(port) connobj.sid = params['sid'] connobj.jdbc = params['jdbc'] connobj.instance_name = params['instancename'] connobj.database_name = params['databasename'] if params['jdbc_driver_name']: jdbclist = DxJDBCList() driver_id = jdbclist.get_driver_id_by_name(params['jdbc_driver_name']) connobj.jdbc_driver_id = driver_id elif params['type'] in file_types: path = params['path'] connmode = params['servertype'] connobj = DxFileConnector(engine_obj) connobj.is_database = False connobj.create_connector( connector_name = connname, file_type = params['type'].upper(), environment_id = envref, host=host, port=port, login_name=username, password=password, path=path, connection_mode=connmode.upper() ) else: print_error('Wrong connector type %s' % params['type']) logger.error('Wrong connector type %s' % params['type']) return 1 if connlist.add(connobj): ret = ret + 1 return ret