r53z 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -13
- data/bin/r53z +4 -3
- data/lib/r53z/cli.rb +26 -1
- data/lib/r53z/client.rb +35 -20
- data/lib/r53z/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01330f8ce2de5edce6c20dc4f8a38df05b89bef3
|
4
|
+
data.tar.gz: cfde757ab218ccd71630ccc51459f904b38c5943
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6e4f8cee2366bdf67c884128c7190bee6e1c0796211d34ee7706b0573e5bdc514231c09cd64870dbc93f2b37ed1d9127cdbd9a422ccdd3bbb1b38baf49a8b17
|
7
|
+
data.tar.gz: 5f124496e1d75f8bd22542b506cc8a5fd152edebb2bfeead85f96bdec16758072d17d84b15b88abaa3f934d0d59bb810c42084733ccda2f0e3935a5c6ba3d1bf
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# R53z
|
2
2
|
|
3
|
-
A simple CLI, REPL, and library for managing Route 53. It's primary purpose is to back up and restore Route 53 zones. It can write zones to files in JSON format. It also provides a simple API (not a whole lot easier than the Amazon official API, but for backups and restores, it's much easier to script with and removes tons of boilerplate).
|
3
|
+
A simple CLI, REPL, and library for managing Route 53. It's primary purpose is to back up and restore Route 53 zones. It can write zones to files in JSON format. It also provides a simple API (not a whole lot easier than the Amazon official API, but for backups and restores, it's much easier to script with and removes tons of boilerplate). There are several other similar tools on github (cli53 probably being the best and best known), but they all had something preventing them from working for the use cases I needed to support (or were based on old versions of the AWS API or had built their own incomplete API); as far as I can tell, r53z currently does more then the other tools out there, and once all of the backend has been hooked up to the front end, it'll be a pretty complete CLI and REPL for Route 53.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -16,10 +16,20 @@ And then execute:
|
|
16
16
|
|
17
17
|
$ bundle
|
18
18
|
|
19
|
-
|
19
|
+
Run the command with:
|
20
20
|
|
21
|
-
$
|
21
|
+
$ bundle exec bin/r53z
|
22
|
+
|
23
|
+
And, you can run a REPL with:
|
24
|
+
|
25
|
+
$ bundle exec bin/console
|
26
|
+
|
27
|
+
A `client` object has methods for most common tasks with Route 53, maybe it easy to script with. The REPL is a little clumsy on startup, as it uses the binding method, which gives some clunky output, but it allows setting up both the credentials and client automatically.
|
22
28
|
|
29
|
+
Or install it yourself as (the gem installs an r53z executable in the path, but not the `console` REPL):
|
30
|
+
|
31
|
+
$ gem install r53z
|
32
|
+
|
23
33
|
## Usage
|
24
34
|
|
25
35
|
**NOTE:** Don't get too attached to the current CLI options. I'm rewriting the option parser to use sub-commands in the near future. So, if you love it like it is (surely, nobody could love it like it is), you'll need to lock in a version that still has this parser.
|
@@ -35,12 +45,12 @@ region=us-east-1
|
|
35
45
|
|
36
46
|
You can use the `--section` option to choose which section to use from the credentials file, and the credentials file can be specified with the `--credentials` option. Region is irrelevant with Route 53, but the aws-sdk weirdly still requires it be present.
|
37
47
|
|
38
|
-
```
|
48
|
+
```sh
|
39
49
|
Usage: r53z [options] [args...]
|
40
50
|
|
41
51
|
Simple CLI to manage, backup, and restore, Route 53 zones
|
42
52
|
|
43
|
-
v0.3.
|
53
|
+
v0.3.2
|
44
54
|
|
45
55
|
Options:
|
46
56
|
-h, --help Show command line help
|
@@ -76,7 +86,7 @@ Two files will be generated in the directory specified, one for the zone metadat
|
|
76
86
|
|
77
87
|
##### Example
|
78
88
|
|
79
|
-
```
|
89
|
+
```sh
|
80
90
|
$ r53z --export /home/joe/zones swelljoe.com
|
81
91
|
```
|
82
92
|
|
@@ -90,7 +100,7 @@ If `--delegation-set` is specified on the command line, it will override the del
|
|
90
100
|
|
91
101
|
##### Example
|
92
102
|
|
93
|
-
```
|
103
|
+
```sh
|
94
104
|
$ r53z --restore /home/joe/zones swelljoe.com
|
95
105
|
```
|
96
106
|
|
@@ -104,7 +114,7 @@ Create zone of the NAME provided. An optional command an delegation set ID may b
|
|
104
114
|
|
105
115
|
##### Example
|
106
116
|
|
107
|
-
```
|
117
|
+
```sh
|
108
118
|
$ r53z --create swelljoe.com --comment "My domain"
|
109
119
|
```
|
110
120
|
|
@@ -114,7 +124,7 @@ Delete one or more zones. Argument is the name of the zone, or zones, to delete.
|
|
114
124
|
|
115
125
|
##### Example
|
116
126
|
|
117
|
-
```
|
127
|
+
```sh
|
118
128
|
$ r53z --delete swelljoe.com virtualmin.com
|
119
129
|
```
|
120
130
|
|
@@ -128,7 +138,7 @@ Specify the credentials configuration file on the command line. The file must be
|
|
128
138
|
|
129
139
|
Finding the delegation set of a zone, and backing up all zones that share that delegation set:
|
130
140
|
|
131
|
-
```
|
141
|
+
```sh
|
132
142
|
$ r53z --list-delegation-sets swelljoe.com
|
133
143
|
{
|
134
144
|
"id": "/delegationset/NKXKQ56JI1ZGT",
|
@@ -145,13 +155,13 @@ $ r53z --export ~/dumps --delegation-set "/delegationset/NKXKQ56JI1ZGT"
|
|
145
155
|
|
146
156
|
Creating a new zone with an existing delegation set:
|
147
157
|
|
148
|
-
```
|
158
|
+
```sh
|
149
159
|
$ r53z --create swelljoe.com --comment "dootdoot" --delegation-set "/delegationset/NKXKQ56JI1ZGT"
|
150
160
|
```
|
151
161
|
|
152
162
|
Restoring a zone into a specific delegation set (this will override the delegation set specified in the dump file):
|
153
163
|
|
154
|
-
```
|
164
|
+
```sh
|
155
165
|
$ r53z --restore ~/dumps swelljoe.com --delegation-set "/delegationset/NKXKQ56JI1ZGT"
|
156
166
|
```
|
157
167
|
|
@@ -167,12 +177,15 @@ To run the full test suite, you need a read/write capable account. There must be
|
|
167
177
|
|
168
178
|
To run all tests:
|
169
179
|
|
170
|
-
```
|
180
|
+
```sh
|
171
181
|
$ rake test
|
172
182
|
```
|
173
183
|
|
174
184
|
This will create a few test zones in your account, but unless something goes wrong during the test, they will be removed immediately after, never triggering billing from Amazon. The zones will have somewhat randomly generated names, so they should never clash with existing names (but you may wish to create a non-production account just for testing).
|
175
185
|
|
186
|
+
There is one extra tests file called disabled_tc_101.rb. It is disabled, by default, because it takes quite a while to run, especially on a slow link. It produces 101 zones, in order to exercise the list truncation handling code for sets over 100
|
187
|
+
zones.
|
188
|
+
|
176
189
|
## Contributing
|
177
190
|
|
178
191
|
Bug reports and pull requests are welcome on GitHub at https://github.com/swelljoe/r53z.
|
data/bin/r53z
CHANGED
@@ -9,7 +9,7 @@ class App
|
|
9
9
|
include Methadone::CLILogging
|
10
10
|
|
11
11
|
main do |*args|
|
12
|
-
help_now! "No options provided." if options.empty?
|
12
|
+
help_now! "No options provided." if options.empty?
|
13
13
|
R53z::Cli.new(:options => options, :args => args)
|
14
14
|
end
|
15
15
|
|
@@ -20,7 +20,7 @@ class App
|
|
20
20
|
on("-x DIR", "--export", "Export zones to files in specified directory, optionally specify one or more zones.")
|
21
21
|
on("-r DIR", "--restore", "Restore zone from directory, optionally specify one or more zones.")
|
22
22
|
on("-l", "--list", "List name and ID of one or all zones.")
|
23
|
-
on("-s", "--
|
23
|
+
on("-s", "--list-records", "List record sets for the given zone.")
|
24
24
|
on("-c NAME", "--create", "Create a zone with the given name and optional --comment and --delegation-set.")
|
25
25
|
on("-n COMMENT", "--comment", "Optional comment when creating a zone.")
|
26
26
|
on("-d", "--delete", "Delete one or more zone(s) by name (WARNING: No confirmation!)")
|
@@ -31,6 +31,8 @@ class App
|
|
31
31
|
on("-S", "--create-delegation-sets", "Create one or more delegation sets, optionally associated with listed zones.")
|
32
32
|
on("-D", "--delete-delegation-sets", "Delete one or more delegation sets by ID (WARNING: No confirmation!)")
|
33
33
|
on("-N ID", "--name-servers", "List name servers for delegation set.")
|
34
|
+
on("-L", "--list-by-id", "List one or more zones for the given hosted zone ID(s).")
|
35
|
+
on("-R", "--list-records-by-id", "List one or more record sets for the given hosted zone ID(s).")
|
34
36
|
# args greedily grabs any files or zones listed after the options
|
35
37
|
arg(:args, :any)
|
36
38
|
|
@@ -40,4 +42,3 @@ class App
|
|
40
42
|
|
41
43
|
go!
|
42
44
|
end
|
43
|
-
|
data/lib/r53z/cli.rb
CHANGED
@@ -79,6 +79,20 @@ module R53z
|
|
79
79
|
dset = @client.get_delegation_set(options['name-servers'])
|
80
80
|
puts JSON.pretty_generate(dset.delegation_set[:name_servers])
|
81
81
|
end
|
82
|
+
|
83
|
+
if options['list-by-id']
|
84
|
+
if args.empty?
|
85
|
+
exit_now! "List by ID requires one or more zone IDs."
|
86
|
+
end
|
87
|
+
list_by_id(args)
|
88
|
+
end
|
89
|
+
|
90
|
+
if options['list-records-by-id']
|
91
|
+
if args.empty?
|
92
|
+
exit_now! "List records by ID requies on or more zone IDs."
|
93
|
+
end
|
94
|
+
list_records_by_id(args)
|
95
|
+
end
|
82
96
|
end
|
83
97
|
|
84
98
|
def export(options:, args:)
|
@@ -215,6 +229,17 @@ module R53z
|
|
215
229
|
end
|
216
230
|
end
|
217
231
|
end
|
232
|
+
|
233
|
+
def list_by_id(args)
|
234
|
+
args.each do |id|
|
235
|
+
puts JSON.pretty_generate(@client.list_by_id(id).to_hash)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def list_records_by_id(args)
|
240
|
+
args.each do |id|
|
241
|
+
puts JSON.pretty_generate(@client.list_records(id))
|
242
|
+
end
|
243
|
+
end
|
218
244
|
end
|
219
245
|
end
|
220
|
-
|
data/lib/r53z/client.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module R53z
|
2
|
-
class Client
|
2
|
+
class Client
|
3
3
|
include Methadone::Main
|
4
4
|
include Methadone::CLILogging
|
5
5
|
attr_accessor :client
|
@@ -42,6 +42,9 @@ module R53z
|
|
42
42
|
delegation_set_id: delegation_set_id,
|
43
43
|
marker: marker,
|
44
44
|
)
|
45
|
+
# R53 imposes a 5 request per second limit
|
46
|
+
# Could catch "throttling"/"rate exceeded" error and retry
|
47
|
+
sleep 0.3
|
45
48
|
else
|
46
49
|
resp = self.client.list_hosted_zones(
|
47
50
|
delegation_set_id: delegation_set_id)
|
@@ -59,11 +62,11 @@ module R53z
|
|
59
62
|
# Create zone with record(s) from an info and records hash
|
60
63
|
def create(info:, records: nil)
|
61
64
|
rv = {} # pile up the responses in a single hash
|
62
|
-
#if self.list(info[:name]).any?
|
63
|
-
# error(info[:name] + "exists")
|
65
|
+
#if self.list(name: info[:name]).any?
|
66
|
+
# error(info[:name].to_s + " already exists")
|
64
67
|
#end
|
65
68
|
# XXX: AWS sends out a data structure with config:, but expects
|
66
|
-
# hosted_zone_config on create/restore. argh.
|
69
|
+
# hosted_zone_config: on create/restore. argh.
|
67
70
|
# XXX: also, private_zone is not accepted here for some reason
|
68
71
|
zone = info[:hosted_zone]
|
69
72
|
# Populate a zone_data hash with options for zone creation
|
@@ -84,7 +87,7 @@ module R53z
|
|
84
87
|
# Optionally populate records
|
85
88
|
if records
|
86
89
|
records.each do |record|
|
87
|
-
# skip these, as they are handled separately (delegation
|
90
|
+
# skip these, as they are handled separately (delegation sets)
|
88
91
|
unless (record[:type] == "NS" || record[:type] == "SOA")
|
89
92
|
record_resp = self.client.change_resource_record_sets({
|
90
93
|
:hosted_zone_id => zone_resp[:hosted_zone][:id],
|
@@ -104,12 +107,18 @@ module R53z
|
|
104
107
|
return rv
|
105
108
|
end
|
106
109
|
|
107
|
-
# delete a zone by name
|
108
|
-
def delete(name)
|
109
|
-
#
|
110
|
-
|
111
|
-
|
112
|
-
|
110
|
+
# delete a zone by name, optionally by ID
|
111
|
+
def delete(name, id: nil)
|
112
|
+
# if we got both, demand nil for name, because AWS allows multiples
|
113
|
+
if name and id
|
114
|
+
raise "Name should be nil when id is provided."
|
115
|
+
end
|
116
|
+
unless id
|
117
|
+
id = self.list(:name => name).first[:id]
|
118
|
+
end
|
119
|
+
# Can't delete unless empty of record sets
|
120
|
+
self.delete_all_rr_sets(id)
|
121
|
+
client.delete_hosted_zone(:id => id)
|
113
122
|
end
|
114
123
|
|
115
124
|
# delete all of the resource record sets in a zone (this is required to delete
|
@@ -130,7 +139,7 @@ module R53z
|
|
130
139
|
end
|
131
140
|
end
|
132
141
|
|
133
|
-
# dump a zone to a direcory. Will generate two files; a zoneinfo file and a
|
142
|
+
# dump a zone to a direcory. Will generate two files; a zoneinfo file and a
|
134
143
|
# records file.
|
135
144
|
def dump(dirpath, name)
|
136
145
|
# Get the ID
|
@@ -147,17 +156,15 @@ module R53z
|
|
147
156
|
data: self.list_records(zone_id))
|
148
157
|
|
149
158
|
# Dump the zone metadata, plus the delegated set info
|
150
|
-
out = { :hosted_zone =>
|
159
|
+
out = { :hosted_zone =>
|
151
160
|
self.client.get_hosted_zone({ :id => zone_id}).hosted_zone.to_h,
|
152
|
-
:delegation_set =>
|
161
|
+
:delegation_set =>
|
153
162
|
self.client.get_hosted_zone({:id => zone_id}).delegation_set.to_h
|
154
163
|
}
|
155
164
|
|
156
165
|
R53z::JsonFile.write_json(
|
157
166
|
path: File.join(dirpath, name + "zoneinfo"),
|
158
167
|
data: out)
|
159
|
-
#data: self.client.get_hosted_zone({
|
160
|
-
# :id => zone_id}).hosted_zone.to_h)
|
161
168
|
end
|
162
169
|
|
163
170
|
# Restore a zone from the given path. It expects files named
|
@@ -201,7 +208,7 @@ module R53z
|
|
201
208
|
resp = self.client.list_reusable_delegation_sets({})
|
202
209
|
return resp.delegation_sets
|
203
210
|
end
|
204
|
-
|
211
|
+
|
205
212
|
# get details of a delegation set specified by ID, incuding name servers
|
206
213
|
def get_delegation_set(id)
|
207
214
|
self.client.get_reusable_delegation_set({
|
@@ -227,13 +234,22 @@ module R53z
|
|
227
234
|
return nil
|
228
235
|
end
|
229
236
|
return self.client.get_hosted_zone({
|
230
|
-
id: zone_id
|
237
|
+
id: zone_id
|
231
238
|
}).delegation_set[:id]
|
232
239
|
end
|
233
240
|
|
241
|
+
# Get zone information in a different way for testing
|
242
|
+
def list_by_id(id)
|
243
|
+
# no begin, let exceptions bubble up, maybe it'll give useful data
|
244
|
+
zone = self.client.get_hosted_zone({
|
245
|
+
id: id
|
246
|
+
}).hosted_zone
|
247
|
+
return zone
|
248
|
+
end
|
249
|
+
|
234
250
|
# Get the zone id from name
|
235
251
|
def get_zone_id(name)
|
236
|
-
|
252
|
+
self.list(:name => name).first[:id]
|
237
253
|
end
|
238
254
|
|
239
255
|
# random string generator helper function
|
@@ -242,4 +258,3 @@ module R53z
|
|
242
258
|
end
|
243
259
|
end
|
244
260
|
end
|
245
|
-
|
data/lib/r53z/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r53z
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Cooper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -146,7 +146,6 @@ extra_rdoc_files: []
|
|
146
146
|
files:
|
147
147
|
- ".gitignore"
|
148
148
|
- Gemfile
|
149
|
-
- Gemfile.lock
|
150
149
|
- LICENSE
|
151
150
|
- LICENSE.txt
|
152
151
|
- README.md
|