zonify 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/zonify +13 -4
  3. data/lib/zonify.rb +30 -10
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e30191a3ca007c303fe49c7e5ae55d9dbb1f29f
4
- data.tar.gz: e7f5d12cc76788684ab3940786ed741290a06a50
3
+ metadata.gz: 186d36c96eef1d14b65e3f3a576592cdf3db4bdc
4
+ data.tar.gz: 1505c7e0e7f101d959d3e73c962b8da3e7dc60b7
5
5
  SHA512:
6
- metadata.gz: b5ed894a4cd3b0d60318e25ea352e9b283a65fc74582bdc3a388df5e346d8ebe2779ad2b68d92d6482b2113c189ad968a947f0c51ec3eb341983987597ca4252
7
- data.tar.gz: 9f7d532d7d0cad92a4a485162d0767a43dda163e08449b5e59a1f2b880df32fed0fe82c775e4042b27e574cfbc9d7b25d5359f51a97f4958795522a92caf7a15
6
+ metadata.gz: 1bfcabe561a6ce7f7f0ae7d63c183c110d1af970da427b84d2e944ea80fb5a65efe1dc5472f008ef66c36d23d762c07a6422a6016a0ff4b23a08e3d00bac7d54
7
+ data.tar.gz: 3250c3104624cc774acfaa8d7f718dc45d835b02fd17cf166c76e3c031e004ded25fd531dcf5963e99a53d50cce11305e7d0de0052098dc51a8d511ab1ca69c1
data/bin/zonify CHANGED
@@ -16,11 +16,12 @@ class CLIAWS
16
16
  attr_reader :options
17
17
  def initialize(access=nil, secret=nil)
18
18
  @options = {}
19
- @options.merge!(options) if options
20
19
  env_adapter
