roadworker 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,11 +1,14 @@
1
1
  # Roadworker
2
2
 
3
- **notice: still unstable**
4
-
5
3
  Roadworker is a tool to manage Route53.
6
4
 
7
5
  It defines the state of Route53 using DSL, and updates Route53 according to DSL.
8
6
 
7
+ **Notice**
8
+
9
+ * HealthCheck is not supported.
10
+ * Cannot update TTL of two or more same records (with different SetIdentifier) after creation.
11
+
9
12
  ## Installation
10
13
 
11
14
  Add this line to your application's Gemfile:
@@ -61,10 +61,6 @@ module Roadworker
61
61
  end
62
62
 
63
63
  actual.each do |keys, zone|
64
- zone.rrsets.each do |record|
65
- record.delete(:cascaded => true)
66
- end
67
-
68
64
  zone.delete
69
65
  end
70
66
  end
@@ -98,7 +94,11 @@ module Roadworker
98
94
  hash = {}
99
95
 
100
96
  collection.each do |item|
101
- key_list = keys.map {|k| item.send(k) }
97
+ key_list = keys.map do |k|
98
+ value = item.send(k)
99
+ (k == :name && value) ? value.downcase.gsub(/\.\Z/, '') : value
100
+ end
101
+
102
102
  hash[key_list] = item
103
103
  end
104
104
 
@@ -3,7 +3,7 @@ module Roadworker
3
3
 
4
4
  def log(level, message, color, log_id = nil)
5
5
  log_id = yield if block_given?
6
- message = "#{message}: #{log_id}"
6
+ message = "#{message}: #{log_id}" if log_id
7
7
  message << ' (dry-run)' if @options.dry_run
8
8
  @options.logger.send(level, message.send(color))
9
9
  end
@@ -38,6 +38,7 @@ module Roadworker
38
38
  ]
39
39
 
40
40
  record_h = item_to_hash(record, *attrs)
41
+ record_h[:name].gsub!("\\052", '*') if record_h[:name]
41
42
  rrsets << record_h
42
43
 
43
44
  rrs = record_h.delete(:resource_records)
@@ -74,6 +74,10 @@ module Roadworker
74
74
  if @options.force
75
75
  log(:info, 'Delete HostedZone', :red, @hosted_zone.name)
76
76
 
77
+ self.rrsets.each do |record|
78
+ record.delete
79
+ end
80
+
77
81
  unless @options.dry_run
78
82
  @hosted_zone.delete
79
83
  @options.updated = true
@@ -156,9 +160,9 @@ module Roadworker
156
160
  true
157
161
  elsif expected and actual
158
162
  case attr
159
- when :resource_records
160
- expected = expected.sort_by {|i| i[:value] }
161
- actual = actual.sort_by {|i| i[:value] }
163
+ when :dns_name
164
+ expected = expected.downcase.gsub(/\.\Z/, '')
165
+ actual = actual.downcase.gsub(/\.\Z/, '')
162
166
  end
163
167
 
164
168
  (expected == actual)
@@ -169,12 +173,14 @@ module Roadworker
169
173
  end
170
174
 
171
175
  def update(expected_record)
172
- log(:info, 'Update ResourceRecordSet', :green) do
173
- log_id = [@resource_record_set.name, @resource_record_set.type].join(' ')
174
- rrset_setid = @resource_record_set.set_identifier
176
+ log_id_proc = proc do
177
+ log_id = [self.name, self.type].join(' ')
178
+ rrset_setid = self.set_identifier
175
179
  rrset_setid ? (log_id + " (#{rrset_setid})") : log_id
176
180
  end
177
181
 
182
+ log(:info, 'Update ResourceRecordSet', :green, &log_id_proc)
183
+
178
184
  Route53Wrapper::RRSET_ATTRS.each do |attr|
179
185
  expected = expected_record.send(attr)
180
186
  expected = nil if expected.kind_of?(Array) && expected.empty?
@@ -182,27 +188,11 @@ module Roadworker
182
188
  actual = nil if actual.kind_of?(Array) && actual.empty?
183
189
 
184
190
  if (expected and !actual) or (!expected and actual)
185
- log(:info, " set #{attr}=#{expected.inspect}" , :green) do
186
- log_id = [@resource_record_set.name, @resource_record_set.type].join(' ')
187
- rrset_setid = @resource_record_set.set_identifier
188
- rrset_setid ? (log_id + " (#{rrset_setid})") : log_id
189
- end
190
-
191
+ log(:info, " set #{attr}=#{expected.inspect}" , :green, &log_id_proc)
191
192
  self.send(:"#{attr}=", expected) unless @options.dry_run
192
193
  elsif expected and actual
193
- case attr
194
- when :resource_records
195
- expected = expected.sort_by {|i| i[:value] }
196
- actual = actual.sort_by {|i| i[:value] }
197
- end
198
-
199
194
  if expected != actual
200
- log(:info, " set #{attr}=#{expected.inspect}" , :green) do
201
- log_id = [@resource_record_set.name, @resource_record_set.type].join(' ')
202
- rrset_setid = @resource_record_set.set_identifier
203
- rrset_setid ? (log_id + " (#{rrset_setid})") : log_id
204
- end
205
-
195
+ log(:info, " set #{attr}=#{expected.inspect}" , :green, &log_id_proc)
206
196
  self.send(:"#{attr}=", expected) unless @options.dry_run
207
197
  end
208
198
  end
@@ -214,14 +204,13 @@ module Roadworker
214
204
  end
215
205
  end
216
206
 
217
- def delete(opts = {})
207
+ def delete
218
208
  return if type =~ /\A(SOA|NS)\Z/i
219
- if not opts[:cascaded] or @options.force
220
- log(:info, 'Delete ResourceRecordSet', :red) do
221
- log_id = [@resource_record_set.name, @resource_record_set.type].join(' ')
222
- rrset_setid = @resource_record_set.set_identifier
223
- rrset_setid ? (log_id + " (#{rrset_setid})") : log_id
224
- end
209
+
210
+ log(:info, 'Delete ResourceRecordSet', :red) do
211
+ log_id = [self.name, self.type].join(' ')
212
+ rrset_setid = self.set_identifier
213
+ rrset_setid ? (log_id + " (#{rrset_setid})") : log_id
225
214
  end
226
215
 
227
216
  unless @options.dry_run
@@ -230,6 +219,11 @@ module Roadworker
230
219
  end
231
220
  end
232
221
 
222
+ def name
223
+ value = @resource_record_set.name
224
+ value ? value.gsub("\\052", '*') : value
225
+ end
226
+
233
227
  def dns_name=(name)
234
228
  if name
235
229
  @resource_record_set.alias_target = @options.route53.dns_name_to_alias_target(name)
@@ -1,5 +1,5 @@
1
1
  module Roadworker
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
4
4
 
5
5
  Version = Roadworker::VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roadworker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: