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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbba7faf4124e6faf33232719132c7d3ee2f0aa9
4
- data.tar.gz: 7ff5f5f4fd2095a528624d8e3ec555a85f658a36
3
+ metadata.gz: 2c3c00f54efdb0caece795e59b3647d555f25ea3
4
+ data.tar.gz: 8cb9cae2f49b2bc0453e32fefdc5f649f34dac24
5
5
  SHA512:
6
- metadata.gz: de8637c2dd77b9b9f3e20a13360ac4fbbc709a164945de83eab5d81167a29d0530e8eedf5b578ae01948371269260c21a68d79e27f40fa890ad605d343e5f768
7
- data.tar.gz: 01933a1e37887cffa3ccd6d34d0f6d0c2781136118d5508d901ecf2813a158e4b2fdaa3edf9e9e8e40110076ea95001e77d0e59b85493d3c06cebda2f5641a15
6
+ metadata.gz: 2f1fb190ffc1853a1341fcc19741b563898e82691c493b3c222d5713e9e3bece065c7d04204fc9212d6719ae43a512f6eff06ae5c8cdc19ed8d31f32221f5cc1
7
+ data.tar.gz: 7e4bcdf75d4b40262809e7958a2f7a0fc7e10bdd37d44cd3b24ba47b8bd57d1c4ae700d43278d89d3db293c43192d47789633762f7aa3532e2c2967cae15bb03
data/bin/ronin CHANGED
@@ -16,4 +16,9 @@
16
16
  # limitations under the License.
17
17
  require 'ronin'
18
18
 
19
- Ronin.run
19
+ unless Process.uid == 0
20
+ puts 'You need to be root to perform this command.'
21
+ exit 1
22
+ end
23
+
24
+ Ronin.run
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/module_runner'
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 ModuleRunner
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[:module_path]}/#{item[:name]}")
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[:module_path]}/#{item[:name]}/")
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[:module_path]}.")
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
- @local_modules = Dir.entries(Ronin::Config[:module_path]).select { |dir| File.directory?("#{Ronin::Config[:module_path]}/#{dir}") and !(dir =='.' || dir == '..') }
61
- @modules = @run_list.modules
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
- @local_modules.each do |mod|
64
- unless @modules.include?(mod)
65
- Ronin::Log.info("No module named #{mod} in run list, but it exists in #{Ronin::Config[:module_path]}. Purging it.")
66
- FileUtils.rm_rf("#{Ronin::Config[:module_path]}/#{mod}/")
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
- # tbd
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/modules.yaml'
37
- default :module_path, '/var/lib/modules'
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(mod)
22
- @cmd = Mixlib::ShellOut.new("git --git-dir=#{Ronin::Config[:module_path]}/#{mod}/.git --work-tree=#{Ronin::Config[:module_path]}/#{mod}/ branch")
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(mod)
30
- @cmd = Mixlib::ShellOut.new("git --git-dir=#{Ronin::Config[:module_path]}/#{mod}/.git --work-tree=#{Ronin::Config[:module_path]}/#{mod}/ pull")
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(mod_data)
38
- @cmd = Mixlib::ShellOut.new("git clone #{mod_data[:repo]} #{Ronin::Config[:module_path]}/#{mod_data[:name]}/ -b #{mod_data[:branch]}")
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[:module_path]}/ronin.pp"
24
- @modules = Ronin::RunList.new.modules
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 puppet output 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[:module_path]} #{@run_list}")
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/module_runner'
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
- @r = Ronin::ModuleRunner.new
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] = :puppet
33
+ if Ronin::Config[:interpreter] == :puppet
37
34
  Ronin::Puppet.run
38
- elsif Ronin::Config[:interpreter] = :chef
35
+ elsif Ronin::Config[:interpreter] == :chef
39
36
  Ronin::Chef.run
40
37
  end
41
38
  end
@@ -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'])['modules']
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 modules
46
+ def artifacts
47
47
  @mods = []
48
48
  @run_list.each { |k,v| @mods << k }
49
49
  @mods
data/lib/ronin/version.rb CHANGED
@@ -14,5 +14,5 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
  module Ronin
17
- VERSION = '0.0.8'
17
+ VERSION = '0.0.9'
18
18
  end
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.8
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/module_runner.rb
99
+ - lib/ronin/artifact_runner.rb
100
100
  - lib/ronin/run_list.rb
101
101
  - lib/ronin/version.rb
102
102
  - README.md