zonify 0.4.3 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/README +4 -0
  3. data/bin/zonify +17 -5
  4. data/lib/zonify.rb +27 -12
  5. metadata +38 -59
  6. data/lib/zonify/log.rb +0 -36
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e30191a3ca007c303fe49c7e5ae55d9dbb1f29f
4
+ data.tar.gz: e7f5d12cc76788684ab3940786ed741290a06a50
5
+ SHA512:
6
+ metadata.gz: b5ed894a4cd3b0d60318e25ea352e9b283a65fc74582bdc3a388df5e346d8ebe2779ad2b68d92d6482b2113c189ad968a947f0c51ec3eb341983987597ca4252
7
+ data.tar.gz: 9f7d532d7d0cad92a4a485162d0767a43dda163e08449b5e59a1f2b880df32fed0fe82c775e4042b27e574cfbc9d7b25d5359f51a97f4958795522a92caf7a15
data/README CHANGED
@@ -34,6 +34,10 @@ DESCRIPTION
34
34
 
35
35
  AWS_REGION=eu-west-1
36
36
 
37
+ One may specify --use-iam-profile option to configure the zonify tool
38
+ with AWS IAM-provided access and secret keys. This capability is avail-
39
+ able only when running the tool on an EC2 instance with an IAM role.
40
+
37
41
  The Zonify subcommands allow staged generation, transformation and
38
42
  auditing of entries as well as straightforward, one-step synchroniza-
39
43
  tion.
data/bin/zonify CHANGED
@@ -18,7 +18,7 @@ class CLIAWS
18
18
  @options = {}
19
19
  @options.merge!(options) if options
20
20
  env_adapter
