Skip to content

Commit

Permalink
Merge pull request #41 from neong83/fix/default_api_key_on_lambda_metric
Browse files Browse the repository at this point in the history
check api_key had been set before setting the value from env
  • Loading branch information
tianchu authored Jan 16, 2020
2 parents d7e0795 + 3585f1a commit 61fcc84
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions datadog_lambda/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,20 @@ def submit_errors_metric(lambda_context):


# Set API Key and Host in the module, so they only set once per container
DD_API_KEY_SECRET_ARN = os.environ.get("DD_API_KEY_SECRET_ARN", "")
DD_KMS_API_KEY = os.environ.get("DD_KMS_API_KEY", "")
DD_API_KEY = os.environ.get("DD_API_KEY", os.environ.get("DATADOG_API_KEY", ""))
if DD_API_KEY_SECRET_ARN:
api._api_key = boto3.client("secretsmanager").get_secret_value(
SecretId=DD_API_KEY_SECRET_ARN
)["SecretString"]
elif DD_KMS_API_KEY:
api._api_key = boto3.client("kms").decrypt(
CiphertextBlob=base64.b64decode(DD_KMS_API_KEY)
)["Plaintext"]
else:
api._api_key = DD_API_KEY
if not api._api_key:
DD_API_KEY_SECRET_ARN = os.environ.get("DD_API_KEY_SECRET_ARN", "")
DD_KMS_API_KEY = os.environ.get("DD_KMS_API_KEY", "")
DD_API_KEY = os.environ.get("DD_API_KEY", os.environ.get("DATADOG_API_KEY", ""))
if DD_API_KEY_SECRET_ARN:
api._api_key = boto3.client("secretsmanager").get_secret_value(
SecretId=DD_API_KEY_SECRET_ARN
)["SecretString"]
elif DD_KMS_API_KEY:
api._api_key = boto3.client("kms").decrypt(
CiphertextBlob=base64.b64decode(DD_KMS_API_KEY)
)["Plaintext"]
else:
api._api_key = DD_API_KEY
logger.debug("Setting DATADOG_API_KEY of length %d", len(api._api_key))

# Set DATADOG_HOST, to send data to a non-default Datadog datacenter
Expand Down

0 comments on commit 61fcc84

Please sign in to comment.