Skip to content

Commit

Permalink
Hide passwords in logs even in case of using the 'connect using custo…
Browse files Browse the repository at this point in the history
…m params' keyword - check most common password parameter names
  • Loading branch information
amochin committed Jul 13, 2023
1 parent d4aa009 commit 66f45e4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/DatabaseLibrary/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,16 @@ def connect_to_database_using_custom_params(self, dbapiModuleName=None, db_conne

db_connect_string = f'db_api_2.connect({db_connect_string})'

logger.info('Executing : Connect To Database Using Custom Params : %s.connect(%s) ' % (dbapiModuleName, db_connect_string))
connection_string_with_hidden_pass = db_connect_string
for pass_param_name in ['pass', 'passwd', 'password', 'pwd', 'PWD']:
splitted = connection_string_with_hidden_pass.split(pass_param_name + '=')
if len(splitted) < 2:
continue
splitted = splitted[1].split(',')
value_to_hide = splitted[0]
connection_string_with_hidden_pass = connection_string_with_hidden_pass.replace(value_to_hide, "***")
logger.info('Executing : Connect To Database Using Custom Params : %s.connect(%s) ' % (dbapiModuleName, connection_string_with_hidden_pass))

self._dbconnection = eval(db_connect_string)

def connect_to_database_using_custom_connection_string(self, dbapiModuleName=None, db_connect_string=''):
Expand Down

0 comments on commit 66f45e4

Please sign in to comment.