11import logging
22import os
33
4- from datadog_lambda .fips import fips_mode_enabled
4+ from datadog_lambda .config import config
55
66logger = logging .getLogger (__name__ )
77KMS_ENCRYPTION_CONTEXT_KEY = "LambdaFunctionName"
@@ -29,7 +29,6 @@ def decrypt_kms_api_key(kms_client, ciphertext):
2929 is added. We need to try decrypting the API key both with and without the encryption context.
3030 """
3131 # Try without encryption context, in case API key was encrypted using the AWS CLI
32- function_name = os .environ .get ("AWS_LAMBDA_FUNCTION_NAME" )
3332 try :
3433 plaintext = kms_client .decrypt (CiphertextBlob = decoded_bytes )[
3534 "Plaintext"
@@ -43,7 +42,7 @@ def decrypt_kms_api_key(kms_client, ciphertext):
4342 plaintext = kms_client .decrypt (
4443 CiphertextBlob = decoded_bytes ,
4544 EncryptionContext = {
46- KMS_ENCRYPTION_CONTEXT_KEY : function_name ,
45+ KMS_ENCRYPTION_CONTEXT_KEY : config . function_name ,
4746 },
4847 )["Plaintext" ].decode ("utf-8" )
4948
@@ -66,7 +65,7 @@ def get_api_key() -> str:
6665 DD_API_KEY = os .environ .get ("DD_API_KEY" , os .environ .get ("DATADOG_API_KEY" , "" ))
6766
6867 LAMBDA_REGION = os .environ .get ("AWS_REGION" , "" )
69- if fips_mode_enabled :
68+ if config . fips_mode_enabled :
7069 logger .debug (
7170 "FIPS mode is enabled, using FIPS endpoints for secrets management."
7271 )
@@ -82,7 +81,7 @@ def get_api_key() -> str:
8281 return ""
8382 endpoint_url = (
8483 f"https://secretsmanager-fips.{ secrets_region } .amazonaws.com"
85- if fips_mode_enabled
84+ if config . fips_mode_enabled
8685 else None
8786 )
8887 secrets_manager_client = _boto3_client (
@@ -95,7 +94,7 @@ def get_api_key() -> str:
9594 # SSM endpoints: https://docs.aws.amazon.com/general/latest/gr/ssm.html
9695 fips_endpoint = (
9796 f"https://ssm-fips.{ LAMBDA_REGION } .amazonaws.com"
98- if fips_mode_enabled
97+ if config . fips_mode_enabled
9998 else None
10099 )
101100 ssm_client = _boto3_client ("ssm" , endpoint_url = fips_endpoint )
@@ -106,7 +105,7 @@ def get_api_key() -> str:
106105 # KMS endpoints: https://docs.aws.amazon.com/general/latest/gr/kms.html
107106 fips_endpoint = (
108107 f"https://kms-fips.{ LAMBDA_REGION } .amazonaws.com"
109- if fips_mode_enabled
108+ if config . fips_mode_enabled
110109 else None
111110 )
112111 kms_client = _boto3_client ("kms" , endpoint_url = fips_endpoint )
@@ -118,7 +117,7 @@ def get_api_key() -> str:
118117
119118
120119def init_api ():
121- if not os . environ . get ( "DD_FLUSH_TO_LOG" , "" ). lower () == "true" :
120+ if not config . flush_to_log :
122121 # Make sure that this package would always be lazy-loaded/outside from the critical path
123122 # since underlying packages are quite heavy to load
124123 # and useless with the extension unless sending metrics with timestamps
0 commit comments