spaux 0.0.2 → 0.0.3

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: 8c2a52a8929cfd462d77814d9b080ca8e282d740
4
- data.tar.gz: 5594916e7f5c25b2e54d92dd885a67cc0aa4d14a
3
+ metadata.gz: 4ca6cdb0701d57bb9e1e6757409f445751a7be00
4
+ data.tar.gz: ebc351a25943fb1ac5a927d6ef349404dd9eb3cf
5
5
  SHA512:
6
- metadata.gz: c310e8a8abe5b70067a267b53c90f3105d32bdde096cb8c6dc788b677b0b1ec95c55558416b5028c828c7421a1abe47b638d7d1cccd4a3d5b12f8c079be2a662
7
- data.tar.gz: 923c4039a0bbd5f4f0c40840495225e08114830130e4ebdea52a9d71edbf5ad4ec417f58f7afb336c01e8cdc51abfe29d2a633919807c8c77b2895d61bb33411
6
+ metadata.gz: 49a94afda451ae1327d989492ccf24f26e8b7edd2798f2f6e97b13332b0688f02f260ac4089f8678a705866a22597871237a761312cbd7045b2b924a1de12b86
7
+ data.tar.gz: c01509c2736bd400bb0c878f967b67468ebac7995ca09f3419232bfa0f1c4b335c2eb0dba58d2cea3da37dc156e2250e01782e3815513441f5fe16526f053c68
@@ -0,0 +1,2 @@
1
+ current_dir = File.dirname(__FILE__)
2
+ cookbook_path [current_dir]
@@ -51,6 +51,14 @@ class Spaux
51
51
  argv = []
52
52
  super
53
53
  end
54
+
55
+ def run_application
56
+ begin
57
+ super
58
+ rescue SystemExit => e
59
+ # just ignore chef-client exit
60
+ end
61
+ end
54
62
  end
55
63
  end
56
64
  end
@@ -0,0 +1,52 @@
1
+ require 'chef/application/knife'
2
+ require 'fileutils'
3
+ require 'spaux/chef/knife_monkey_patches'
4
+
5
+ class Spaux
6
+ class Chef
7
+ class Knife < ::Chef::Application::Knife
8
+
9
+ DEFAULT_KNIFE_CONFIG = {
10
+ config_file: {
11
+ flags: %w(--config -c),
12
+ value: ::File.join('@work_dir', 'knife.rb')
13
+ }
14
+ }
15
+
16
+ attr_accessor :work_dir
17
+ attr_accessor :args
18
+
19
+ def initialize(work_dir, args)
20
+ @work_dir = work_dir
21
+ @args = args
22
+
23
+ DEFAULT_KNIFE_CONFIG.each do |_,v|
24
+ v[:value].is_a?(String) && v[:value].gsub!(/@work_dir/, @work_dir)
25
+ end
26
+
27
+ cf_flags = DEFAULT_KNIFE_CONFIG[:config_file][:flags]
28
+ unless @args.include?(cf_flags.first) || @args.include?(cf_flags.last)
29
+ @args << DEFAULT_KNIFE_CONFIG[:config_file][:flags].first
30
+ @args << DEFAULT_KNIFE_CONFIG[:config_file][:value]
31
+ end
32
+
33
+ config_file = DEFAULT_KNIFE_CONFIG[:config_file][:value]
34
+ FileUtils.touch config_file
35
+ end
36
+
37
+ def run
38
+ Mixlib::Log::Formatter.show_time = false
39
+ quiet_traps
40
+ # I'm not sure why I have to do this if this class is child
41
+ # of Chef::Application::Knife, so options should be set already
42
+ knife = ::Chef::Application::Knife.new
43
+ options = knife.options
44
+ begin
45
+ ::Chef::Knife.run(@args, options)
46
+ rescue SystemExit => e
47
+ # just ignore the exit of knife tool
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,27 @@
1
+ class Chef
2
+ class Knife
3
+ def configure_spaux
4
+ config.merge!(Spaux::default_knife_config)
5
+ end
6
+ def self.run(args, options={})
7
+ # Fallback debug logging. Normally the logger isn't configured until we
8
+ # read the config, but this means any logging that happens before the
9
+ # config file is read may be lost. If the KNIFE_DEBUG variable is set, we
10
+ # setup the logger for debug logging to stderr immediately to catch info
11
+ # from early in the setup process.
12
+ if ENV['KNIFE_DEBUG']
13
+ Chef::Log.init($stderr)
14
+ Chef::Log.level(:debug)
15
+ end
16
+
17
+ load_commands
18
+ subcommand_class = subcommand_class_from(args)
19
+ subcommand_class.options = options.merge!(subcommand_class.options)
20
+ subcommand_class.load_deps
21
+ instance = subcommand_class.new(args)
22
+ instance.configure_spaux
23
+ instance.configure_chef
24
+ instance.run_with_pretty_exceptions
25
+ end
26
+ end
27
+ end
data/lib/spaux/cli.rb CHANGED
@@ -35,22 +35,31 @@ class Spaux
35
35
  ::File.write(options[:file], key)
