spaux 0.0.2 → 0.0.3
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/examples/knife_minimal.rb +2 -0
- data/lib/spaux/chef/client.rb +8 -0
- data/lib/spaux/chef/knife.rb +52 -0
- data/lib/spaux/chef/knife_monkey_patches.rb +27 -0
- data/lib/spaux/cli.rb +25 -16
- data/lib/spaux/defaults/knife.rb +6 -0
- data/lib/spaux/version.rb +1 -1
- data/lib/spaux.rb +7 -0
- data/spec/spaux_spec.rb +16 -2
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ca6cdb0701d57bb9e1e6757409f445751a7be00
|
4
|
+
data.tar.gz: ebc351a25943fb1ac5a927d6ef349404dd9eb3cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49a94afda451ae1327d989492ccf24f26e8b7edd2798f2f6e97b13332b0688f02f260ac4089f8678a705866a22597871237a761312cbd7045b2b924a1de12b86
|
7
|
+
data.tar.gz: c01509c2736bd400bb0c878f967b67468ebac7995ca09f3419232bfa0f1c4b335c2eb0dba58d2cea3da37dc156e2250e01782e3815513441f5fe16526f053c68
|
data/lib/spaux/chef/client.rb
CHANGED
@@ -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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
data/lib/spaux/version.rb
CHANGED
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
|
-
|
26
|
-
|
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.
|
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-
|
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
|