Sha256: 8fd27e3307be4ba5a8b20b3771a8b1b55fccc690a251208939109b02f1f5aa69

Contents?: true

Size: 1.79 KB

Versions: 151

Compression:

Stored size: 1.79 KB

Contents

module Awspec::Generator
  module Spec
    class Route53HostedZone
      include Awspec::Helper::Finder
      def generate_by_domain_name(id)
        hosted_zone = find_hosted_zone(id)
        raise 'Not Found Route53 Hosted Zone' unless hosted_zone
        id = hosted_zone[:id]
        res = @route53_client.list_resource_record_sets({
                                                          hosted_zone_id: id
                                                        })
        resource_record_sets = res.resource_record_sets.map do |record_set|
          generate_linespec(record_set)
        end

        content = ERB.new(route53_hosted_zone_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
      end

      def generate_linespec(record_set)
        name = record_set.name.gsub(/\\052/, '*') # wildcard support
        if !record_set.resource_records.empty?
          template = <<-'EOF'
it { should have_record_set('<%= name %>').<%= type %>('<%= v %>').ttl(<%= record_set.ttl %>) }
EOF
          v = record_set.resource_records.map { |r| r.value }.join("\n")
          type = record_set.type.downcase
        else
          # ALIAS
          dns_name = record_set.alias_target.dns_name
          hosted_zone_id = record_set.alias_target.hosted_zone_id
          template = <<-'EOF'
it { should have_record_set('<%= name %>').alias('<%= dns_name %>', '<%= hosted_zone_id %>') }
EOF
        end
        ERB.new(template, nil, '-').result(binding)
      end

      def route53_hosted_zone_spec_template
        template = <<-'EOF'
describe route53_hosted_zone('<%= hosted_zone.name %>') do
  it { should exist }
  its(:resource_record_set_count) { should eq <%= hosted_zone.resource_record_set_count %> }
<% resource_record_sets.each do |line| %>
  <%= line %>
<% end %>
end
EOF
        template
      end
    end
  end
end

Version data entries

151 entries across 151 versions & 2 rubygems

Version Path
awspec-1.18.0 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.17.4 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.17.3 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.17.2 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.17.1 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.17.0 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.16.1 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.16.0 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.15.3 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.15.2 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.15.1 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.15.0 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.14.1 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.14.0 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.13.0 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.12.7 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.12.6 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.12.5 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.12.4 lib/awspec/generator/spec/route53_hosted_zone.rb
awspec-1.12.3 lib/awspec/generator/spec/route53_hosted_zone.rb