36
36
  end
37
37
  end
38
+ desc 'knife', 'Run Chef knife in Spaux context'
39
+ option :dir, :desc => 'Working directory', :banner => 'DIRECTORY'
40
+ option :current, :type => :boolean, :default => true,
41
+ :desc => 'Create and/or use a working directory in the current directory'
42
+ def knife(*args)
43
+ work_dir = get_work_dir(options)
44
+ knife = Spaux::Chef::Knife.new(work_dir, args)
45
+ knife.run
46
+ end
38
47
 
39
- # private
40
- # def get_work_dir(options)
41
- # dir = options[:dir]
42
- # current = options[:current]
43
- # if !dir
44
- # work_dir = if ENV['SPAUX_HOME']
45
- # ENV['SPAUX_HOME']
46
- # elsif current
47
- # ::File.join(ENV['PWD'], 'current')
48
- # else
49
- # Dir.mktmpdir
50
- # end
51
- # else
52
- # work_dir = dir
53
- # end
54
- # end
48
+ private
49
+ def get_work_dir(options)
50
+ dir = options[:dir]
51
+ current = options[:current]
52
+ if !dir
53
+ work_dir = if ENV['SPAUX_HOME']
54
+ ENV['SPAUX_HOME']
55
+ elsif current
56
+ ::File.join(ENV['PWD'], 'current')
57
+ else
58
+ Dir.mktmpdir
59
+ end
60
+ else
61
+ work_dir = dir
62
+ end
63
+ end
55
64
  end
56
65
  end
@@ -0,0 +1,6 @@
1
+ current_dir = File.dirname(__FILE__)
2
+ node_name "spaux"
3
+ client_key ::File.join(current_dir, 'spaux.pem')
4
+ chef_server_url "https://api.opscode.com/organizations/spaux"
5
+ cookbook_path [current_dir]
6
+ ssl_verify_mode :verify_peer
data/lib/spaux/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Spaux
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/spaux.rb CHANGED
@@ -1,6 +1,13 @@
1
1
  require 'spaux/version'
2
2
  require 'spaux/cli'
3
3
  require 'spaux/chef/client'
4
+ require 'spaux/chef/knife'
4
5
 
5
6
  class Spaux
7
+ def self.default_knife_config
8
+ lib_dir = ::File.expand_path(::File::join(__FILE__, '..'))
9
+ knife_rb = ::File::join(lib_dir, 'spaux', 'defaults', 'knife.rb')
10
+ ::Chef::Config.from_string(::File.read(knife_rb), knife_rb)
11
+ ::Chef::Config.configuration
12
+ end
6
13
  end
data/spec/spaux_spec.rb CHANGED
@@ -19,11 +19,16 @@ describe Spaux::Chef::Client do
19
19
  end
20
20
 
21
21
  #describe Spaux::Chef::Key
22
+ #describe Spaux::Chef::Knife
22
23
 
23
24
  describe Spaux::CLI do
24
25
  describe '#converge' do
25
- xit 'prints "chef client" in stdout' do
26
- expect { Spaux::CLI.new.converge }.to output(/Starting Chef Client/).to_stdout
26
+ it 'prints "chef client" in stdout' do
27
+ begin
28
+ spaux = Spaux::CLI.new
29
+ rescue SystemExit
30
+ expect { spaux.converge }.to output(/Starting Chef Client/).to_stdout
31
+ end
27
32
  end
28
33
  end
29
34
  describe '#savekey' do
@@ -31,4 +36,13 @@ describe Spaux::CLI do
31
36
  expect { Spaux::CLI.new.savekey }.to output(/^-----BEGIN RSA PRIVATE KEY-----/).to_stdout
32
37
  end
33
38
  end
39
+ describe '#knife' do
40
+ it 'prints expect knife output in stdout' do
41
+ begin
42
+ spaux = Spaux::CLI.new
43
+ rescue SystemExit
44
+ expect { spaux.knife("help", "list") }.to output(/help topics/).to_stdout
45
+ end
46
+ end
47
+ end
34
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spaux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Landaeta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-16 00:00:00.000000000 Z
11
+ date: 2014-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -180,11 +180,15 @@ files:
180
180
  - bin/spaux
181
181
  - examples/attributes.json
182
182
  - examples/knife.rb
183
+ - examples/knife_minimal.rb
183
184
  - lib/spaux.rb
184
185
  - lib/spaux/chef/client.rb
185
186
  - lib/spaux/chef/key.rb
187
+ - lib/spaux/chef/knife.rb
188
+ - lib/spaux/chef/knife_monkey_patches.rb
186
189
  - lib/spaux/chef/monkey_patches.rb
187
190
  - lib/spaux/cli.rb
191
+ - lib/spaux/defaults/knife.rb
188
192
  - lib/spaux/version.rb
189
193
  - spaux.gemspec
190
194
  - spec/spaux_spec.rb