class Chef::Resource::AwsRoute53RecordSet
Public Class Methods
new(name, *args)
click to toggle source
Calls superclass method
# File lib/chef/resource/aws_route53_record_set.rb, line 57 def initialize(name, *args) rr_name(name) unless @rr_name super(name, *args) end
verify_unique!(record_sets)
click to toggle source
# File lib/chef/resource/aws_route53_record_set.rb, line 134 def self.verify_unique!(record_sets) seen = {} record_sets.each do |rs| key = rs.aws_key if seen.key?(key) raise Chef::Exceptions::ValidationFailed, "Duplicate RecordSet found in resource: [#{key}]" else seen[key] = 1 end end # TODO: be helpful and print out all duplicates, not just the first. true end
Public Instance Methods
aws_key()
click to toggle source
# File lib/chef/resource/aws_route53_record_set.rb, line 104 def aws_key fqdn.to_s end
fqdn()
click to toggle source
# File lib/chef/resource/aws_route53_record_set.rb, line 108 def fqdn if rr_name !~ /#{aws_route53_zone_name}\.?$/ "#{rr_name}.#{aws_route53_zone_name}" else rr_name end end
to_aws_change_struct(aws_action)
click to toggle source
# File lib/chef/resource/aws_route53_record_set.rb, line 125 def to_aws_change_struct(aws_action) # there are more elements which are optional, notably 'weight' and 'region': see the API doc at # http://redirx.me/?t3zo { action: aws_action, resource_record_set: to_aws_struct } end
to_aws_struct()
click to toggle source
# File lib/chef/resource/aws_route53_record_set.rb, line 116 def to_aws_struct { name: fqdn, type: type, ttl: ttl, resource_records: resource_records.map { |rr| { value: rr } } } end
validate!()
click to toggle source
because these resources can't actually converge themselves, we have to trigger the validations.
# File lib/chef/resource/aws_route53_record_set.rb, line 97 def validate! %i{rr_name type ttl resource_records aws_route53_zone_name}.each { |f| send(f) } # this was in an :is validator, but didn't play well with inheriting default values. validate_rr_type!(type, resource_records) end
validate_rr_type!(type, rr_list)
click to toggle source
# File lib/chef/resource/aws_route53_record_set.rb, line 62 def validate_rr_type!(type, rr_list) case type # we'll check for integers, but leave the user responsible for valid DNS names. when "A" rr_list.all? { |v| v =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ } || raise(::Chef::Exceptions::ValidationFailed, "A records are of the form '141.2.25.3'") when "MX" rr_list.all? { |v| v =~ /^\d+\s+[^ ]+/ } || raise(::Chef::Exceptions::ValidationFailed, "MX records must have a priority and mail server, of the form '15 mail.example.com.'") when "SRV" rr_list.all? { |v| v =~ /^\d+\s+\d+\s+\d+\s+[^ ]+$/ } || raise(::Chef::Exceptions::ValidationFailed, "SRV records must have a priority, weight, port, and hostname, of the form '15 10 25 service.example.com.'") when "CNAME" rr_list.size == 1 || raise(::Chef::Exceptions::ValidationFailed, "CNAME records may only have a single value (a hostname).") when "SOA", "NS", "TXT", "PTR", "AAAA", "SPF" true else raise ArgumentError, "Argument '#{type}' must be one of %w(SOA NS A MX SRV CNAME TXT PTR AAAA SPF)" end end
validate_zone_name!(rr_name, zone_name)
click to toggle source
# File lib/chef/resource/aws_route53_record_set.rb, line 89 def validate_zone_name!(rr_name, zone_name) if rr_name.end_with?(".") && rr_name !~ /#{zone_name}\.$/ raise(::Chef::Exceptions::ValidationFailed, "RecordSet name #{rr_name} does not match parent HostedZone name #{zone_name}.") end true end