Beispiel #1
0
def create_connection(connection_info_json, prompt_prefix, typeOfInfo):
    user_name = connection_info_json.get('userName', None) or prompt(prompt_prefix + 'Username: '******'password', None) or prompt_pass(msg=prompt_prefix + 'Password: '******'serverName', None)
    if "mysql" in typeOfInfo:
        port = connection_info_json.get('port', 3306)
        return MySqlConnectionInfo(user_name=user_name,
                                   password=password,
                                   server_name=server_name,
                                   port=port)
    elif "postgres" in typeOfInfo:
        database_name = connection_info_json.get('databaseName', "postgres")
        port = connection_info_json.get('port', 5432)
        return PostgreSqlConnectionInfo(user_name=user_name,
                                        password=password,
                                        server_name=server_name,
                                        database_name=database_name,
                                        port=port)
    elif "mongo" in typeOfInfo:
        connection_string = connection_info_json['connectionString']
        # Strip out the username and password from the connection string (if they exist) to store them securely.
        rex_conn_string = re.compile(r'^(mongodb://|mongodb\+srv://|http://|https://)(.*:.*@)?(.*)')
        connection_string_match = rex_conn_string.search(connection_string)
        connection_string = connection_string_match.group(1) + connection_string_match.group(3)
        if connection_string_match.group(2) is not None and not user_name and not password:
            rex_un_pw = re.compile('^(.*):(.*)@')
            un_pw_match = rex_un_pw.search(connection_string_match.group(2))
            user_name = un_pw_match.group(1)
            password = un_pw_match.group(2)
        return MongoDbConnectionInfo(connection_string=connection_string,
                                     user_name=user_name,
                                     password=password)
    else:
        # If no match, Pass the connection info through
        return connection_info_json
Beispiel #2
0
def create_connection(connection_info_json, prompt_prefix, typeOfInfo):
    typeOfInfo = typeOfInfo.lower()

    user_name = connection_info_json.get(
        'userName', None) or prompt(prompt_prefix + 'Username: '******'password', None) or prompt_pass(msg=prompt_prefix + 'Password: '******'serverName', None)
    if "mysql" in typeOfInfo:
        port = connection_info_json.get('port', 3306)
        return MySqlConnectionInfo(user_name=user_name,
                                   password=password,
                                   server_name=server_name,
                                   port=port)
    elif "postgre" in typeOfInfo:
        database_name = connection_info_json.get('databaseName', "postgres")
        port = connection_info_json.get('port', 5432)
        return PostgreSqlConnectionInfo(user_name=user_name,
                                        password=password,
                                        server_name=server_name,
                                        database_name=database_name,
                                        port=port)
    data_source = connection_info_json.get('dataSource', None)
    authentication = connection_info_json.get('authentication', None)
    encrypt_connection = connection_info_json.get('encryptConnection', None)
    trust_server_certificate = connection_info_json.get(
        'trustServerCertificate', None)
    additional_settings = connection_info_json.get('additionalSettings', None)
    return SqlConnectionInfo(user_name=user_name,
                             password=password,
                             data_source=data_source,
                             authentication=authentication,
                             encrypt_connection=encrypt_connection,
                             trust_server_certificate=trust_server_certificate,
                             additional_settings=additional_settings)
Beispiel #3
0
def create_connection(connection_info_json, prompt_prefix, typeOfInfo):
    user_name = connection_info_json.get(
        'userName', None) or prompt(prompt_prefix + 'Username: '******'password', None) or prompt_pass(msg=prompt_prefix + 'Password: '******'serverName', None)
    if "mysql" in typeOfInfo:
        port = connection_info_json.get('port', 3306)
        return MySqlConnectionInfo(user_name=user_name,
                                   password=password,
                                   server_name=server_name,
                                   port=port)

    database_name = connection_info_json.get('databaseName', "postgres")
    port = connection_info_json.get('port', 5432)
    return PostgreSqlConnectionInfo(user_name=user_name,
                                    password=password,
                                    server_name=server_name,
                                    database_name=database_name,
                                    port=port)