Class: Cumulus::Route53::ZoneConfig
- Inherits:
-
Object
- Object
- Cumulus::Route53::ZoneConfig
- Defined in:
- lib/route53/models/ZoneConfig.rb
Overview
Public: An object representing configuration for a zone
Defined Under Namespace
Classes: RecordKey
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#private ⇒ Object
readonly
Returns the value of attribute private.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
-
#vpc ⇒ Object
readonly
Returns the value of attribute vpc.
Instance Method Summary collapse
-
#diff(aws) ⇒ Object
Public: Produce an array of differences between this local configuration and the configuration in AWS.
-
#initialize(name, json = nil) ⇒ ZoneConfig
constructor
Public: Constructor.
-
#populate(aws) ⇒ Object
Public: Populate this ZoneConfig from an AWS resource.
-
#pretty_json ⇒ Object
Public: Get the config as a prettified JSON string.
Constructor Details
#initialize(name, json = nil) ⇒ ZoneConfig
Public: Constructor
json - a hash containing the JSON configuration for the zone
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/route53/models/ZoneConfig.rb', line 25 def initialize(name, json = nil) @name = name if !json.nil? @id = "/hostedzone/#{json["zone-id"]}" @domain = json["domain"].chomp(".") @private = json["private"] @vpc = if @private then json["vpc"].map { |v| Vpc.new(v["id"], v["region"]) } else [] end @comment = json["comment"] includes = if json["records"]["includes"].nil? then [] else json["records"]["includes"] end includes = includes.flat_map(&Loader.method(:includes_file)) @records = (json["records"]["inlines"] + includes).map do |j| RecordConfig.new(j, @domain, json["zone-id"]) end @ignored = if json["records"]["ignored"].nil? then [] else json["records"]["ignored"] end end end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
14 15 16 |
# File 'lib/route53/models/ZoneConfig.rb', line 14 def comment @comment end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
15 16 17 |
# File 'lib/route53/models/ZoneConfig.rb', line 15 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
16 17 18 |
# File 'lib/route53/models/ZoneConfig.rb', line 16 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/route53/models/ZoneConfig.rb', line 17 def name @name end |
#private ⇒ Object (readonly)
Returns the value of attribute private.
18 19 20 |
# File 'lib/route53/models/ZoneConfig.rb', line 18 def private @private end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
19 20 21 |
# File 'lib/route53/models/ZoneConfig.rb', line 19 def records @records end |
#vpc ⇒ Object (readonly)
Returns the value of attribute vpc.
20 21 22 |
# File 'lib/route53/models/ZoneConfig.rb', line 20 def vpc @vpc 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 ZoneDiffs that were found
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/route53/models/ZoneConfig.rb', line 83 def diff(aws) diffs = [] if @comment != aws.config.comment diffs << ZoneDiff.new(ZoneChange::COMMENT, aws, self) end if @domain != aws.name diffs << ZoneDiff.new(ZoneChange::DOMAIN, aws, self) end if @private != aws.config.private_zone diffs << ZoneDiff.new(ZoneChange::PRIVATE, aws, self) end if @private and @vpc.sort != aws.vpc.sort diffs << ZoneDiff.new(ZoneChange::VPC, aws, self) end record_diffs = diff_records(aws.records) if !record_diffs.empty? diffs << ZoneDiff.records(record_diffs, self) end diffs end |
#populate(aws) ⇒ Object
Public: Populate this ZoneConfig from an AWS resource
aws - the aws resource
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/route53/models/ZoneConfig.rb', line 46 def populate(aws) @id = aws.id.sub(/\/hostedzone\//, '') @domain = aws.name @private = aws.config.private_zone @vpc = if @private then aws.vpc else nil end @comment = aws.config.comment @records = aws.records.map do |record| r = RecordConfig.new() r.populate(record, @domain) r end end |
#pretty_json ⇒ Object
Public: Get the config as a prettified JSON string.
Returns the JSON string
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/route53/models/ZoneConfig.rb', line 62 def pretty_json JSON.pretty_generate({ "zone-id" => @id, "domain" => @domain, "private" => @private, "vpc" => if @vpc.nil? then nil else @vpc.map(&:to_hash) end, "comment" => @comment, "records" => { "ignored" => if @ignored.nil? then [] else @ignored end, "includes" => [], "inlines" => @records.map(&:to_hash), }, }.reject { |k, v| v.nil? }) end |