Skip to content

Commit

Permalink
module_utils.cloudfront_facts Move to module.client and add minimal R…
Browse files Browse the repository at this point in the history
…etry wrapper (#138)
  • Loading branch information
tremble authored Aug 26, 2020
1 parent 27f991d commit d3eaef3
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions plugins/module_utils/cloudfront_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,61 +36,56 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from .ec2 import boto3_conn
from .ec2 import AWSRetry
from .ec2 import boto3_tag_list_to_ansible_dict
from .ec2 import get_aws_connection_info


class CloudFrontFactsServiceManager(object):
"""Handles CloudFront Facts Services"""

def __init__(self, module):
self.module = module

region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
self.client = boto3_conn(module, conn_type='client',
resource='cloudfront', region=region,
endpoint=ec2_url, **aws_connect_kwargs)
self.client = module.client('cloudfront', retry_decorator=AWSRetry.jittered_backoff())

def get_distribution(self, distribution_id):
try:
return self.client.get_distribution(Id=distribution_id)
return self.client.get_distribution(Id=distribution_id, aws_retry=True)
except botocore.exceptions.ClientError as e:
self.module.fail_json_aws(e, msg="Error describing distribution")

def get_distribution_config(self, distribution_id):
try:
return self.client.get_distribution_config(Id=distribution_id)
return self.client.get_distribution_config(Id=distribution_id, aws_retry=True)
except botocore.exceptions.ClientError as e:
self.module.fail_json_aws(e, msg="Error describing distribution configuration")

def get_origin_access_identity(self, origin_access_identity_id):
try:
return self.client.get_cloud_front_origin_access_identity(Id=origin_access_identity_id)
return self.client.get_cloud_front_origin_access_identity(Id=origin_access_identity_id, aws_retry=True)
except botocore.exceptions.ClientError as e:
self.module.fail_json_aws(e, msg="Error describing origin access identity")

def get_origin_access_identity_config(self, origin_access_identity_id):
try:
return self.client.get_cloud_front_origin_access_identity_config(Id=origin_access_identity_id)
return self.client.get_cloud_front_origin_access_identity_config(Id=origin_access_identity_id, aws_retry=True)
except botocore.exceptions.ClientError as e:
self.module.fail_json_aws(e, msg="Error describing origin access identity configuration")

def get_invalidation(self, distribution_id, invalidation_id):
try:
return self.client.get_invalidation(DistributionId=distribution_id, Id=invalidation_id)
return self.client.get_invalidation(DistributionId=distribution_id, Id=invalidation_id, aws_retry=True)
except botocore.exceptions.ClientError as e:
self.module.fail_json_aws(e, msg="Error describing invalidation")

def get_streaming_distribution(self, distribution_id):
try:
return self.client.get_streaming_distribution(Id=distribution_id)
return self.client.get_streaming_distribution(Id=distribution_id, aws_retry=True)
except botocore.exceptions.ClientError as e:
self.module.fail_json_aws(e, msg="Error describing streaming distribution")

def get_streaming_distribution_config(self, distribution_id):
try:
return self.client.get_streaming_distribution_config(Id=distribution_id)
return self.client.get_streaming_distribution_config(Id=distribution_id, aws_retry=True)
except botocore.exceptions.ClientError as e:
self.module.fail_json_aws(e, msg="Error describing streaming distribution")

Expand All @@ -115,7 +110,7 @@ def list_distributions(self, keyed=True):

def list_distributions_by_web_acl_id(self, web_acl_id):
try:
result = self.client.list_distributions_by_web_acl_id(WebAclId=web_acl_id)
result = self.client.list_distributions_by_web_acl_id(WebAclId=web_acl_id, aws_retry=True)
distribution_list = result.get('DistributionList', {}).get('Items', [])
return self.keyed_list_helper(distribution_list)
except botocore.exceptions.ClientError as e:
Expand Down Expand Up @@ -177,7 +172,7 @@ def summary_get_distribution_list(self, streaming=False):
invalidation_ids = self.get_list_of_invalidation_ids_from_distribution_id(dist['Id'])
if invalidation_ids:
temp_distribution['Invalidations'] = invalidation_ids
resource_tags = self.client.list_tags_for_resource(Resource=dist['ARN'])
resource_tags = self.client.list_tags_for_resource(Resource=dist['ARN'], aws_retry=True)
temp_distribution['Tags'] = boto3_tag_list_to_ansible_dict(resource_tags['Tags'].get('Items', []))
distribution_list[list_name].append(temp_distribution)
return distribution_list
Expand Down

0 comments on commit d3eaef3

Please sign in to comment.