Skip to content

Commit

Permalink
Renam to get_deployed_distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-griffin committed Dec 12, 2024
1 parent 1b3cda5 commit f528e90
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions application-load-balancer/lambda_function/secret_rotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_cloudfront_client(self) -> boto3.client:
aws_secret_access_key=credentials["SecretAccessKey"],
aws_session_token=credentials["SessionToken"])

def get_distro_list(self) -> List[Dict[str, Any]]:
def get_deployed_distributions(self) -> List[Dict[str, Any]]:
client = self.get_cloudfront_client()
paginator = client.get_paginator("list_distributions")
matching_distributions = []
Expand Down Expand Up @@ -471,7 +471,7 @@ def set_secret(self, service_client, arn, token):
token (string): The ClientRequestToken associated with the secret version
"""
# Confirm CloudFront distributions are in Deployed state
matching_distributions = self.get_distro_list()
matching_distributions = self.get_deployed_distributions()

if not matching_distributions:
self.logger.error("No matching distributions found. Cannot update Cloudfront distributions or WAF ACLs")
Expand Down Expand Up @@ -560,7 +560,7 @@ def run_test_secret(self, service_client, arn, token, test_domains=[]):

secrets = [pendingsecret['HEADERVALUE'], currentsecret['HEADERVALUE']]

distro_list = self.get_distro_list()
distro_list = self.get_deployed_distributions()
for distro in distro_list:
self.logger.info(f"Testing distro: {distro['Id']}")
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_identifies_distributions_that_need_secret_updates(self, rotator):
mock_paginator.paginate.return_value = [mock_distributions]
mock_session.return_value = mock_client

result = rotator.get_distro_list()
result = rotator.get_deployed_distributions()

assert result == expected_result, f"Expected: {expected_result}, but got: {result}"

Expand Down Expand Up @@ -497,7 +497,7 @@ def test_set_secret_updates_all_components_in_correct_order(self, rotator):
mock_current_secret
]

with patch.object(rotator, 'get_distro_list') as mock_get_distro_list, \
with patch.object(rotator, 'get_deployed_distributions') as mock_get_deployed_distributions, \
patch.object(rotator, 'get_cf_distro') as mock_get_cf_distro, \
patch.object(rotator, 'update_waf_acl') as mock_update_waf_acl, \
patch.object(rotator, 'update_cf_distro') as mock_update_cf_distro, \
Expand All @@ -506,7 +506,7 @@ def test_set_secret_updates_all_components_in_correct_order(self, rotator):

mock_client = MagicMock()
mock_session.return_value = mock_client
mock_get_distro_list.return_value = mock_distributions
mock_get_deployed_distributions.return_value = mock_distributions
mock_get_cf_distro.return_value = mock_get_distro

rotator.set_secret(mock_service_client, "test-arn", "test-token")
Expand Down Expand Up @@ -554,10 +554,10 @@ def test_secret_validates_all_origins_with_both_secrets(self, rotator):
]
mock_service_client.describe_secret.return_value = mock_metadata

with patch.object(rotator, 'get_distro_list') as mock_get_distro_list, \
with patch.object(rotator, 'get_deployed_distributions') as mock_get_deployed_distributions, \
patch.object(rotator, 'run_test_origin_access') as mock_run_test_origin_access:

mock_get_distro_list.return_value = mock_distributions
mock_get_deployed_distributions.return_value = mock_distributions
mock_run_test_origin_access.return_value = True

rotator.run_test_secret(mock_service_client, "test-arn", "test_token")
Expand Down Expand Up @@ -665,11 +665,11 @@ def test_fails_early_if_distribution_not_deployed(self, rotator):
]

mock_service_client = MagicMock()
with patch.object(rotator, 'get_distro_list') as mock_get_distro_list, \
with patch.object(rotator, 'get_deployed_distributions') as mock_get_deployed_distributions, \
patch.object(rotator, 'get_cf_distro') as mock_get_cf_distro, \
patch.object(rotator, 'update_waf_acl') as mock_update_waf_acl:

mock_get_distro_list.return_value = mock_distributions
mock_get_deployed_distributions.return_value = mock_distributions
mock_get_cf_distro.side_effect = [
{"Distribution": {"Status": "Deployed"}},
{"Distribution": {"Status": "InProgress"}}
Expand Down Expand Up @@ -701,12 +701,12 @@ def test_handles_waf_update_failure_without_distribution_updates(self, rotator):
mock_current_secret, # For AWSCURRENT
]

with patch.object(rotator, 'get_distro_list') as mock_get_distro_list, \
with patch.object(rotator, 'get_deployed_distributions') as mock_get_deployed_distributions, \
patch.object(rotator, 'get_cf_distro') as mock_get_cf_distro, \
patch.object(rotator, 'update_cf_distro') as mock_update_cf_distro, \
patch.object(rotator, 'process_cf_distributions_and_WAF_rules') as mock_process:

mock_get_distro_list.return_value = mock_distributions
mock_get_deployed_distributions.return_value = mock_distributions
mock_get_cf_distro.return_value = mock_get_distro

mock_process.side_effect = ClientError(
Expand Down Expand Up @@ -865,7 +865,7 @@ def test_run_test_secret_with_test_domains(self, rotator):
with patch('boto3.client') as mock_boto3_client, \
patch('rotate_secret_lambda.boto3.client') as mock_lambda_boto, \
patch('secret_rotator.boto3.client') as mock_secret_rotator_boto, \
patch.object(rotator, 'get_distro_list') as mock_get_distro_list, \
patch.object(rotator, 'get_deployed_distributions') as mock_get_deployed_distributions, \
patch('rotate_secret_lambda.SecretRotator') as MockSecretRotator:

# Create a specific mock client to use
Expand All @@ -875,8 +875,8 @@ def test_run_test_secret_with_test_domains(self, rotator):
mock_service_client = mock_boto3_client.return_value
mock_rotator_instance = MockSecretRotator.return_value

# mocks get_distro_list and calls made in get_secrets() method
mock_get_distro_list.return_value = mock_distributions
# mocks get_deployed_distributions and calls made in get_secrets() method
mock_get_deployed_distributions.return_value = mock_distributions
mock_service_client.describe_secret.return_value = mock_metadata
mock_service_client.get_secret_value.side_effect = [
mock_pending_secret,
Expand Down

0 comments on commit f528e90

Please sign in to comment.