Class: Cumulus::Route53::RecordConfig
- Inherits:
-
Object
- Object
- Cumulus::Route53::RecordConfig
- Defined in:
- lib/route53/models/RecordConfig.rb
Overview
Public: An object representing configurationf for a single record in a zone
Instance Attribute Summary collapse
-
#alias_target ⇒ Object
readonly
Returns the value of attribute alias_target.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#diff(aws) ⇒ Object
Public: Produce an array of differences between this local configuration and the configuration in AWS.
-
#initialize(json = nil, domain = nil, zone_id = nil) ⇒ RecordConfig
constructor
Public: Constructor.
-
#is_cloudfront_alias? ⇒ Boolean
Public: Determine if the record is an alias for a Cloudfront distribution.
-
#is_elb_alias? ⇒ Boolean
Public: Determine if the record is an alias for an ELB.
-
#is_record_set_alias? ⇒ Boolean
Public: Determine if the recourd is an alias for another record.
-
#is_s3_alias? ⇒ Boolean
Public: Determine if the record is an alias for an S3 website.
-
#populate(aws, domain) ⇒ Object
Public: Populate this RecordConfig from an AWS resource.
-
#readable_name ⇒ Object
Public: Produce a useful human readable version of the name of this RecordConfig.
-
#resource_records ⇒ Object
Public: Produce a ‘resource_records` array that is analogous to the one used in AWS from the values array used by Cumulus.
-
#to_hash ⇒ Object
Public: Get the config as a hash.
Constructor Details
#initialize(json = nil, domain = nil, zone_id = nil) ⇒ RecordConfig
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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |
Instance Attribute Details
#alias_target ⇒ Object (readonly)
Returns the value of attribute alias_target.
21 22 23 |
# File 'lib/route53/models/RecordConfig.rb', line 21 def alias_target @alias_target end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/route53/models/RecordConfig.rb', line 22 def name @name end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
23 24 25 |
# File 'lib/route53/models/RecordConfig.rb', line 23 def ttl @ttl end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
24 25 26 |
# File 'lib/route53/models/RecordConfig.rb', line 24 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
25 26 27 |
# File 'lib/route53/models/RecordConfig.rb', line 25 def value @value end |
Instance Method Details
#diff(aws) ⇒ Object
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
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# 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? ⇒ Boolean
Public: Determine if the record is an alias for a Cloudfront distribution
Returns whether this record is an alias for a Cloudfront distribution
156 157 158 |
# File 'lib/route53/models/RecordConfig.rb', line 156 def is_cloudfront_alias? !@alias_target.nil? and @alias_target.is_cloudfront? end |
#is_elb_alias? ⇒ Boolean
Public: Determine if the record is an alias for an ELB
Returns whether this record is an alias for an ELB
135 136 137 |
# 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? ⇒ Boolean
Public: Determine if the recourd is an alias for another record
Returns whether this record is an alias for another record
142 143 144 |
# 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? ⇒ Boolean
Public: Determine if the record is an alias for an S3 website
Returns whether this record is an alias for an S3 website
149 150 151 |
# File 'lib/route53/models/RecordConfig.rb', line 149 def is_s3_alias? !@alias_target.nil? and @alias_target.is_s3? end |
#populate(aws, domain) ⇒ Object
Public: Populate this RecordConfig from an AWS resource.
aws - the aws resource domain - the domain of the parent hosted zone
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# 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 ⇒ Object
Public: Produce a useful human readable version of the name of this RecordConfig
Returns the string name
173 174 175 |
# File 'lib/route53/models/RecordConfig.rb', line 173 def readable_name "(#{@type}) #{@name}" end |
#resource_records ⇒ Object
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`
164 165 166 167 168 |
# File 'lib/route53/models/RecordConfig.rb', line 164 def resource_records if !@value.nil? @value.map { |v| { value: v } } end end |
#to_hash ⇒ Object
Public: Get the config as a hash
Returns the hash
96 97 98 99 100 101 102 103 104 |
# 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 |