ronin-wrapper 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ronin/artifact_runner.rb +3 -2
- data/lib/ronin/chef.rb +8 -10
- data/lib/ronin/config.rb +21 -14
- data/lib/ronin/etcd.rb +51 -9
- data/lib/ronin/puppet.rb +6 -6
- data/lib/ronin/ronin.rb +27 -9
- data/lib/ronin/run_list.rb +18 -14
- data/lib/ronin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53e2dbec8e427757f3f6aa4dd83f44da312e738a
|
4
|
+
data.tar.gz: d9826525467d51515bd6e17b84a7a4d3f0f02fa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3caca00937edd64378164774cac21fa6ffe5f21577a9f69960fdabff2ae180ab14d3ac4006ed0b5d6e693f9b96da786d85ea5f2b459d0226315383b62152d6be
|
7
|
+
data.tar.gz: 2144ce58a9df7fea7f7d68819660bef0e7a3d9dfc0f54789b26b0a9edc930a452ef43b55aac3060075a019f6e8e08b353a43af15439452e7b1c01e54f5102924
|
@@ -28,8 +28,9 @@ module Ronin
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def download_and_report_changes
|
31
|
-
|
32
|
-
|
31
|
+
@items = @run_list.items
|
32
|
+
Parallel.each(@items, :in_threads => Ronin::Util.num_cores) do |item|
|
33
|
+
@actual_branch = Ronin::Git.branch(item[:name])
|
33
34
|
|
34
35
|
if File.exist?("#{Ronin::Config[:artifact_path]}/#{item[:name]}")
|
35
36
|
if item[:branch] != 'master'
|
data/lib/ronin/chef.rb
CHANGED
@@ -19,17 +19,18 @@ require 'ronin/log'
|
|
19
19
|
require 'json'
|
20
20
|
|
21
21
|
module Ronin
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
class Chef
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@run_list = "#{Ronin::Config[:artifact_path]}/ronin.json"
|
26
|
+
@solo_conf = "#{Ronin::Config[:artifact_path]}/ronin-chef-solo.rb"
|
27
|
+
@recipes = Ronin::RunList.new.artifacts
|
28
|
+
end
|
26
29
|
|
27
30
|
def create_run_list
|
28
31
|
Ronin::Log.info("Building Chef run list at #{@run_list}.")
|
29
|
-
|
30
32
|
@rl = []
|
31
33
|
@rl_obj = {}
|
32
|
-
|
33
34
|
@recipes.each do |r|
|
34
35
|
@rl << "recipe[#{r}]"
|
35
36
|
Ronin::Log.info("Adding recipe '#{r}' to run list.")
|
@@ -41,7 +42,6 @@ module Ronin
|
|
41
42
|
f.write(@rl_obj.to_json)
|
42
43
|
end
|
43
44
|
end
|
44
|
-
module_function :create_run_list
|
45
45
|
|
46
46
|
def run
|
47
47
|
self.create_run_list
|
@@ -51,7 +51,6 @@ module Ronin
|
|
51
51
|
@cmd.run_command
|
52
52
|
self.clean_up
|
53
53
|
end
|
54
|
-
module_function :run
|
55
54
|
|
56
55
|
def create_solo_conf
|
57
56
|
@solo_config = "file_cache_path '/var/tmp/ronin/chef-solo'\ncookbook_path '#{Ronin::Config[:artifact_path]}'\n"
|
@@ -60,7 +59,6 @@ module Ronin
|
|
60
59
|
f.write(@solo_config)
|
61
60
|
end
|
62
61
|
end
|
63
|
-
module_function :create_solo_conf
|
64
62
|
|
65
63
|
def clean_up
|
66
64
|
Ronin::Log.info("Cleaning up Chef run list at #{@run_list}.")
|
@@ -69,6 +67,6 @@ module Ronin
|
|
69
67
|
Ronin::Log.info("Cleaning up Chef-Solo config at #{@solo_conf}.")
|
70
68
|
File.delete(@solo_conf)
|
71
69
|
end
|
72
|
-
|
70
|
+
|
73
71
|
end
|
74
72
|
end
|
data/lib/ronin/config.rb
CHANGED
@@ -14,6 +14,7 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
require 'mixlib/config'
|
17
|
+
require 'ronin/etcd'
|
17
18
|
|
18
19
|
module Ronin
|
19
20
|
class Config
|
@@ -27,19 +28,25 @@ module Ronin
|
|
27
28
|
puts "No configuration file at #{config_file}, using defaults."
|
28
29
|
end
|
29
30
|
|
30
|
-
config_strict_mode
|
31
|
-
default :
|
32
|
-
default :
|
33
|
-
default :
|
34
|
-
default :
|
35
|
-
default :
|
36
|
-
default :
|
37
|
-
default :
|
38
|
-
default :
|
39
|
-
default :
|
40
|
-
default :
|
31
|
+
config_strict_mode true
|
32
|
+
default :config_from_etcd, false
|
33
|
+
default :lock_file, '/var/tmp/ronin.lock'
|
34
|
+
default :log_path, '/var/log/ronin'
|
35
|
+
default :log_level, :info
|
36
|
+
default :update_on_change, true
|
37
|
+
default :interpreter, 'chef'
|
38
|
+
default :artifact_path, '/var/lib/ronin/artifacts'
|
39
|
+
default :run_list_type, 'yaml'
|
40
|
+
default :run_list_file, '/etc/ronin/artifacts.yaml'
|
41
|
+
default :etcd_host, '127.0.0.1'
|
42
|
+
default :etcd_port, 4001
|
43
|
+
default :etcd_conn_timeout, 5
|
44
|
+
default :etcd_read_timeout, 5
|
45
|
+
default :etcd_use_ssl, false
|
46
|
+
default :etcd_ssl_ca_cert, ''
|
47
|
+
default :etcd_ssl_cert, ''
|
48
|
+
default :etcd_ssl_key, ''
|
49
|
+
default :etcd_keys, [ 'common', 'env', 'node' ]
|
41
50
|
|
42
51
|
end
|
43
|
-
end
|
44
|
-
|
45
|
-
|
52
|
+
end
|
data/lib/ronin/etcd.rb
CHANGED
@@ -20,25 +20,67 @@ require 'socket'
|
|
20
20
|
require 'json'
|
21
21
|
|
22
22
|
# Add test data thus.
|
23
|
-
|
24
|
-
#
|
23
|
+
|
24
|
+
#curl -L http://127.0.0.1:4001/v2/keys/ronin/config/common -X PUT -d value='{
|
25
|
+
# "artifacts": [
|
25
26
|
# "https://github.com/opscode-cookbooks/motd-tail"
|
26
27
|
# ]
|
27
28
|
#}'
|
28
29
|
|
30
|
+
#curl -L http://127.0.0.1:4001/v2/keys/ronin/config/common -X PUT -d value='{
|
31
|
+
# "log_path": "/var/log/ronin",
|
32
|
+
# "interpreter": ":chef",
|
33
|
+
# "artifact_path": "/var/lib/ronin/artifacts",
|
34
|
+
# "update_on_change": "true",
|
35
|
+
# "run_list_type": ":etcd",
|
36
|
+
# "run_list_file": "/etc/ronin/artifacts.yaml"
|
37
|
+
#}'
|
38
|
+
|
29
39
|
module Ronin
|
30
40
|
module Etcd
|
31
|
-
|
41
|
+
|
42
|
+
def get_key(type, key)
|
32
43
|
# Will add error handling... one day.
|
33
|
-
@
|
34
|
-
@
|
35
|
-
@http =
|
36
|
-
@http.
|
44
|
+
@path = "/v2/keys/ronin/#{type}/#{key}"
|
45
|
+
@http = Net::HTTP.new(Ronin::Config[:etcd_host], Ronin::Config[:etcd_port])
|
46
|
+
@http.read_timeout = Ronin::Config[:etcd_read_timeout]
|
47
|
+
@http.open_timeout = Ronin::Config[:etcd_conn_timeout]
|
48
|
+
|
49
|
+
if Ronin::Config[:etcd_use_ssl]
|
50
|
+
@http.use_ssl = true
|
51
|
+
unless Ronin::Config[:etcd_ssl_cert] = ''
|
52
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
53
|
+
store = OpenSSL::X509::Store.new
|
54
|
+
store.add_cert(OpenSSL::X509::Certificate.new(File.read(Ronin::Config[:etcd_ssl_ca_cert])))
|
55
|
+
@http.cert_store = store
|
56
|
+
@http.key = OpenSSL::PKey::RSA.new(File.read(Ronin::Config[:etcd_ssl_cert]))
|
57
|
+
@http.cert = OpenSSL::X509::Certificate.new(File.read(Ronin::Config[:etcd_ssl_key]))
|
58
|
+
end
|
59
|
+
else
|
60
|
+
@http.use_ssl = false
|
61
|
+
end
|
62
|
+
|
37
63
|
@request = Net::HTTP::Get.new(@path)
|
38
64
|
@result = @http.request(@request)
|
39
|
-
|
40
|
-
|
65
|
+
return JSON.parse(@result.body)['node']['value']
|
66
|
+
end
|
67
|
+
module_function :get_key
|
68
|
+
|
69
|
+
def get_config
|
70
|
+
@hostname = Socket.gethostname
|
71
|
+
@common = JSON.parse(Ronin::Etcd.get_key('config', 'common'))
|
72
|
+
#@specific = JSON.parse(Ronin::Etcd.get_key('config', @hostname))
|
73
|
+
#return @common.merge(@specific)
|
74
|
+
end
|
75
|
+
module_function :get_config
|
76
|
+
|
77
|
+
def get_run_list
|
78
|
+
@hostname = Socket.gethostname
|
79
|
+
@common = JSON.parse(Ronin::Etcd.get_key('run_list', 'common'))['artifacts']
|
80
|
+
#@specific = JSON.parse(Ronin::Etcd.get_key('run_list', @hostname))['artifacts']
|
81
|
+
#return (@common+@specific).uniq
|
41
82
|
end
|
42
83
|
module_function :get_run_list
|
84
|
+
|
43
85
|
end
|
44
86
|
end
|
data/lib/ronin/puppet.rb
CHANGED
@@ -18,10 +18,12 @@ require 'ronin/config'
|
|
18
18
|
require 'ronin/log'
|
19
19
|
|
20
20
|
module Ronin
|
21
|
-
|
21
|
+
class Puppet
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
def initialize
|
24
|
+
@run_list = "#{Ronin::Config[:artifact_path]}/ronin.pp"
|
25
|
+
@modules = Ronin::RunList.new.artifacts
|
26
|
+
end
|
25
27
|
|
26
28
|
def create_run_list
|
27
29
|
Ronin::Log.info("Building Puppet run list at #{@run_list}.")
|
@@ -32,7 +34,6 @@ module Ronin
|
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
35
|
-
module_function :create_run_list
|
36
37
|
|
37
38
|
def run
|
38
39
|
self.create_run_list
|
@@ -41,12 +42,11 @@ module Ronin
|
|
41
42
|
@cmd.run_command
|
42
43
|
self.clean_up
|
43
44
|
end
|
44
|
-
module_function :run
|
45
45
|
|
46
46
|
def clean_up
|
47
47
|
Ronin::Log.info("Cleaning up Puppet run list at #{@run_list}.")
|
48
48
|
File.delete(@run_list)
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
end
|
52
52
|
end
|
data/lib/ronin/ronin.rb
CHANGED
@@ -23,6 +23,20 @@ require 'ronin/log'
|
|
23
23
|
module Ronin
|
24
24
|
def run
|
25
25
|
|
26
|
+
if Ronin::Config[:config_from_etcd] == true
|
27
|
+
Ronin::Log.info("Pulling configuration items from etcd (#{Ronin::Config[:etcd_host]}:#{Ronin::Config[:etcd_port]}).")
|
28
|
+
|
29
|
+
Ronin::Etcd.get_config.each do |k, v|
|
30
|
+
Ronin::Log.info("Setting #{k} to #{v}.")
|
31
|
+
|
32
|
+
if v.start_with?(':')
|
33
|
+
v = v[1..-1].to_sym
|
34
|
+
end
|
35
|
+
|
36
|
+
Ronin::Config["#{k}"] = v
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
26
40
|
Ronin::Log.level = Ronin::Config[:log_level]
|
27
41
|
|
28
42
|
if Ronin::Util.find_cmd("git").nil?
|
@@ -40,23 +54,27 @@ module Ronin
|
|
40
54
|
if Ronin::Util.find_cmd("chef-solo").nil? and Ronin::Config[:interpreter] == :puppet
|
41
55
|
abort("You need to have Chef-Solo installed to perform this command with Chef set as the interpreter.")
|
42
56
|
else
|
43
|
-
$CHEFSOLO_BIN = Ronin::Util.find_cmd("
|
57
|
+
$CHEFSOLO_BIN = Ronin::Util.find_cmd("chef-solo")
|
44
58
|
end
|
45
59
|
|
46
60
|
unless File.exists?(Ronin::Config[:lock_file])
|
47
61
|
Ronin::Log.info("Dropping lock file. (#{Ronin::Config[:lock_file]})")
|
48
62
|
File.new(Ronin::Config[:lock_file], "w")
|
49
63
|
|
50
|
-
|
51
|
-
|
52
|
-
|
64
|
+
r = Ronin::ArtifactRunner.new
|
65
|
+
changes = r.download_and_report_changes
|
66
|
+
r.purge_unused
|
53
67
|
|
54
|
-
if
|
55
|
-
if Ronin::Config[:interpreter] ==
|
56
|
-
Ronin::Puppet.
|
57
|
-
|
58
|
-
|
68
|
+
if changes
|
69
|
+
if Ronin::Config[:interpreter] == 'puppet'
|
70
|
+
runner = Ronin::Puppet.new
|
71
|
+
runner.run
|
72
|
+
elsif Ronin::Config[:interpreter] == 'chef'
|
73
|
+
runner = Ronin::Chef.new
|
74
|
+
runner.run
|
59
75
|
end
|
76
|
+
else
|
77
|
+
Ronin::Log.info("No changes detected, not running interpretor.")
|
60
78
|
end
|
61
79
|
Ronin::Log.info("Deleting lock file and exiting. (#{Ronin::Config[:lock_file]})")
|
62
80
|
File.delete(Ronin::Config[:lock_file])
|
data/lib/ronin/run_list.rb
CHANGED
@@ -23,24 +23,28 @@ module Ronin
|
|
23
23
|
|
24
24
|
def initialize
|
25
25
|
@run_list = {}
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
|
27
|
+
if Ronin::Config[:run_list_type] == 'etcd'
|
28
|
+
@artifacts_raw = Ronin::Etcd.get_run_list
|
29
|
+
else
|
30
|
+
@artifacts_raw = YAML.load_file(Ronin::Config['run_list_file'])['artifacts']
|
30
31
|
end
|
31
32
|
|
32
|
-
@artifacts_raw.
|
33
|
-
if a.include?(";")
|
34
|
-
@repo = a.split(";")[0].sub(/(\/)+$/,'')
|
35
|
-
@branch = a.split(";")[1]
|
36
|
-
else
|
37
|
-
@repo = a
|
38
|
-
@branch = 'master'
|
39
|
-
end
|
33
|
+
unless @artifacts_raw.nil?
|
40
34
|
|
41
|
-
@
|
35
|
+
@artifacts_raw.each do |a|
|
36
|
+
if a.include?(";")
|
37
|
+
@repo = a.split(";")[0].sub(/(\/)+$/,'')
|
38
|
+
@branch = a.split(";")[1]
|
39
|
+
else
|
40
|
+
@repo = a
|
41
|
+
@branch = 'master'
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
+
@name = @repo.split("/").last
|
45
|
+
|
46
|
+
@run_list[@name] = { :name => @name, :repo => @repo, :branch => @branch }
|
47
|
+
end
|
44
48
|
end
|
45
49
|
|
46
50
|
@run_list
|
data/lib/ronin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ronin-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Milford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yajl-ruby
|