ronin-wrapper 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ronin +6 -1
- data/lib/ronin.rb +1 -1
- data/lib/ronin/{module_runner.rb → artifact_runner.rb} +10 -10
- data/lib/ronin/chef.rb +51 -1
- data/lib/ronin/config.rb +2 -2
- data/lib/ronin/git.rb +6 -6
- data/lib/ronin/puppet.rb +4 -4
- data/lib/ronin/ronin.rb +6 -9
- data/lib/ronin/run_list.rb +2 -2
- 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: 2c3c00f54efdb0caece795e59b3647d555f25ea3
|
4
|
+
data.tar.gz: 8cb9cae2f49b2bc0453e32fefdc5f649f34dac24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f1fb190ffc1853a1341fcc19741b563898e82691c493b3c222d5713e9e3bece065c7d04204fc9212d6719ae43a512f6eff06ae5c8cdc19ed8d31f32221f5cc1
|
7
|
+
data.tar.gz: 7e4bcdf75d4b40262809e7958a2f7a0fc7e10bdd37d44cd3b24ba47b8bd57d1c4ae700d43278d89d3db293c43192d47789633762f7aa3532e2c2967cae15bb03
|
data/bin/ronin
CHANGED
data/lib/ronin.rb
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
require 'ronin/config'
|
17
|
-
require 'ronin/
|
17
|
+
require 'ronin/artifact_runner'
|
18
18
|
require 'ronin/run_list'
|
19
19
|
require 'ronin/version'
|
20
20
|
require 'ronin/puppet'
|
@@ -19,7 +19,7 @@ require 'ronin/log'
|
|
19
19
|
require 'fileutils'
|
20
20
|
|
21
21
|
module Ronin
|
22
|
-
class
|
22
|
+
class ArtifactRunner
|
23
23
|
def initialize
|
24
24
|
@changes = false
|
25
25
|
@run_list = Ronin::RunList.new
|
@@ -29,7 +29,7 @@ module Ronin
|
|
29
29
|
@run_list.items.each do |item|
|
30
30
|
@actual_branch = Ronin::Git.branch(item[:name])
|
31
31
|
|
32
|
-
if File.exist?("#{Ronin::Config[:
|
32
|
+
if File.exist?("#{Ronin::Config[:artifact_path]}/#{item[:name]}")
|
33
33
|
if item[:branch] != 'master'
|
34
34
|
Ronin::Log.info("Module #{item[:name]} is being pulled from the #{item[:branch]} branch and not master.")
|
35
35
|
end
|
@@ -43,12 +43,12 @@ module Ronin
|
|
43
43
|
end
|
44
44
|
else
|
45
45
|
Ronin::Log.info("Module #{item[:name]} already cached, but is the wrong branch. Deleting cached copy of branch #{@actual_branch}")
|
46
|
-
FileUtils.rm_rf("#{Ronin::Config[:
|
46
|
+
FileUtils.rm_rf("#{Ronin::Config[:artifact_path]}/#{item[:name]}/")
|
47
47
|
Ronin::Git.clone(item[:repo], item[:branch])
|
48
48
|
@changes = true if Ronin::Config[:update_on_change]
|
49
49
|
end
|
50
50
|
else
|
51
|
-
Ronin::Log.info("Module #{item[:name]} not cached, cloning branch #{item[:branch]} of #{item[:repo]} to #{Ronin::Config[:
|
51
|
+
Ronin::Log.info("Module #{item[:name]} not cached, cloning branch #{item[:branch]} of #{item[:repo]} to #{Ronin::Config[:artifact_path]}.")
|
52
52
|
Ronin::Git.clone(item)
|
53
53
|
@changes = true if Ronin::Config[:update_on_change]
|
54
54
|
end
|
@@ -57,13 +57,13 @@ module Ronin
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def purge_unused
|
60
|
-
@
|
61
|
-
@
|
60
|
+
@local_artifacts = Dir.entries(Ronin::Config[:artifact_path]).select { |dir| File.directory?("#{Ronin::Config[:artifact_path]}/#{dir}") and !(dir =='.' || dir == '..') }
|
61
|
+
@artifacts = @run_list.artifacts
|
62
62
|
|
63
|
-
@
|
64
|
-
unless @
|
65
|
-
Ronin::Log.info("No module named #{
|
66
|
-
FileUtils.rm_rf("#{Ronin::Config[:
|
63
|
+
@local_artifacts.each do |a|
|
64
|
+
unless @artifacts.include?(a)
|
65
|
+
Ronin::Log.info("No module named #{a} in run list, but it exists in #{Ronin::Config[:artifact_path]}. Purging it.")
|
66
|
+
FileUtils.rm_rf("#{Ronin::Config[:artifact_path]}/#{a}/")
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
data/lib/ronin/chef.rb
CHANGED
@@ -16,9 +16,59 @@
|
|
16
16
|
require 'ronin/run_list'
|
17
17
|
require 'ronin/config'
|
18
18
|
require 'ronin/log'
|
19
|
+
require 'json'
|
19
20
|
|
20
21
|
module Ronin
|
21
22
|
module Chef
|
22
|
-
#
|
23
|
+
@run_list = "#{Ronin::Config[:artifact_path]}/ronin.json"
|
24
|
+
@solo_conf = "#{Ronin::Config[:artifact_path]}/ronin-chef-solo.rb"
|
25
|
+
@recipes = Ronin::RunList.new.artifacts
|
26
|
+
|
27
|
+
def create_run_list
|
28
|
+
Ronin::Log.info("Building Chef run list at #{@run_list}.")
|
29
|
+
|
30
|
+
@rl = []
|
31
|
+
@rl_obj = {}
|
32
|
+
|
33
|
+
@recipes.each do |r|
|
34
|
+
@rl << "recipe[#{r}]"
|
35
|
+
Ronin::Log.info("Adding recipe '#{r}' to run list.")
|
36
|
+
end
|
37
|
+
|
38
|
+
@rl_obj['run_list'] = @rl
|
39
|
+
|
40
|
+
File.open(@run_list, "w") do |f|
|
41
|
+
f.write(@rl_obj.to_json)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
module_function :create_run_list
|
45
|
+
|
46
|
+
def run
|
47
|
+
self.create_run_list
|
48
|
+
self.create_solo_conf
|
49
|
+
Ronin::Log.info("Running Chef, logging to #{Ronin::Config[:log_path]}/ronin-chef.log.")
|
50
|
+
@cmd = Mixlib::ShellOut.new("chef-solo --logfile #{Ronin::Config[:log_path]}/ronin-chef.log --config #{@solo_conf} --json-attributes #{@run_list}")
|
51
|
+
@cmd.run_command
|
52
|
+
self.clean_up
|
53
|
+
end
|
54
|
+
module_function :run
|
55
|
+
|
56
|
+
def create_solo_conf
|
57
|
+
@solo_config = "file_cache_path '/var/tmp/ronin/chef-solo'\ncookbook_path '#{Ronin::Config[:artifact_path]}'\n"
|
58
|
+
|
59
|
+
File.open(@solo_conf, "w") do |f|
|
60
|
+
f.write(@solo_config)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
module_function :create_solo_conf
|
64
|
+
|
65
|
+
def clean_up
|
66
|
+
Ronin::Log.info("Cleaning up Chef run list at #{@run_list}.")
|
67
|
+
File.delete(@run_list)
|
68
|
+
|
69
|
+
Ronin::Log.info("Cleaning up Chef-Solo config at #{@solo_conf}.")
|
70
|
+
File.delete(@solo_conf)
|
71
|
+
end
|
72
|
+
module_function :clean_up
|
23
73
|
end
|
24
74
|
end
|
data/lib/ronin/config.rb
CHANGED
@@ -33,8 +33,8 @@ module Ronin
|
|
33
33
|
default :update_on_change, true
|
34
34
|
default :run_list_type, :yaml
|
35
35
|
default :interpreter, :puppet
|
36
|
-
default :run_list_file, '/etc/ronin/
|
37
|
-
default :
|
36
|
+
default :run_list_file, '/etc/ronin/artifacts.yaml'
|
37
|
+
default :artifact_path, '/var/lib/ronin/artifacts'
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
data/lib/ronin/git.rb
CHANGED
@@ -18,24 +18,24 @@ require 'ronin/config'
|
|
18
18
|
|
19
19
|
module Ronin
|
20
20
|
module Git
|
21
|
-
def branch(
|
22
|
-
@cmd = Mixlib::ShellOut.new("git --git-dir=#{Ronin::Config[:
|
21
|
+
def branch(artifact)
|
22
|
+
@cmd = Mixlib::ShellOut.new("git --git-dir=#{Ronin::Config[:artifact_path]}/#{artifact}/.git --work-tree=#{Ronin::Config[:artifact_path]}/#{artifact}/ branch")
|
23
23
|
@cmd.run_command
|
24
24
|
@branch = @cmd.stdout.chomp.split(' ')[1]
|
25
25
|
@branch
|
26
26
|
end
|
27
27
|
module_function :branch
|
28
28
|
|
29
|
-
def pull_and_report_updated(
|
30
|
-
@cmd = Mixlib::ShellOut.new("git --git-dir=#{Ronin::Config[:
|
29
|
+
def pull_and_report_updated(artifact)
|
30
|
+
@cmd = Mixlib::ShellOut.new("git --git-dir=#{Ronin::Config[:artifact_path]}/#{artifact}/.git --work-tree=#{Ronin::Config[:artifact_path]}/#{artifact}/ pull")
|
31
31
|
@cmd.run_command
|
32
32
|
@updated = @cmd.stdout.include?("Updating")
|
33
33
|
@updated ? true : false
|
34
34
|
end
|
35
35
|
module_function :pull_and_report_updated
|
36
36
|
|
37
|
-
def clone(
|
38
|
-
@cmd = Mixlib::ShellOut.new("git clone #{
|
37
|
+
def clone(artifact_data)
|
38
|
+
@cmd = Mixlib::ShellOut.new("git clone #{artifact_data[:repo]} #{Ronin::Config[:artifact_path]}/#{artifact_data[:name]}/ -b #{artifact_data[:branch]}")
|
39
39
|
@cmd.run_command
|
40
40
|
@cmd.stdout
|
41
41
|
end
|
data/lib/ronin/puppet.rb
CHANGED
@@ -20,8 +20,8 @@ require 'ronin/log'
|
|
20
20
|
module Ronin
|
21
21
|
module Puppet
|
22
22
|
|
23
|
-
@run_list = "#{Ronin::Config[:
|
24
|
-
@modules = Ronin::RunList.new.
|
23
|
+
@run_list = "#{Ronin::Config[:artifact_path]}/ronin.pp"
|
24
|
+
@modules = Ronin::RunList.new.artifacts
|
25
25
|
|
26
26
|
def create_run_list
|
27
27
|
Ronin::Log.info("Building Puppet run list at #{@run_list}.")
|
@@ -36,8 +36,8 @@ module Ronin
|
|
36
36
|
|
37
37
|
def run
|
38
38
|
self.create_run_list
|
39
|
-
Ronin::Log.info("Running Puppet, logging
|
40
|
-
@cmd = Mixlib::ShellOut.new("puppet apply --verbose --ordering manifest --logdest #{Ronin::Config[:log_path]}/ronin-puppet.log --modulepath #{Ronin::Config[:
|
39
|
+
Ronin::Log.info("Running Puppet, logging to #{Ronin::Config[:log_path]}/ronin-puppet.log.")
|
40
|
+
@cmd = Mixlib::ShellOut.new("puppet apply --verbose --ordering manifest --logdest #{Ronin::Config[:log_path]}/ronin-puppet.log --modulepath #{Ronin::Config[:artifact_path]} #{@run_list}")
|
41
41
|
@cmd.run_command
|
42
42
|
self.clean_up
|
43
43
|
end
|
data/lib/ronin/ronin.rb
CHANGED
@@ -14,28 +14,25 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
$LOAD_PATH << "."
|
17
|
-
require 'ronin/
|
17
|
+
require 'ronin/artifact_runner'
|
18
18
|
require 'ronin/run_list'
|
19
19
|
require 'ronin/config'
|
20
20
|
|
21
21
|
module Ronin
|
22
22
|
def run
|
23
23
|
|
24
|
-
unless Process.uid == 0
|
25
|
-
puts 'You need to be root to perform this command.'
|
26
|
-
exit 1
|
27
|
-
end
|
28
|
-
|
29
24
|
Ronin::Log.level = Ronin::Config[:log_level]
|
30
25
|
|
31
|
-
|
26
|
+
puts Ronin::Config[:interpreter].inspect
|
27
|
+
|
28
|
+
@r = Ronin::ArtifactRunner.new
|
32
29
|
@changes = @r.download_and_report_changes
|
33
30
|
@r.purge_unused
|
34
31
|
|
35
32
|
if @changes
|
36
|
-
if Ronin::Config[:interpreter]
|
33
|
+
if Ronin::Config[:interpreter] == :puppet
|
37
34
|
Ronin::Puppet.run
|
38
|
-
elsif Ronin::Config[:interpreter]
|
35
|
+
elsif Ronin::Config[:interpreter] == :chef
|
39
36
|
Ronin::Chef.run
|
40
37
|
end
|
41
38
|
end
|
data/lib/ronin/run_list.rb
CHANGED
@@ -23,7 +23,7 @@ module Ronin
|
|
23
23
|
def initialize
|
24
24
|
@run_list = {}
|
25
25
|
if Ronin::Config['run_list_type'] = :yaml
|
26
|
-
@modules_raw = YAML.load_file(Ronin::Config['run_list_file'])['
|
26
|
+
@modules_raw = YAML.load_file(Ronin::Config['run_list_file'])['artifacts']
|
27
27
|
end
|
28
28
|
|
29
29
|
@modules_raw.each do |m|
|
@@ -43,7 +43,7 @@ module Ronin
|
|
43
43
|
@run_list
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
46
|
+
def artifacts
|
47
47
|
@mods = []
|
48
48
|
@run_list.each { |k,v| @mods << k }
|
49
49
|
@mods
|
data/lib/ronin/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Milford
|
@@ -96,7 +96,7 @@ files:
|
|
96
96
|
- lib/ronin/chef.rb
|
97
97
|
- lib/ronin/git.rb
|
98
98
|
- lib/ronin/log.rb
|
99
|
-
- lib/ronin/
|
99
|
+
- lib/ronin/artifact_runner.rb
|
100
100
|
- lib/ronin/run_list.rb
|
101
101
|
- lib/ronin/version.rb
|
102
102
|
- README.md
|