Exemple #1
0
    def __jdbc_connector(connection_profile):
        base_keys_validation_output = RdbmsDAO._validate_connection_profile(
            connection_profile,
            ['user', 'password', 'host', 'port', 'database', 'driver'])

        if base_keys_validation_output[0]:
            driver_keys_validation_output = RdbmsDAO._validate_connection_profile(
                connection_profile['driver'], ['name', 'path'])
            if not driver_keys_validation_output[0]:
                raise KeyError(
                    f'One or more of {driver_keys_validation_output[1]} keys not configured in profile'
                )
        else:
            raise KeyError(
                f'One or more of {base_keys_validation_output[1]} keys not configured in profile'
            )

        # If all required properties are available, get a new connection to the Netezza database
        return JdbcConnector.connection({
            "jclassname":
            connection_profile['driver']['name'],
            "jars":
            connection_profile['driver']['path'],
            "url":
            f"jdbc:netezza://{connection_profile['host']}:{connection_profile['port']}/{connection_profile['database']}",
            "user":
            connection_profile['user'],
            "password":
            connection_profile['password']
        })
Exemple #2
0
    def __odbc_connector(connection_profile):
        base_keys_validation_output = RdbmsDAO._validate_connection_profile(
            connection_profile,
            ['user', 'password', 'host', 'port', 'database', 'driver'])

        if base_keys_validation_output[0]:
            driver_keys_validation_output = RdbmsDAO._validate_connection_profile(
                connection_profile['driver'], ['name'])
            if not driver_keys_validation_output[0]:
                raise KeyError(
                    f'One or more of {driver_keys_validation_output[1]} keys not configured in profile'
                )
        else:
            raise KeyError(
                f'One or more of {base_keys_validation_output[1]} keys not configured in profile'
            )

        return OdbcConnector.connection({
            "driver":
            connection_profile['driver']['name'],
            "connection_string":
            f"DRIVER={connection_profile['driver']['name']};SERVER={connection_profile['host']};"
            f"PORT={connection_profile['port']};DATABASE={connection_profile['database']};"
            f"UID={connection_profile['user']};PWD={connection_profile['password']};"
        })
Exemple #3
0
    def __jdbc_connector(connection_profile):
        base_keys_validation_output = RdbmsDAO._validate_connection_profile(
            connection_profile, ['user', 'password', 'host', 'port', 'driver'])

        if base_keys_validation_output[0]:
            is_sid = RdbmsDAO._validate_connection_profile(
                connection_profile, ['sid'])
            is_service_name = RdbmsDAO._validate_connection_profile(
                connection_profile, ['service_name'])

            if is_sid[0]:
                url = f"jdbc:oracle:thin:@{connection_profile['host']}:{connection_profile['port']}:{connection_profile['sid']}"
            elif is_service_name[0]:
                url = f"jdbc:oracle:thin:@//{connection_profile['host']}:{connection_profile['port']}/{connection_profile['service_name']}"
            else:
                raise KeyError(
                    f'One or more of {["sid", "service_name"]} keys not configured in profile'
                )

            driver_keys_validation_output = RdbmsDAO._validate_connection_profile(
                connection_profile['driver'], ['name', 'path'])
            if not driver_keys_validation_output[0]:
                raise KeyError(
                    f'One or more of {driver_keys_validation_output[1]} keys not configured in profile'
                )
        else:
            raise KeyError(
                f'One or more of {base_keys_validation_output[1]} keys not configured in profile'
            )

        # If all required properties are available, get a new connection to the Netezza database
        return JdbcConnector.connection({
            "jclassname":
            connection_profile['driver']['name'],
            "jars":
            connection_profile['driver']['path'],
            "url":
            url,
            "user":
            connection_profile['user'],
            "password":
            connection_profile['password']
        })
Exemple #4
0
    def __snowflake_connector(connection_profile):

        auth_type1_present = RdbmsDAO._validate_connection_profile(
            connection_profile,
            ['account', 'role', 'warehouse', 'user', 'password'])

        if not auth_type1_present[0]:
            auth_type2_present = RdbmsDAO._validate_connection_profile(
                connection_profile,
                ['account', 'role', 'warehouse', 'user', 'authenticator'])

            if not auth_type2_present[0]:
                raise KeyError(
                    f'One or more of {auth_type1_present[1] + auth_type2_present[1]} keys '
                    f'not configured in profile')
            else:
                kwrgs = {
                    'account': connection_profile['account'],
                    'role': connection_profile['role'],
                    'warehouse': connection_profile['warehouse'],
                    'user': connection_profile['user'],
                    'authenticator': connection_profile['authenticator'],
                    'login_timeout': 30
                }
        else:
            kwrgs = {
                'account': connection_profile['account'],
                'role': connection_profile['role'],
                'warehouse': connection_profile['warehouse'],
                'user': connection_profile['user'],
                'password': connection_profile['password'],
                'login_timeout': 30
            }

        if 'database' in connection_profile:
            kwrgs['database'] = connection_profile['database']

            if 'schema' in connection_profile:
                kwrgs['schema'] = connection_profile['schema']

        return snowflake.connector.connect(**kwrgs)
Exemple #5
0
    def __cx_oracle_connector(connection_profile):
        base_keys_validation_output = RdbmsDAO._validate_connection_profile(
            connection_profile,
            ['user', 'password', 'host', 'port', 'sid', 'client_library_dir'])

        if not base_keys_validation_output[0]:
            raise KeyError(
                f'One or more of {base_keys_validation_output[1]} keys not configured in profile'
            )

        cx_Oracle.init_oracle_client(
            lib_dir=connection_profile['client_library_dir'])

        dsn = cx_Oracle.makedsn(connection_profile['host'],
                                connection_profile['port'],
                                connection_profile['sid'])

        return cx_Oracle.connect(connection_profile['user'],
                                 connection_profile['password'],
                                 dsn=dsn)