class CloudFrontOriginAccessIdentityValidationManager(object): """ Manages CloudFront Origin Access Identities """ def __init__(self, module): self.module = module self.__cloudfront_facts_mgr = CloudFrontFactsServiceManager(module) def validate_etag_from_origin_access_identity_id( self, origin_access_identity_id): try: if origin_access_identity_id is None: return oai = self.__cloudfront_facts_mgr.get_origin_access_identity( origin_access_identity_id) if oai is not None: return oai.get('ETag') except (ClientError, BotoCoreError) as e: self.module.fail_json_aws( e, msg="Error getting etag from origin_access_identity.") def validate_origin_access_identity_id_from_caller_reference( self, caller_reference): try: origin_access_identities = self.__cloudfront_facts_mgr.list_origin_access_identities( ) origin_origin_access_identity_ids = [ oai.get('Id') for oai in origin_access_identities ] for origin_access_identity_id in origin_origin_access_identity_ids: oai_config = (self.__cloudfront_facts_mgr. get_origin_access_identity_config( origin_access_identity_id)) temp_caller_reference = oai_config.get( 'CloudFrontOriginAccessIdentityConfig').get( 'CallerReference') if temp_caller_reference == caller_reference: return origin_access_identity_id except (ClientError, BotoCoreError) as e: self.module.fail_json_aws( e, msg= "Error getting Origin Access Identity from caller_reference.") def validate_comment(self, comment): if comment is None: return "origin access identity created by Ansible with datetime " + datetime.datetime.now( ).strftime('%Y-%m-%dT%H:%M:%S.%f') return comment
class CloudFrontInvalidationValidationManager(object): """ Manages Cloudfront validations for invalidation batches """ def __init__(self, module): self.module = module self.__cloudfront_facts_mgr = CloudFrontFactsServiceManager(module) def validate_distribution_id(self, distribution_id, alias): try: if distribution_id is None and alias is None: self.module.fail_json( msg="distribution_id or alias must be specified") if distribution_id is None: distribution_id = self.__cloudfront_facts_mgr.get_distribution_id_from_domain_name( alias) return distribution_id except (ClientError, BotoCoreError) as e: self.module.fail_json_aws(e, msg="Error validating parameters.") def create_aws_list(self, invalidation_batch): aws_list = {} aws_list["Quantity"] = len(invalidation_batch) aws_list["Items"] = invalidation_batch return aws_list def validate_invalidation_batch(self, invalidation_batch, caller_reference): try: if caller_reference is not None: valid_caller_reference = caller_reference else: valid_caller_reference = datetime.datetime.now().isoformat() valid_invalidation_batch = { 'paths': self.create_aws_list(invalidation_batch), 'caller_reference': valid_caller_reference } return valid_invalidation_batch except (ClientError, BotoCoreError) as e: self.module.fail_json_aws( e, msg="Error validating invalidation batch.")
class CloudFrontInvalidationValidationManager(object): """ Manages Cloudfront validations for invalidation batches """ def __init__(self, module): self.module = module self.__cloudfront_facts_mgr = CloudFrontFactsServiceManager(module) def validate_distribution_id(self, distribution_id, alias): try: if distribution_id is None and alias is None: self.module.fail_json(msg="distribution_id or alias must be specified") if distribution_id is None: distribution_id = self.__cloudfront_facts_mgr.get_distribution_id_from_domain_name(alias) return distribution_id except (ClientError, BotoCoreError) as e: self.module.fail_json_aws(e, msg="Error validating parameters.") def create_aws_list(self, invalidation_batch): aws_list = {} aws_list["Quantity"] = len(invalidation_batch) aws_list["Items"] = invalidation_batch return aws_list def validate_invalidation_batch(self, invalidation_batch, caller_reference): try: if caller_reference is not None: valid_caller_reference = caller_reference else: valid_caller_reference = datetime.datetime.now().isoformat() valid_invalidation_batch = { 'paths': self.create_aws_list(invalidation_batch), 'caller_reference': valid_caller_reference } return valid_invalidation_batch except (ClientError, BotoCoreError) as e: self.module.fail_json_aws(e, msg="Error validating invalidation batch.")
def __init__(self, module): self.module = module self.__cloudfront_facts_mgr = CloudFrontFactsServiceManager(module)
def __init__(self, module): self.module = module self.__cloudfront_facts_mgr = CloudFrontFactsServiceManager(module)