@@ -64,16 +64,36 @@ def get_api_key() -> str:
64
64
DD_KMS_API_KEY = os .environ .get ("DD_KMS_API_KEY" , "" )
65
65
DD_API_KEY = os .environ .get ("DD_API_KEY" , os .environ .get ("DATADOG_API_KEY" , "" ))
66
66
67
+ REGION = os .environ .get ("AWS_REGION" , "" )
68
+ is_gov_region = REGION .startswith ("us-gov-" )
69
+
67
70
if DD_API_KEY_SECRET_ARN :
68
- api_key = boto3 .client ("secretsmanager" ).get_secret_value (
71
+ # Secrets manager endpoints: https://docs.aws.amazon.com/general/latest/gr/asm.html
72
+ fips_endpoint = f"https://secretsmanager-fips.{ REGION } .amazonaws.com" if is_gov_region else None
73
+ secrets_manager_client = boto3 .client (
74
+ "secretsmanager" ,
75
+ endpoint_url = fips_endpoint
76
+ )
77
+ api_key = secrets_manager_client .get_secret_value (
69
78
SecretId = DD_API_KEY_SECRET_ARN
70
79
)["SecretString" ]
71
80
elif DD_API_KEY_SSM_NAME :
72
- api_key = boto3 .client ("ssm" ).get_parameter (
81
+ # SSM endpoints: https://docs.aws.amazon.com/general/latest/gr/ssm.html
82
+ fips_endpoint = f"https://ssm-fips.{ REGION } .amazonaws.com" if is_gov_region else None
83
+ ssm_client = boto3 .client (
84
+ "ssm" ,
85
+ endpoint_url = fips_endpoint
86
+ )
87
+ api_key = ssm_client .get_parameter (
73
88
Name = DD_API_KEY_SSM_NAME , WithDecryption = True
74
89
)["Parameter" ]["Value" ]
75
90
elif DD_KMS_API_KEY :
76
- kms_client = boto3 .client ("kms" )
91
+ # KMS endpoints: https://docs.aws.amazon.com/general/latest/gr/kms.html
92
+ fips_endpoint = f"https://kms-fips.{ REGION } .amazonaws.com" if is_gov_region else None
93
+ kms_client = boto3 .client (
94
+ "kms" ,
95
+ endpoint_url = fips_endpoint
96
+ )
77
97
api_key = decrypt_kms_api_key (kms_client , DD_KMS_API_KEY )
78
98
else :
79
99
api_key = DD_API_KEY
0 commit comments