Skip to content

Commit

Permalink
Merge pull request #24 from reecetech/bugfix/FC-3427-reduce-vault-cre…
Browse files Browse the repository at this point in the history
…dential-requests

Reuse Vault credentials in calls to get_connection_params
  • Loading branch information
jwettenhall authored Dec 16, 2024
2 parents 15ebe54 + f4bd9fc commit c299c78
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions django_informixdb_vault/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,30 +160,31 @@ def get_credentials_from_vault(self):

def get_connection_params(self):
"""Returns connection parameters for Informix, with credentials from Vault"""
# django_informixdb expects USER and PASSWORD, so fake them for now
self.settings_dict['USER'] = ''
self.settings_dict['PASSWORD'] = ''
# django_informixdb expects USER and PASSWORD, so fake them if missing
if 'USER' not in self.settings_dict:
self.settings_dict['USER'] = ''
if 'PASSWORD' not in self.settings_dict:
self.settings_dict['PASSWORD'] = ''

# parse/get conn_params from django_informixdb
conn_params = super().get_connection_params()

# We don't actually use USER and PASSWORD, so delete them.
try:
del self.settings_dict['USER']
except KeyError:
# Another thread may have already deleted it
pass
try:
del self.settings_dict['PASSWORD']
except KeyError:
# Another thread may have already deleted it
pass
username = self.settings_dict['USER']
password = self.settings_dict['PASSWORD']

if (username and password):
conn_params['USER'] = username
conn_params['PASSWORD'] = password

return conn_params

username, password = self.get_credentials_from_vault()
logger.info(
f"Retrieved username ({username}) and password from Vault"
f" for database server {self.settings_dict['SERVER']}"
)
self.settings_dict['USER'] = username
self.settings_dict['PASSWORD'] = password

conn_params['USER'] = username
conn_params['PASSWORD'] = password
Expand Down

0 comments on commit c299c78

Please sign in to comment.