21
- { :region => ENV['AWS_REGION'],
21
+ { :region => ENV['AWS_DEFAULT_REGION'],
22
22
  :aws_access_key_id => (access or ENV['AWS_ACCESS_KEY']),
23
23
  :aws_secret_access_key => (secret or ENV['AWS_SECRET_KEY'])
24
24
  }.each{|k,v| @options.merge!(k=>v) if v }
@@ -27,8 +27,9 @@ class CLIAWS
27
27
  aws.respond_to?(sym)
28
28
  end
29
29
  def env_adapter
30
- [ %w| AWS_ACCESS_KEY_ID AWS_ACCESS_KEY |,
31
- %w| AWS_SECRET_ACCESS_KEY AWS_SECRET_KEY | ].each do |a, b|
30
+ [ %w| AWS_REGION AWS_DEFAULT_REGION |,
31
+ %w| AWS_ACCESS_KEY_ID AWS_ACCESS_KEY |,
32
+ %w| AWS_SECRET_ACCESS_KEY AWS_SECRET_KEY | ].each do |a, b|
32
33
  ENV[a] = ENV[b] if ENV[b] # Ensure new variable takes precedence.
33
34
  ENV[b] = ENV[a] unless ENV[b]
34
35
  end
@@ -151,7 +152,9 @@ def main
151
152
  netlogging = (ARGV.delete("-n") or ARGV.delete("--net"))
152
153
  norm = (ARGV.delete("--srv-singleton") or not
153
154
  ARGV.delete("--no-srv-singleton"))
155
+ use_iam_profile = ARGV.delete("--use-iam-profile")
154
156
  aws = CLIAWS.new
157
+ aws.options[:use_iam_profile] = true if use_iam_profile
155
158
  types = nil
156
159
  while i = ARGV.index('--types')
157
160
  ARGV.delete_at(i)
@@ -183,13 +186,22 @@ def main
183
186
  Zonify::YAML.trim_lines(dumped).join.sub(/ *\[\]$/,'')
184
187
  end.join
185
188
  STDOUT.write entries
189
+ when 'merge'
190
+ parsed = ARGV[1..-1].map{|path| Zonify::YAML.read(File.read(path)) }
191
+ unless parsed.empty?
192
+ suffix, records = parsed[0]
193
+ rebased = parsed[1..-1].map do |sfx, recs|
194
+ Zonify::Mappings.rewrite(recs, [[sfx,[suffix]]])
195
+ end
196
+ STDOUT.write Zonify::YAML.format(Zonify.merge(records, *rebased), suffix)
197
+ end
186
198
  when 'diff'
187
199
  suffix, old_records = Zonify::YAML.read(File.read(ARGV[1]))
188
200
  new_suffix, new_records = Zonify::YAML.read(File.read(ARGV[2]))
189
201
  qualified = Zonify::Mappings.rewrite(new_records, [[new_suffix,[suffix]]])
190
202
  changes = Zonify.diff(qualified, old_records, (types or %w| * |))
191
203
  STDERR.puts(display(changes)) unless quiet
192
- STDOUT.write(Zonify::YAML.trim_lines(YAML.dump(changes)))
204
+ STDOUT.write(Zonify::YAML.trim_lines(YAML.dump(changes)).join)
193
205
  when 'sync'
194
206
  suffix = ARGV[1]
195
207
  check_name(suffix)
@@ -214,7 +226,7 @@ def main
214
226
  _, old_records = aws.route53_zone(suffix)
215
227
  changes = Zonify.diff(mapped, old_records, (types or %w| CNAME SRV |))
216
228
  STDERR.puts(display(changes)) unless quiet
217
- STDOUT.write(Zonify::YAML.trim_lines(YAML.dump(changes)))
229
+ STDOUT.write(Zonify::YAML.trim_lines(YAML.dump(changes)).join)
218
230
  when 'summarize'
219
231
  handle = ARGV[1] ? File.open(ARGV[1]) : STDIN
220
232
  changes = yaml_with_default(handle, [])
@@ -95,7 +95,8 @@ class AWS
95
95
  dns = i.dns_name
96
96
  # The default hostname for EC2 instances is derived from their internal
97
97
  # DNS entry.
98
- unless dns.nil? or dns.empty? or i.state == 'terminated'
98
+ terminal_states = %w| terminated shutting-down |
99
+ unless dns.nil? or dns.empty? or terminal_states.member? i.state
99
100
  groups = (i.groups or [])
100
101
  attrs = { :sg => groups,
101
102
  :tags => (i.tags or []),
@@ -111,7 +112,7 @@ class AWS
111
112
  def load_balancers
112
113
  elb.load_balancers.map do |elb|
113
114
  { :instances => elb.instances,
114
- :prefix => Zonify.cut_down_elb_name(elb.dns_name) }
115
+ :prefix => Zonify.cut_down_elb_name(elb.dns_name.downcase) }
115
116
  end
116
117
  end
117
118
  def eips
@@ -170,8 +171,8 @@ def zone(hosts, elbs)
170
171
  host_records = hosts.map do |id,info|
171
172
  name = "#{id}.inst."
172
173
  priv = "#{info[:priv]}.priv."
173
- [ Zonify::RR.cname(name, info[:dns], '86400'),
174
- Zonify::RR.cname(priv, info[:dns], '86400'),
174
+ [ Zonify::RR.cname(name, info[:dns], '600'),
175
+ Zonify::RR.cname(priv, info[:dns], '600'),
175
176
  Zonify::RR.srv('inst.', name) ] +
176
177
  info[:tags].map do |tag|
177
178
  k, v = tag
@@ -464,17 +465,31 @@ end
464
465
  module YAML
465
466
  extend self
466
467
  def format(records, suffix='')
467
- _suffix_ = Zonify._dot(Zonify.dot_(suffix))
468
- entries = records.keys.sort.map do |k|
469
- dumped = ::YAML.dump(k=>records[k])
470
- Zonify::YAML.trim_lines(dumped).map{|ln| ' ' + ln }.join
471
- end.join
472
- "suffix: #{_suffix_}\nrecords:\n" + entries
468
+ _suffix_ = Zonify._dot(Zonify.dot_(suffix))
469
+ entries = records.keys.sort.map do |k|
470
+ if k == 'CNAME'
471
+ STDERR.puts(::YAML.dump(records))
472
+ abort "A problem was found // #{ARGV[0]}"
473
+ end
474
+ [ k + ":\n" ] + records[k].keys.sort_by{|kk| kk.to_s }.map do |kk|
475
+ sorted = Zonify::YAML.sorted_hash(records[k][kk])
476
+ lines = Zonify::YAML.trim_lines(sorted)
477
+ [ kk + ":\n" ] + lines.map{|ln| ' ' + ln }
478
+ end.flatten.map{|ln| ' ' + ln }
479
+ end.flatten.map{|ln| ' ' + ln }.join
480
+ "suffix: #{_suffix_}\nrecords:\n" + entries
481
+ end
482
+ def sorted_hash(h)
483
+ result = ::YAML::quick_emit(h.object_id, {}) do |out|
484
+ out.map("") do |map|
485
+ h.keys.sort_by{|k| k.to_s }.each{|k| map.add(k, h[k]) }
486
+ end
487
+ end
473
488
  end
474
489
  def read(text)
475
490
  yaml = ::YAML.load(text)
476
- if yaml['suffix'] and yaml['records']
477
- [yaml['suffix'], yaml['records']]
491
+ if yaml['suffix']
492
+ [yaml['suffix'], (yaml['records'] or {})]
478
493
  end
479
494
  end
480
495
  def trim_lines(yaml)
metadata CHANGED
@@ -1,85 +1,64 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: zonify
3
- version: !ruby/object:Gem::Version
4
- hash: 9
5
- prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 3
10
- version: 0.4.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.6
11
5
  platform: ruby
12
- authors:
13
- - Airbnb
6
+ authors:
7
+ - Jason Dusek
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2013-02-04 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2014-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: fog
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
32
20
  type: :runtime
33
- version_requirements: *id001
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
34
27
  description: |
35
28
  Zonify provides a command line tool for generating DNS records from EC2
36
29
  instances, instance tags, load balancers and security groups. A mechanism for
37
30
  syncing these records with a zone stored in Route 53 is also provided.
38
-
39
- email: contact@airbnb.com
40
- executables:
31
+ email: oss@solidsnack.be
32
+ executables:
41
33
  - zonify
42
34
  extensions: []
43
-
44
35
  extra_rdoc_files: []
45
-
46
- files:
47
- - lib/zonify/log.rb
36
+ files:
48
37
  - lib/zonify.rb
49
38
  - README
50
39
  - bin/zonify
51
- homepage: https://github.com/airbnb/zonify
52
- licenses:
40
+ homepage: https://github.com/solidsnack/zonify
41
+ licenses:
53
42
  - BSD
43
+ metadata: {}
54
44
  post_install_message:
55
45
  rdoc_options: []
56
-
57
- require_paths:
46
+ require_paths:
58
47
  - lib
59
- required_ruby_version: !ruby/object:Gem::Requirement
60
- none: false
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- hash: 3
65
- segments:
66
- - 0
67
- version: "0"
68
- required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
77
58
  requirements: []
78
-
79
59
  rubyforge_project:
80
- rubygems_version: 1.8.24
60
+ rubygems_version: 2.0.14
81
61
  signing_key:
82
- specification_version: 3
62
+ specification_version: 4
83
63
  summary: Generate DNS information from EC2 metadata.
84
64
  test_files: []
85
-
@@ -1,36 +0,0 @@
1
- require 'time'
2
-
3
- require 'sqlite3'
4
-
5
- module Zonify
6
- module Log
7
-
8
- class SQLite
9
- attr_reader :connection_string, :connection
10
- def initialize(connection_string=':memory:')
11
- @connection_string = connection_string
12
- @connection = SQLite3::Database.new(@connection_string)
13
- end
14
-
15
- def log(record)
16
- name, type, ttl, value,
17
- weight, set = [ record[:name], record[:type],
18
- record[:ttl], record[:value],
19
- record[:weight], record[:set_identifier] ]
20
- name, type, ttl, value,
21
- weight, set = [ record[:name], record[:type],
22
- record[:ttl], record[:value],
23
- record[:weight], record[:set_identifier] ]
24
- end
25
- end
26
-
27
- extend self
28
-
29
- def now
30
- x = Time.now.utc
31
- x.iso8601.sub('T', ' ').sub('Z','.') + ("%0.3f" % x.to_f).split('.').last
32
- end
33
-
34
- end
35
- end
36
-