spaux 0.0.8 → 0.0.9
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/attributes2.json +30 -0
- data/examples/chef.rb +4 -0
- data/examples/spaux.rb +1 -0
- data/lib/spaux/chef/client.rb +12 -4
- data/lib/spaux/chef/key.rb +1 -3
- data/lib/spaux/chef/monkey_patches/client.rb +0 -15
- data/lib/spaux/cli/ssh_subcommand.rb +52 -0
- data/lib/spaux/cli.rb +28 -3
- data/lib/spaux/version.rb +1 -1
- data/spec/spaux_spec.rb +1 -0
- 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: 466f15ee386ce8a4828c78c2ddd79d237abba028
|
4
|
+
data.tar.gz: 33f63a81f23e5b16a956be021578a8cf104d044a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 490e90f25221c3c7e3d36527ecc7a92b542253912aafa2958d09fab7a4d568f326032101f00fb9c83387e4ec890257bec5888c6fb4a49c4c92a8f2258ac8f0df
|
7
|
+
data.tar.gz: c73694ab180b60e7f51f367e3004b4057345aafc5500471e2ec721810d4d830d8ec73b5d89086f2654fb9e7825914719a3d767390419227c254bae4a1bd754eb
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"spaux":{
|
3
|
+
"machine":{
|
4
|
+
"action":"converge",
|
5
|
+
"key_name":"fancy",
|
6
|
+
"name":"shangrila",
|
7
|
+
"runlist":[
|
8
|
+
"ufw",
|
9
|
+
"hostname",
|
10
|
+
"apt",
|
11
|
+
"git",
|
12
|
+
"users::sysadmins",
|
13
|
+
"sudo"
|
14
|
+
]
|
15
|
+
},
|
16
|
+
"digital_ocean":{
|
17
|
+
"bootstrap_options":{
|
18
|
+
"flavor_name":"512MB"
|
19
|
+
}
|
20
|
+
},
|
21
|
+
"conf_mgmt":{
|
22
|
+
"chef":{
|
23
|
+
"endpoint":"https://api.qirtaiba.org/organizations/xanadu",
|
24
|
+
"options":{
|
25
|
+
"client_name":"xanadu"
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
data/examples/chef.rb
ADDED
data/examples/spaux.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{:chef_private_key_gist_id =>"513395c90bfe499fdc55"}
|
data/lib/spaux/chef/client.rb
CHANGED
@@ -19,12 +19,11 @@ class Spaux
|
|
19
19
|
@config.merge! default_chef_config.merge(chef_config)
|
20
20
|
|
21
21
|
default_spaux_config = Spaux::default_spaux_config
|
22
|
-
|
23
22
|
@spaux_config = default_spaux_config.merge(spaux_config)
|
24
|
-
#if !@spaux_config.eql?(default_spaux_config)
|
25
|
-
#trigger a reevalutation of the private key
|
26
23
|
|
27
|
-
@config[:raw_key] = Spaux::Chef::
|
24
|
+
@config[:raw_key] = Spaux::Chef::Key.new(@spaux_config).raw_key
|
25
|
+
# ugly hack but better than another options...
|
26
|
+
redefine_chef_http_authenticator @config[:raw_key]
|
28
27
|
|
29
28
|
FileUtils.touch @config[:config_file]
|
30
29
|
FileUtils.touch @config[:client_key]
|
@@ -51,6 +50,15 @@ class Spaux
|
|
51
50
|
# just ignore chef-client exit
|
52
51
|
end
|
53
52
|
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def redefine_chef_http_authenticator(key)
|
56
|
+
::Chef::HTTP::Authenticator.send(:define_method,
|
57
|
+
'load_signing_key') do |signing_key_filename, raw_key|
|
58
|
+
@raw_key = key
|
59
|
+
@key = OpenSSL::PKey::RSA.new(@raw_key)
|
60
|
+
end
|
61
|
+
end
|
54
62
|
end
|
55
63
|
end
|
56
64
|
end
|
data/lib/spaux/chef/key.rb
CHANGED
@@ -10,7 +10,7 @@ class Spaux
|
|
10
10
|
|
11
11
|
def initialize(config={})
|
12
12
|
@work_dir = ::File.join(ENV['PWD'], 'current')
|
13
|
-
@config =
|
13
|
+
@config = default_spaux_config.merge(config)
|
14
14
|
@raw_key ||= get_raw_key
|
15
15
|
end
|
16
16
|
|
@@ -64,5 +64,3 @@ class Spaux
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
68
|
-
Spaux::Chef::RawKey = Spaux::Chef::Key.new.raw_key
|
@@ -1,21 +1,6 @@
|
|
1
1
|
require 'chef'
|
2
2
|
require 'chef/application/client'
|
3
3
|
|
4
|
-
class Chef
|
5
|
-
class HTTP
|
6
|
-
class Authenticator
|
7
|
-
def load_signing_key(key_file, raw_key = nil)
|
8
|
-
@raw_key = Spaux::Chef::RawKey
|
9
|
-
@key = OpenSSL::PKey::RSA.new(@raw_key)
|
10
|
-
rescue OpenSSL::PKey::RSAError
|
11
|
-
msg = "The file #{key_file} or :raw_key option does not contain a correctly formatted private key.\n"
|
12
|
-
msg << "The key file should begin with '-----BEGIN RSA PRIVATE KEY-----' and end with '-----END RSA PRIVATE KEY-----'"
|
13
|
-
raise Chef::Exceptions::InvalidPrivateKey, msg
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
4
|
class ChefVault
|
20
5
|
class Item < Chef::DataBagItem
|
21
6
|
def secret
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'chef/http/authenticator'
|
3
|
+
require 'pry'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
class Spaux
|
7
|
+
class CLI < Thor
|
8
|
+
class SSHSubcommand
|
9
|
+
def initialize(*args)
|
10
|
+
chef_config = args.shift || {}
|
11
|
+
spaux_config = args.shift || {}
|
12
|
+
|
13
|
+
default_chef_config = Spaux::default_chef_config(:client)
|
14
|
+
@config = {}
|
15
|
+
@config.merge! default_chef_config.merge(chef_config)
|
16
|
+
|
17
|
+
default_spaux_config = Spaux::default_spaux_config
|
18
|
+
@spaux_config = default_spaux_config.merge(spaux_config)
|
19
|
+
|
20
|
+
@config[:raw_key] = Spaux::Chef::Key.new(@spaux_config).raw_key
|
21
|
+
redefine_chef_http_authenticator @config[:raw_key]
|
22
|
+
end
|
23
|
+
|
24
|
+
def run(nodename, options={})
|
25
|
+
begin
|
26
|
+
node = ::Chef::Node.load(nodename)
|
27
|
+
rescue Net::HTTPServerException => e
|
28
|
+
not_found_msg = nodename + ' node could not be found in the server'
|
29
|
+
STDERR.puts not_found_msg if e.response.code.eql?('404')
|
30
|
+
end
|
31
|
+
node_ipaddress = node[:ipaddress]
|
32
|
+
node_rsa_public_key = node[:keys][:ssh][:host_rsa_public]
|
33
|
+
# write a gem to do this instead of shelling out
|
34
|
+
node_key = `ssh-keyscan -H #{node_ipaddress} 2>/dev/null`
|
35
|
+
tmp_known_hosts_file = Tempfile.new('tmp_known_hosts_file')
|
36
|
+
tmp_known_hosts_file.write(node_key)
|
37
|
+
tmp_known_hosts_file.flush
|
38
|
+
ssh_cmd = "ssh -o UserKnownHostsFile="
|
39
|
+
exec(ssh_cmd + "#{tmp_known_hosts_file.path} #{node_ipaddress}")
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def redefine_chef_http_authenticator(key)
|
44
|
+
::Chef::HTTP::Authenticator.send(:define_method,
|
45
|
+
'load_signing_key') do |signing_key_filename, raw_key|
|
46
|
+
@raw_key = key
|
47
|
+
@key = OpenSSL::PKey::RSA.new(@raw_key)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/spaux/cli.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'spaux'
|
3
|
+
require 'spaux/cli/ssh_subcommand'
|
3
4
|
require 'tmpdir'
|
4
5
|
require 'fileutils'
|
5
6
|
|
@@ -9,17 +10,28 @@ class Spaux
|
|
9
10
|
option :dir, :desc => 'Working directory', :banner => 'DIRECTORY'
|
10
11
|
option :current, :type => :boolean, :default => true,
|
11
12
|
:desc => 'Create and/or use a working directory in the current directory'
|
13
|
+
option :config, :desc => 'Configuration file to use with chef-client',
|
14
|
+
:aliases => :c
|
15
|
+
option :spaux_config, :desc => 'Configuration file to use with spaux',
|
16
|
+
:aliases => :s
|
12
17
|
def converge
|
13
18
|
work_dir = get_work_dir(options)
|
14
19
|
FileUtils.mkdir_p work_dir
|
15
20
|
|
16
|
-
|
17
|
-
|
21
|
+
begin
|
22
|
+
chef_config = parse_config_file(options[:config]) if options[:config]
|
23
|
+
spaux_config = parse_config_file(options[:spaux_config]) if options[:spaux_config]
|
24
|
+
client = Spaux::Chef::Client.new(work_dir, chef_config, spaux_config)
|
25
|
+
client.run
|
26
|
+
rescue Errno::ENOENT => e
|
27
|
+
ssh_message = 'error: You need to create a ssh keypair'
|
28
|
+
STDERR.puts ssh_message if e.message.match(/id_rsa/)
|
29
|
+
end
|
18
30
|
end
|
19
31
|
desc 'savekey', 'Show/save private chef key'
|
20
32
|
option :file, :type => :string
|
21
33
|
def savekey
|
22
|
-
key = Spaux::Chef::
|
34
|
+
key = Spaux::Chef::Key.new.raw_key
|
23
35
|
if !options[:file]
|
24
36
|
puts key
|
25
37
|
else
|
@@ -35,6 +47,11 @@ class Spaux
|
|
35
47
|
knife = Spaux::Chef::Knife.new(work_dir, args)
|
36
48
|
knife.run
|
37
49
|
end
|
50
|
+
desc 'ssh', 'Connect via ssh to a node'
|
51
|
+
def ssh(nodename)
|
52
|
+
ssh_cmd = Spaux::CLI::SSHSubcommand.new
|
53
|
+
ssh_cmd.run(nodename, options)
|
54
|
+
end
|
38
55
|
|
39
56
|
private
|
40
57
|
def get_work_dir(options)
|
@@ -52,5 +69,13 @@ class Spaux
|
|
52
69
|
work_dir = dir
|
53
70
|
end
|
54
71
|
end
|
72
|
+
def parse_config_file(file)
|
73
|
+
begin
|
74
|
+
eval(IO.read(file))
|
75
|
+
rescue Errno::ENOENT => e
|
76
|
+
puts e.message
|
77
|
+
{}
|
78
|
+
end
|
79
|
+
end
|
55
80
|
end
|
56
81
|
end
|
data/lib/spaux/version.rb
CHANGED
data/spec/spaux_spec.rb
CHANGED
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.9
|
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
|
+
date: 2014-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -179,8 +179,11 @@ files:
|
|
179
179
|
- Rakefile
|
180
180
|
- bin/spaux
|
181
181
|
- examples/attributes.json
|
182
|
+
- examples/attributes2.json
|
183
|
+
- examples/chef.rb
|
182
184
|
- examples/knife.rb
|
183
185
|
- examples/knife_minimal.rb
|
186
|
+
- examples/spaux.rb
|
184
187
|
- lib/spaux.rb
|
185
188
|
- lib/spaux/chef/client.rb
|
186
189
|
- lib/spaux/chef/default/client.rb
|
@@ -190,6 +193,7 @@ files:
|
|
190
193
|
- lib/spaux/chef/monkey_patches/client.rb
|
191
194
|
- lib/spaux/chef/monkey_patches/knife.rb
|
192
195
|
- lib/spaux/cli.rb
|
196
|
+
- lib/spaux/cli/ssh_subcommand.rb
|
193
197
|
- lib/spaux/config.rb
|
194
198
|
- lib/spaux/version.rb
|
195
199
|
- spaux.gemspec
|