21
- { :region => ENV['AWS_DEFAULT_REGION'],
22
- :aws_access_key_id => (access or ENV['AWS_ACCESS_KEY']),
23
- :aws_secret_access_key => (secret or ENV['AWS_SECRET_KEY'])
20
+ auth = { :aws_access_key_id => (access or ENV['AWS_ACCESS_KEY']),
21
+ :aws_secret_access_key => (secret or ENV['AWS_SECRET_KEY']) }
22
+ auth = { :use_iam_profile => true } unless auth.values.all?
23
+ @options.merge!(auth)
24
+ { :region => ENV['AWS_DEFAULT_REGION'],
24
25
  }.each{|k,v| @options.merge!(k=>v) if v }
25
26
  end
26
27
  def respond_to?(sym)
@@ -153,8 +154,16 @@ def main
153
154
  norm = (ARGV.delete("--srv-singleton") or not
154
155
  ARGV.delete("--no-srv-singleton"))
155
156
  use_iam_profile = ARGV.delete("--use-iam-profile")
157
+ zone = nil
158
+ while i = ARGV.index('--zone')
159
+ raise 'Zone already set...' if zone
160
+ ARGV.delete_at(i)
161
+ zone = ARGV[i]
162
+ ARGV.delete_at(i)
163
+ end
156
164
  aws = CLIAWS.new
157
165
  aws.options[:use_iam_profile] = true if use_iam_profile
166
+ aws.options[:zone] = zone if zone
158
167
  types = nil
159
168
  while i = ARGV.index('--types')
160
169
  ARGV.delete_at(i)
@@ -19,12 +19,14 @@ class AWS
19
19
  def create(options)
20
20
  options_ec2 = options.merge( :provider=>'AWS',
21
21
  :connection_options=>{:nonblock=>false} )
22
+ options_ec2.delete(:zone)
22
23
  ec2 = Proc.new{|| Fog::Compute.new(options_ec2) }
23
24
  options_elb = options_ec2.dup.delete_if{|k, _| k == :provider }
24
25
  elb = Proc.new{|| Fog::AWS::ELB.new(options_elb) }
25
26
  options_r53 = options_ec2.dup.delete_if{|k, _| k == :region }
26
27
  r53 = Proc.new{|| Fog::DNS.new(options_r53) }
27
- Zonify::AWS.new(:ec2_proc=>ec2, :elb_proc=>elb, :r53_proc=>r53)
28
+ options.merge!(:ec2_proc=>ec2, :elb_proc=>elb, :r53_proc=>r53)
29
+ Zonify::AWS.new(options)
28
30
  end
29
31
  end
30
32
  attr_reader :ec2_proc, :elb_proc, :r53_proc
@@ -35,6 +37,7 @@ class AWS
35
37
  @ec2_proc = opts[:ec2_proc]
36
38
  @elb_proc = opts[:elb_proc]
37
39
  @r53_proc = opts[:r53_proc]
40
+ @zone = opts[:zone]
38
41
  end
39
42
  def ec2
40
43
  @ec2 ||= @ec2_proc.call
@@ -56,7 +59,11 @@ class AWS
56
59
  def route53_zone(suffix)
57
60
  suffix_ = Zonify.dot_(suffix)
58
61
  relevant_zone = r53.zones.select do |zone|
59
- suffix_.end_with?(zone.domain)
62
+ if @zone
63
+ @zone == zone.id
64
+ else
65
+ suffix_.end_with?(zone.domain)
66
+ end
60
67
  end.sort_by{|zone| zone.domain.length }.last
61
68
  if relevant_zone
62
69
  relevant_records = relevant_zone.records.all!.map do |rr|
@@ -70,9 +77,19 @@ class AWS
70
77
  # Apply a changeset to the records in Route53. The records must all be under
71
78
  # the same zone and suffix.
72
79
  def apply(changes, comment='Synced with Zonify tool.')
73
- # Dumb way to do this because I can not figure out #reject!
74
- keep = changes.select{|c| c[:value].length <= 100 }
75
- filtered = changes.select{|c| c[:value].length > 100 }
80
+ filtered = changes.select{|change| change[:value].length > 100 }
81
+ # For all the SRV records that were considered too long, get the names of
82
+ # the associated weighted CNAMEs.
83
+ filtered_correlates = filtered.map do |change|
84
+ case change[:name]
85
+ when /^_[*][.]_[*][.]/
86
+ change[:name][6, change[:name].length]
87
+ end
88
+ end.compact
89
+ keep = changes.select do |change|
90
+ change[:value].length <= 100 and not
91
+ filtered_correlates.include?(change[:name])
92
+ end
76
93
  unless keep.empty?
77
94
  suffix = keep.first[:name] # Works because of longest submatch rule.
78
95
  zone, _ = route53_zone(suffix)
@@ -85,14 +102,18 @@ class AWS
85
102
  acc
86
103
  end
87
104
  end
88
- r53.change_resource_record_sets(zone.id, rekeyed, :comment=>comment)
105
+ begin
106
+ r53.change_resource_record_sets(zone.id, rekeyed, :comment=>comment)
107
+ rescue Fog::Errors::Error => e
108
+ STDERR.puts("Failed with some records, due to:\n#{e}")
109
+ end
89
110
  end
90
111
  end
91
112
  filtered
92
113
  end
93
114
  def instances
94
115
  ec2.servers.inject({}) do |acc, i|
95
- dns = i.dns_name
116
+ dns = (i.dns_name or i.private_dns_name)
96
117
  # The default hostname for EC2 instances is derived from their internal
97
118
  # DNS entry.
98
119
  terminal_states = %w| terminated shutting-down |
@@ -294,7 +315,7 @@ def cname_multitudinous(tree)
294
315
  if 'SRV' == type and 1 < data[:value].length
295
316
  wrrs = data[:value].inject({}) do |accumulator, rr|
296
317
  server = Zonify.dot_(rr.sub(/^([^ ]+ +){3}/, '').strip)
297
- id = server.split('.').first # Always the isntance ID.
318
+ id = server.split('.').first # Always the instance ID.
298
319
  accumulator[id] = data.merge(:value=>[server], :weight=>"16")
299
320
  accumulator
300
321
  end
@@ -434,7 +455,7 @@ end
434
455
  LDH_RE = /^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])$/
435
456
  def string_to_ldh_component(s)
436
457
  LDH_RE.match(s) ? s.downcase : s.downcase.gsub(/[^a-z0-9-]/, '-').
437
- sub(/(^[-]+|[-]+$)/, '')[0...64]
458
+ sub(/(^[-]+|[-]+$)/, '')[0...63]
438
459
  end
439
460
 
440
461
  def string_to_ldh(s)
@@ -602,4 +623,3 @@ end
602
623
  RRTYPE_RE = /^([*]|[A-Z0-9-]+)$/
603
624
 
604
625
  end
605
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zonify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Dusek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-31 00:00:00.000000000 Z
11
+ date: 2015-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog