roadworker 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -102,6 +102,10 @@ info.winebarrel.jp. A:
102
102
 
103
103
  (Please note test of A(Alias) is not possible to perfection...)
104
104
 
105
+ ## Demo
106
+
107
+ ![Roadworker Demo](https://bitbucket.org/winebarrel/roadworker/downloads/roadworker-demo.gif)
108
+
105
109
  ## DNS management using GitHub/Bitbucket
106
110
 
107
111
  ![DNS management using Git](https://cacoo.com/diagrams/geJfslZqd8qne90t-BC7C7.png)
@@ -26,32 +26,37 @@ options = {
26
26
  }
27
27
 
28
28
  ARGV.options do |opt|
29
- access_key = nil
30
- secret_key = nil
31
-
32
- opt.on('-k', '--access-key ACCESS_KEY') {|v| access_key = v }
33
- opt.on('-s', '--secret-key SECRET_KEY') {|v| secret_key = v }
34
- opt.on('-a', '--apply') {|v| mode = :apply }
35
- opt.on('-f', '--file FILE') {|v| file = v }
36
- opt.on('', '--dry-run') {|v| options[:dry_run] = true }
37
- opt.on('' , '--force') { options[:force] = true }
38
- opt.on('', '--no-health-check-gc') {|v| options[:no_health_check_gc] = true }
39
- opt.on('-e', '--export') {|v| mode = :export }
40
- opt.on('-o', '--output FILE') {|v| output_file = v }
41
- opt.on('', '--split') {|v| split = true }
42
- opt.on('', '--with-soa-ns') {|v| options[:with_soa_ns] = true }
43
- opt.on('-t', '--test') {|v| mode = :test }
44
- opt.on('' , '--no-color') { options[:color] = false }
45
- opt.on('' , '--debug') { options[:debug] = true }
46
- opt.parse!
47
-
48
- if access_key and secret_key
49
- AWS.config({
50
- :access_key_id => access_key,
51
- :secret_access_key => secret_key,
52
- })
53
- elsif (access_key and !secret_key) or (!access_key and secret_key) or mode.nil?
54
- puts opt.help
29
+ begin
30
+ access_key = nil
31
+ secret_key = nil
32
+
33
+ opt.on('-k', '--access-key ACCESS_KEY') {|v| access_key = v }
34
+ opt.on('-s', '--secret-key SECRET_KEY') {|v| secret_key = v }
35
+ opt.on('-a', '--apply') {|v| mode = :apply }
36
+ opt.on('-f', '--file FILE') {|v| file = v }
37
+ opt.on('', '--dry-run') {|v| options[:dry_run] = true }
38
+ opt.on('' , '--force') { options[:force] = true }
39
+ opt.on('', '--no-health-check-gc') {|v| options[:no_health_check_gc] = true }
40
+ opt.on('-e', '--export') {|v| mode = :export }
41
+ opt.on('-o', '--output FILE') {|v| output_file = v }
42
+ opt.on('', '--split') {|v| split = true }
43
+ opt.on('', '--with-soa-ns') {|v| options[:with_soa_ns] = true }
44
+ opt.on('-t', '--test') {|v| mode = :test }
45
+ opt.on('' , '--no-color') { options[:color] = false }
46
+ opt.on('' , '--debug') { options[:debug] = true }
47
+ opt.parse!
48
+
49
+ if access_key and secret_key
50
+ AWS.config({
51
+ :access_key_id => access_key,
52
+ :secret_access_key => secret_key,
53
+ })
54
+ elsif (access_key and !secret_key) or (!access_key and secret_key) or mode.nil?
55
+ puts opt.help
56
+ exit 1
57
+ end
58
+ rescue => e
59
+ $stderr.puts e
55
60
  exit 1
56
61
  end
57
62
  end
@@ -35,10 +35,11 @@ module Roadworker
35
35
  error_messages = []
36
36
  warning_messages = []
37
37
 
38
- records.each do |key, rrs|
38
+ validate_record = lambda do |key, rrs, asterisk_answers|
39
39
  errors = []
40
40
 
41
- name = asterisk_to_anyname(key[0])
41
+ original_name = key[0]
42
+ name = asterisk_to_anyname(original_name)
42
43
  type = key[1]
43
44
 
44
45
  log(:debug, 'Check DNS', :white, "#{name} #{type}")
@@ -93,6 +94,18 @@ module Roadworker
93
94
  end
94
95
 
95
96
  errors << [logmsg_expected, logmsg_actual] unless is_same
97
+
98
+ if asterisk_answers
99
+ asterisk_answers.each do |ast_key, answers|
100
+ ast_name = ast_key[0]
101
+ ast_regex = Regexp.new('\A' + ast_name.sub(/\.\Z/, '').gsub('.', '\.').gsub('*', '.+') + '\Z')
102
+
103
+ if ast_regex =~ name.sub(/\.\Z/, '') and actual_value.any? {|i| answers.include?(i) }
104
+ warning_messages << "#{name} #{type}: same as `#{ast_name}`"
105
+ end
106
+ end
107
+ end
108
+
96
109
  is_same
97
110
  }
98
111
 
@@ -106,8 +119,33 @@ module Roadworker
106
119
  error_messages << "#{name} #{type}:\n #{logmsg_expected}\n #{logmsg_actual}"
107
120
  end
108
121
  end
122
+ end
123
+
124
+ asterisk_records = {}
125
+ asterisk_answers = {}
126
+
127
+ records.keys.each do |key|
128
+ asterisk_records[key] = records.delete(key) if key[0]['*']
129
+ end
130
+
131
+ asterisk_records.map do |key, rrs|
132
+ original_name = key[0]
133
+ name = asterisk_to_anyname(original_name)
134
+ type = key[1]
135
+
136
+ response = query(name, type)
137
+
138
+ if response
139
+ asterisk_answers[key] = response.answer.map {|i| (type == 'TXT' ? i.txt : i.value).strip }
140
+ end
141
+ end
109
142
 
110
- result &&= is_valid
143
+ asterisk_records.each do |key, rrs|
144
+ validate_record.call(key, rrs, nil)
145
+ end
146
+
147
+ records.each do |key, rrs|
148
+ validate_record.call(key, rrs, asterisk_answers)
111
149
  end
112
150
 
113
151
  puts unless @options.debug
@@ -156,14 +194,14 @@ module Roadworker
156
194
  name.gsub('*', "#{ASTERISK_PREFIX}-#{rand_str}")
157
195
  end
158
196
 
159
- def query(name, type, warning_messages)
197
+ def query(name, type, warning_messages = nil)
160
198
  ctype = Net::DNS.const_get(type)
161
199
  response = nil
162
200
 
163
201
  begin
164
202
  response = @resolver.query(name, ctype)
165
203
  rescue => e
166
- warning_messages << "#{name} #{type}: #{e.message}"
204
+ warning_messages << "#{name} #{type}: #{e.message}" if warning_messages
167
205
  end
168
206
 
169
207
  return response
@@ -1,5 +1,5 @@
1
1
  module Roadworker
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
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.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-04 00:00:00.000000000 Z
12
+ date: 2013-08-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk