class Cumulus::Route53::RecordConfig

Public: An object representing configurationf for a single record in a zone

Attributes

alias_target[R]
name[R]
ttl[R]
type[R]
value[R]

Public Class Methods

new(json = nil, domain = nil, zone_id = nil) click to toggle source

Public: Constructor.

json - a hash containing the JSON configuration for the record domain - the domain of the zone this record belongs to zone_id - the id of the zone this record belongs to

# File lib/route53/models/RecordConfig.rb, line 32
def initialize(json = nil, domain = nil, zone_id = nil)
  if !json.nil?
    @name = if json["name"] == "" then domain else "#{json["name"].chomp(".")}.#{domain}".chomp(".") end
    @ttl = json["ttl"]
    @type = json["type"]

    if !json["value"].nil?
      @value = json["value"]

      # TXT and SPF records have each value wrapped in quotes
      if @type == "TXT" or @type == "SPF"
        @value = @value.map { |v| "\"#{v}\"" }
      end
    else
      alias_name = if json["alias"]["name"].nil?
        if json["alias"]["type"] == "s3" then @name else domain end
      else
        json["alias"]["name"].chomp(".")
      end
      @alias_target = AliasTarget.new(
        alias_name,
        json["alias"]["type"],
        zone_id
      )
    end
  end
end

Public Instance Methods

diff(aws) click to toggle source

Public: Produce an array of differences between this local configuration and the configuration in AWS

aws - the AWS resource

Returns an array of the RecordDiffs that were found

# File lib/route53/models/RecordConfig.rb, line 112
def diff(aws)
  diffs = []

  if @ttl != aws.ttl
    diffs << SingleRecordDiff.new(RecordChange::TTL, aws, self)
  end
  if !@value.nil? and @value.sort != aws.resource_records.map(&:value).sort
    diffs << SingleRecordDiff.new(RecordChange::VALUE, aws, self)
  end
  if !@alias_target.nil?
    if aws.alias_target.nil? or
      (is_elb_alias? and aws.alias_target.elb_dns_name != ELB::get_aws(@alias_target.name).dns_name) or
      (aws.alias_target.chomped_dns != @alias_target.dns_name)
      diffs << SingleRecordDiff.new(RecordChange::ALIAS, aws, self)
    end
  end

  diffs
end
is_cloudfront_alias?() click to toggle source

Public: Determine if the record is an alias for a Cloudfront distribution

Returns whether this record is an alias for a Cloudfront distribution

# File lib/route53/models/RecordConfig.rb, line 156
def is_cloudfront_alias?
  !@alias_target.nil? and @alias_target.is_cloudfront?
end
is_elb_alias?() click to toggle source

Public: Determine if the record is an alias for an ELB

Returns whether this record is an alias for an ELB

# File lib/route53/models/RecordConfig.rb, line 135
def is_elb_alias?
  !@alias_target.nil? and @alias_target.is_elb?
end
is_record_set_alias?() click to toggle source

Public: Determine if the recourd is an alias for another record

Returns whether this record is an alias for another record

# File lib/route53/models/RecordConfig.rb, line 142
def is_record_set_alias?
  !@alias_target.nil? and @alias_target.is_record_set?
end
is_s3_alias?() click to toggle source

Public: Determine if the record is an alias for an S3 website

Returns whether this record is an alias for an S3 website

# File lib/route53/models/RecordConfig.rb, line 149
def is_s3_alias?
  !@alias_target.nil? and @alias_target.is_s3?
end
populate(aws, domain) click to toggle source

Public: Populate this RecordConfig from an AWS resource.

aws - the aws resource domain - the domain of the parent hosted zone

# File lib/route53/models/RecordConfig.rb, line 64
def populate(aws, domain)
  @name = aws.name.chomp(domain).chomp(".")
  @ttl = aws.ttl
  @type = aws.type
  if !aws.resource_records.nil?
    if @type == "TXT" or @type == "SPF"
      @value = aws.resource_records.map { |r| r.value[1..-2] }
    else
      @value = aws.resource_records.map(&:value)
    end
  end

  if !aws.alias_target.nil?
    if aws.alias_target.dns_name.include? "elb"
      @alias_target = AliasTarget.new(
        Cumulus::ELB::get_aws_by_dns_name(aws.alias_target.elb_dns_name).load_balancer_name,
        "elb",
        nil
      )
    elsif aws.alias_target.dns_name.include? "s3"
      @alias_target = AliasTarget.new(nil, "s3", nil)
    elsif aws.alias_target.dns_name.include? "cloudfront"
      @alias_target = AliasTarget.new(nil, "cloudfront", nil)
    else
      @alias_target = AliasTarget.new(aws.alias_target.dns_name.chomp("."), "record", nil)
    end
  end
end
readable_name() click to toggle source

Public: Produce a useful human readable version of the name of this RecordConfig

Returns the string name

# File lib/route53/models/RecordConfig.rb, line 173
def readable_name
  "(#{@type}) #{@name}"
end
resource_records() click to toggle source

Public: Produce a `resource_records` array that is analogous to the one used in AWS from the values array used by Cumulus

Returns the `resource_records`

# File lib/route53/models/RecordConfig.rb, line 164
def resource_records
  if !@value.nil?
    @value.map { |v| { value: v } }
  end
end
to_hash() click to toggle source

Public: Get the config as a hash

Returns the hash

# File lib/route53/models/RecordConfig.rb, line 96
def to_hash
  {
    "name" => @name,
    "type" => @type,
    "ttl" => @ttl,
    "value" => @value,
    "alias" => if @alias_target.nil? then nil else @alias_target.to_hash end,
  }.reject { |k, v| v.nil? }
end