SuperDuperDB/superduperdb

[MISC] Show the DataLayer configuration

Closed this issue · 0 comments

Right after the "building data layer", plz print a log for the DataLayer configuration.
For better readability, make it as a table (See how I printed the routes for cdc)

 2024-Mar-29 13:15:27.56| INFO     | jupyter-fnikolai| superduperdb.base.datalayer:89   | Building Data Layer
 2024-Mar-29 13:15:27.58| INFO     | jupyter-fnikolai| superduperdb.components.component:374  | Initializing DataType : dill
 2024-Mar-29 13:15:27.58| INFO     | jupyter-fnikolai| superduperdb.components.component:377  | Initialized  DataType : dill successfully
 2024-Mar-29 13:15:27.72| INFO     | jupyter-fnikolai| superduperdb.components.component:374  | Initializing DataType : dill
 2024-Mar-29 13:15:27.72| INFO     | jupyter-fnikolai| superduperdb.components.component:377  | Initialized  DataType : dill successfully

To hide the credentials in connection strings, but retain debuggability, we need to keep only the first and the last letter of each section of the connection uri.

Like: mongodb://u********e:p********d@hostip/documents

Here is a snippet to anonymize the mongo strings.

import re

def anonymize_url(url):
    # Define a regular expression pattern to match the username and password
    pattern = r'mongodb://(\w+):(\w+)@'
    
    # Use re.findall to find all matches of the pattern in the URL
    matches = re.findall(pattern, url)
    
    # Iterate over matches and anonymize each username and password
    for match in matches:
        username = match[0]
        password = match[1]
        
        # Anonymize username and password
        anonymized_username = username[0] + '*' * (len(username) - 2) + username[-1]
        anonymized_password = password[0] + '*' * (len(password) - 2) + password[-1]
        
        # Replace the original username and password with the anonymized ones in the URL
        anonymized_url = re.sub(rf'mongodb://{username}:{password}@', f'mongodb://{anonymized_username}:{anonymized_password}@', url)
        
        print(anonymized_url)

# Example usage
url = "mongodb://username1:password1@hostip/documents mongodb://username2:password2@hostip/documents"
anonymize_url(url)