Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 8a9edf4

Browse files
authored
Support referencing env vars in the postgresql configuration
Adds support for referencing `$DATABASE_HOSTNAME` and similar env vars as the value of the configuration; the `$` will be the trigger in this case and checks the environment if the key exists before using it, otherwise falling back on the value given. This then allows for hosts/users/pw and so on that would start with `$`
1 parent 884aad3 commit 8a9edf4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

newrelic_python_agent/plugins/postgresql.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,16 @@ def connection_arguments(self):
277277
filtered_args = ["name", "superuser", "relation_stats"]
278278
args = {}
279279
for key in set(self.config) - set(filtered_args):
280+
value = self.config[key]
281+
# If value starts with $ and exists as an env var, use that value
282+
if value[0] == "$":
283+
# strip the $, check if the env var exists, otherwise fallback
284+
value = os.getenv(value, value)
285+
280286
if key == 'dbname':
281-
args['database'] = self.config[key]
287+
args['database'] = value
282288
else:
283-
args[key] = self.config[key]
289+
args[key] = value
284290
return args
285291

286292
def poll(self):

0 commit comments

Comments
 (0)