77class TestDatadogLambdaAPI (unittest .TestCase ):
88 def setUp (self ):
99 api .api_key = None
10- self .env_patcher = patch .dict (os .environ , {
11- "DD_API_KEY_SECRET_ARN" : "" ,
12- "DD_API_KEY_SSM_NAME" : "" ,
13- "DD_KMS_API_KEY" : "" ,
14- "DD_API_KEY" : "" ,
15- "DATADOG_API_KEY" : "" ,
16- "AWS_REGION" : "" ,
17- }, clear = True )
10+ self .env_patcher = patch .dict (
11+ os .environ ,
12+ {
13+ "DD_API_KEY_SECRET_ARN" : "" ,
14+ "DD_API_KEY_SSM_NAME" : "" ,
15+ "DD_KMS_API_KEY" : "" ,
16+ "DD_API_KEY" : "" ,
17+ "DATADOG_API_KEY" : "" ,
18+ "AWS_REGION" : "" ,
19+ },
20+ clear = True ,
21+ )
1822 self .env_patcher .start ()
1923
20- @patch (' boto3.client' )
24+ @patch (" boto3.client" )
2125 def test_secrets_manager_fips_endpoint (self , mock_boto3_client ):
2226 mock_client = MagicMock ()
2327 mock_client .get_secret_value .return_value = {"SecretString" : "test-api-key" }
@@ -30,14 +34,16 @@ def test_secrets_manager_fips_endpoint(self, mock_boto3_client):
3034
3135 mock_boto3_client .assert_called_with (
3236 "secretsmanager" ,
33- endpoint_url = "https://secretsmanager-fips.us-gov-east-1.amazonaws.com"
37+ endpoint_url = "https://secretsmanager-fips.us-gov-east-1.amazonaws.com" ,
3438 )
3539 self .assertEqual (api_key , "test-api-key" )
3640
37- @patch (' boto3.client' )
41+ @patch (" boto3.client" )
3842 def test_ssm_fips_endpoint (self , mock_boto3_client ):
3943 mock_client = MagicMock ()
40- mock_client .get_parameter .return_value = {"Parameter" : {"Value" : "test-api-key" }}
44+ mock_client .get_parameter .return_value = {
45+ "Parameter" : {"Value" : "test-api-key" }
46+ }
4147 mock_boto3_client .return_value = mock_client
4248
4349 os .environ ["AWS_REGION" ] = "us-gov-west-1"
@@ -46,13 +52,12 @@ def test_ssm_fips_endpoint(self, mock_boto3_client):
4652 api_key = api .get_api_key ()
4753
4854 mock_boto3_client .assert_called_with (
49- "ssm" ,
50- endpoint_url = "https://ssm-fips.us-gov-west-1.amazonaws.com"
55+ "ssm" , endpoint_url = "https://ssm-fips.us-gov-west-1.amazonaws.com"
5156 )
5257 self .assertEqual (api_key , "test-api-key" )
5358
54- @patch (' boto3.client' )
55- @patch (' datadog_lambda.api.decrypt_kms_api_key' )
59+ @patch (" boto3.client" )
60+ @patch (" datadog_lambda.api.decrypt_kms_api_key" )
5661 def test_kms_fips_endpoint (self , mock_decrypt_kms , mock_boto3_client ):
5762 mock_client = MagicMock ()
5863 mock_boto3_client .return_value = mock_client
@@ -64,21 +69,12 @@ def test_kms_fips_endpoint(self, mock_decrypt_kms, mock_boto3_client):
6469 api_key = api .get_api_key ()
6570
6671 mock_boto3_client .assert_called_with (
67- "kms" ,
68- endpoint_url = "https://kms-fips.us-gov-west-1.amazonaws.com"
72+ "kms" , endpoint_url = "https://kms-fips.us-gov-west-1.amazonaws.com"
6973 )
7074 self .assertEqual (api_key , "test-api-key" )
7175
72- @patch (' boto3.client' )
76+ @patch (" boto3.client" )
7377 def test_no_fips_for_standard_regions (self , mock_boto3_client ):
7478 mock_client = MagicMock ()
7579 mock_client .get_secret_value .return_value = {"SecretString" : "test-api-key" }
7680 mock_boto3_client .return_value = mock_client
77-
78- os .environ .clear ()
79- os .environ ["AWS_REGION" ] = "us-west-2"
80- os .environ ["DD_API_KEY_SECRET_ARN" ] = "test-arn"
81-
82- api .get_api_key ()
83-
84- mock_boto3_client .assert_called_with ("secretsmanager" , endpoint_url = None )
0 commit comments