reyes 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/bin/reyes +9 -0
- data/lib/reyes/aws_manager.rb +5 -0
- data/lib/reyes/diff.rb +42 -0
- data/lib/reyes/group_manager.rb +21 -6
- data/lib/reyes/ipset.rb +1 -1
- data/lib/reyes/utils.rb +13 -0
- data/lib/reyes/version.rb +1 -1
- data/lib/reyes.rb +3 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTNjMTNjOGU3ZmM0YTBhMWNhNjE1YTYxNjY5ODczYmJiNDRlZTc5YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjdlNzBkMDBlY2I1MTkyZTJiNGY0ODBkOTI0MzVmZDNlNDkwM2I2Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzI2MjVhMDFiMjBmZDZjYzFkMTVkMjMzZmZhMTU3NjE0NWMxNDU3OTY5N2U1
|
10
|
+
Y2E0YmFhY2E1ZDRlZmMzNTM3Yjk3NGIwNDFkZTk0MGZhZWYwNDgzOTlmZjc2
|
11
|
+
MWNmMjc2ZjBjNjJhNDA3YWQwYjdkYjM3NTBjNDhmNzNmZDM3N2E=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTU5MTM0ODAwNDM5ZjkzNThhOWU1YzMxNTg0NDNmYzc5MzkzMjdmM2Y5YzFi
|
14
|
+
ZjJlZjFkYTMwNzFiMWJmZDhiYmU2ODAwMzRmMGJlMTE3Y2UxY2ExNmUyYWQ3
|
15
|
+
ZmNlZTUyZDVlMTM2ZTM0YzNiMDJkMDc2ODBmZTNkYmVkMTc4NzU=
|
data/bin/reyes
CHANGED
@@ -15,6 +15,11 @@ end
|
|
15
15
|
def command_install(options)
|
16
16
|
instance_id = options.fetch(:instance_id)
|
17
17
|
region = options.fetch(:region)
|
18
|
+
|
19
|
+
if options[:splay]
|
20
|
+
Reyes::Utils.sleep_random(options[:splay])
|
21
|
+
end
|
22
|
+
|
18
23
|
AWS.memoize do
|
19
24
|
g = Reyes::GroupManager.new(region, instance_id, options[:config])
|
20
25
|
|
@@ -75,6 +80,10 @@ Options:
|
|
75
80
|
options[:run_options][:empty] = true
|
76
81
|
end
|
77
82
|
|
83
|
+
opts.on('--splay SECS', 'Delay up to SECS before execution') do |arg|
|
84
|
+
options[:splay] = Integer(arg)
|
85
|
+
end
|
86
|
+
|
78
87
|
opts.on('-h', '--help', 'Display this help message') do
|
79
88
|
STDERR.puts opts
|
80
89
|
exit 0
|
data/lib/reyes/aws_manager.rb
CHANGED
data/lib/reyes/diff.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Reyes
|
2
|
+
class Diff
|
3
|
+
def initialize
|
4
|
+
@old = Tempfile.new('old')
|
5
|
+
@new = Tempfile.new('new')
|
6
|
+
end
|
7
|
+
|
8
|
+
# Consumes the +Diff+, returning the full unified diff of @old and @new
|
9
|
+
# @return [String]
|
10
|
+
def diff
|
11
|
+
raise "Diff has already been created" unless @old && @new
|
12
|
+
|
13
|
+
[@old, @new].each do |f|
|
14
|
+
f.flush
|
15
|
+
end
|
16
|
+
|
17
|
+
Subprocess.call(["diff", '-u', @old.path, @new.path], :stdout => Subprocess::PIPE) do |c|
|
18
|
+
return c.communicate
|
19
|
+
end
|
20
|
+
ensure
|
21
|
+
@old.unlink
|
22
|
+
@old = nil
|
23
|
+
@new.unlink
|
24
|
+
@new = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns a handle to the underlying File for old, allowing the caller to
|
28
|
+
# populate it's contents
|
29
|
+
# @return [File]
|
30
|
+
def old
|
31
|
+
@old
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns a handle to the underlying File for new, allowing the caller to
|
35
|
+
# populate it's contents
|
36
|
+
# @return [File]
|
37
|
+
def new
|
38
|
+
@new
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
data/lib/reyes/group_manager.rb
CHANGED
@@ -82,13 +82,13 @@ module Reyes
|
|
82
82
|
log.info('Finished firewall configuration run')
|
83
83
|
end
|
84
84
|
|
85
|
-
# TODO: actually do some kind of diff or logging here?
|
86
85
|
def show_iptables_diff(new_rules)
|
87
|
-
|
88
|
-
Subprocess.
|
86
|
+
diff = Diff.new
|
87
|
+
diff.old.puts(Subprocess.check_output(%w{iptables-save}))
|
88
|
+
diff.new.puts(new_rules)
|
89
89
|
|
90
|
-
log.info
|
91
|
-
puts
|
90
|
+
log.info "Proposed IPTables diff:"
|
91
|
+
puts diff.diff
|
92
92
|
end
|
93
93
|
|
94
94
|
def iptables_restore(new_rules)
|
@@ -189,7 +189,22 @@ module Reyes
|
|
189
189
|
end
|
190
190
|
|
191
191
|
def show_ipsets_diff(new_ipsets)
|
192
|
-
|
192
|
+
diff = Diff.new
|
193
|
+
|
194
|
+
dump = lambda do |f, ipset|
|
195
|
+
ipset.sort_by(&:name).each do |ip|
|
196
|
+
f.puts(ip.name)
|
197
|
+
ip.members.sort.each do |m|
|
198
|
+
f.puts("\t#{m}")
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
dump.call(diff.old, Reyes::IPSet.load_all)
|
204
|
+
dump.call(diff.new, new_ipsets)
|
205
|
+
|
206
|
+
log.info "Proposed IPSets diff:"
|
207
|
+
puts diff.diff
|
193
208
|
end
|
194
209
|
|
195
210
|
def materialize_ipsets(new_ipsets)
|
data/lib/reyes/ipset.rb
CHANGED
data/lib/reyes/utils.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Reyes; module Utils
|
2
|
+
include Chalk::Log
|
3
|
+
|
4
|
+
# Sleep a random number of seconds, at least zero and less than `max`.
|
5
|
+
#
|
6
|
+
# @param max [Numeric]
|
7
|
+
#
|
8
|
+
def self.sleep_random(max)
|
9
|
+
delay = Random.rand(max)
|
10
|
+
log.info("Sleeping #{delay} seconds -- chosen from [0, #{max})")
|
11
|
+
sleep(delay)
|
12
|
+
end
|
13
|
+
end; end
|
data/lib/reyes/version.rb
CHANGED
data/lib/reyes.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'set'
|
2
|
+
require 'tempfile'
|
2
3
|
require 'yaml'
|
3
4
|
|
4
5
|
require 'chalk-log'
|
@@ -12,8 +13,10 @@ require_relative './reyes/errors'
|
|
12
13
|
|
13
14
|
require_relative './reyes/aws_manager'
|
14
15
|
require_relative './reyes/config'
|
16
|
+
require_relative './reyes/diff'
|
15
17
|
require_relative './reyes/group_manager'
|
16
18
|
require_relative './reyes/group_tools'
|
17
19
|
require_relative './reyes/ipset'
|
18
20
|
require_relative './reyes/iptables'
|
19
21
|
require_relative './reyes/run_generation'
|
22
|
+
require_relative './reyes/utils'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reyes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Brody
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-02-
|
12
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|
@@ -115,12 +115,14 @@ files:
|
|
115
115
|
- lib/reyes.rb
|
116
116
|
- lib/reyes/aws_manager.rb
|
117
117
|
- lib/reyes/config.rb
|
118
|
+
- lib/reyes/diff.rb
|
118
119
|
- lib/reyes/errors.rb
|
119
120
|
- lib/reyes/group_manager.rb
|
120
121
|
- lib/reyes/group_tools.rb
|
121
122
|
- lib/reyes/ipset.rb
|
122
123
|
- lib/reyes/iptables.rb
|
123
124
|
- lib/reyes/run_generation.rb
|
125
|
+
- lib/reyes/utils.rb
|
124
126
|
- lib/reyes/version.rb
|
125
127
|
- reyes.gemspec
|
126
128
|
homepage: ''
|