Skip to content

Commit bf1fe97

Browse files
committed
Prioritize auth configuration values over environment variables
Setting `DD_API_KEY` and `DD_APP_KEY` in the environment should not override values manually passed to the configuration init. Closes #1786
1 parent ede190a commit bf1fe97

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

.generator/src/generator/templates/configuration.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ class Configuration:
248248
# Load default values from environment
249249
if "DD_SITE" in os.environ:
250250
self.server_variables["site"] = os.environ["DD_SITE"]
251-
if "DD_API_KEY" in os.environ:
251+
if "DD_API_KEY" in os.environ and not self.api_key.get("apiKeyAuth"):
252252
self.api_key["apiKeyAuth"] = os.environ["DD_API_KEY"]
253-
if "DD_APP_KEY" in os.environ:
253+
if "DD_APP_KEY" in os.environ and not self.api_key["appKeyAuth"]:
254254
self.api_key["appKeyAuth"] = os.environ["DD_APP_KEY"]
255255

256256
def __deepcopy__(self, memo):

src/datadog_api_client/configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ def __init__(
287287
# Load default values from environment
288288
if "DD_SITE" in os.environ:
289289
self.server_variables["site"] = os.environ["DD_SITE"]
290-
if "DD_API_KEY" in os.environ:
290+
if "DD_API_KEY" in os.environ and not self.api_key.get("apiKeyAuth"):
291291
self.api_key["apiKeyAuth"] = os.environ["DD_API_KEY"]
292-
if "DD_APP_KEY" in os.environ:
292+
if "DD_APP_KEY" in os.environ and not self.api_key["appKeyAuth"]:
293293
self.api_key["appKeyAuth"] = os.environ["DD_APP_KEY"]
294294

295295
def __deepcopy__(self, memo):

0 commit comments

Comments
 (0)