spaux 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6c50308cb66f6b1d4cfd64255d28a288fcc76719
4
+ data.tar.gz: 9c9c2e3a42e4319be7db0bfa484f36419d625d8f
5
+ SHA512:
6
+ metadata.gz: 73a2d181a03ca651502f506b38fd5023b55ea34226b1018c80bbcfdc2515d1162fa03b35b8b5a25e30303cfb989f5f06191a1c00c4f9ef952bcea91ec5c051c9
7
+ data.tar.gz: a3f2a933510fd6a7252e286c441bddfc854e5a22b371d5b08accd5e9b69e9231d223a6ee63f546e9c3cd16b24be272b91c463281d4592191acdd0d04119628e7
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ current/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spaux.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Miguel Landaeta
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Spaux
2
+
3
+ This is yet another Ruby gem to automate some Chef and cloud computing tasks.
4
+
5
+ I was not satisfied with some programmatic features from Opscode code so I went ahead and wrote my own gem.
6
+
7
+ What I'm aiming for is to centralize credentials (API, SSL keys, etc) in the Chef server (e.g. encrypted data bags or chef-vault), store cloud providers settings there as well (plain data bags and attributes) and have a very very simple CLI to launch new environments.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'spaux'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install spaux
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here. Open an issue with questions if you are insterested, I'm still organizing this.
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/[my-github-username]/spaux/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
data/bin/spaux ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
4
+ require 'spaux/cli'
5
+
6
+ Spaux::CLI.start(ARGV)
@@ -0,0 +1,31 @@
1
+ {
2
+ "action":"converge",
3
+ "spaux":{
4
+ "name":"xanadu",
5
+ "digital_ocean":{
6
+ "bootstrap_options":{
7
+ "flavor_name":"512MB"
8
+ }
9
+ },
10
+ "machine":{
11
+ "with_rvm":false,
12
+ "runlist":[
13
+ "apt",
14
+ "hostname",
15
+ "git",
16
+ "ufw",
17
+ "users::sysadmins",
18
+ "sudo"
19
+ ],
20
+ "attributes":{
21
+ "firewall":{
22
+ "rules":[
23
+ {"http":{"port":"80"}},
24
+ {"https":{"port":"443"}}
25
+ ]
26
+ }
27
+ }
28
+ }
29
+ },
30
+ "override_key_name":"fancy"
31
+ }
@@ -0,0 +1,56 @@
1
+ require 'spaux/chef/key'
2
+ require 'spaux/chef/monkey_patches'
3
+
4
+ class Spaux
5
+ class Chef
6
+ class Client < ::Chef::Application::Client
7
+ attr_accessor :work_dir
8
+ attr_accessor :spaux_config
9
+
10
+ DEFAULT_CHEF_CONFIG = {
11
+ config_file: ::File.join('@work_dir', 'client.rb'),
12
+ cache_path: ::File.join('@work_dir', '.chef'),
13
+ client_key: ::File.join('@work_dir', 'client.pem'),
14
+ json_attribs: ::File.join('@work_dir', 'attributes.json'),
15
+ chef_server_url: 'https://api.opscode.com/organizations/spaux',
16
+ ssl_verify_mode: :verify_peer,
17
+ node_name: 'spaux',
18
+ override_runlist: ["recipe[spaux::machine]"]
19
+ }
20
+
21
+ def initialize(work_dir, *args)
22
+ @work_dir = work_dir
23
+ chef_config = args.shift || {}
24
+ spaux_config = args.shift || {}
25
+ super()
26
+
27
+ DEFAULT_CHEF_CONFIG.each { |_,v| v.is_a?(String) && v.gsub!(/@work_dir/, @work_dir) }
28
+ @config.merge! DEFAULT_CHEF_CONFIG.merge(chef_config)
29
+
30
+ default_spaux_config = Spaux::Chef::Key::DEFAULT_SPAUX_CONFIG
31
+ @spaux_config = default_spaux_config.merge(spaux_config)
32
+ #if !@spaux_config.eql?(default_spaux_config)
33
+ #trigger a reevalutation of the private key
34
+
35
+ @config[:raw_key] = Spaux::Chef::RawKey
36
+
37
+ FileUtils.touch @config[:config_file]
38
+ FileUtils.touch @config[:client_key]
39
+ unless chef_config[:json_attribs]
40
+ @config.delete(:json_attribs) if !::File.exists?(@config[:json_attribs])
41
+ end
42
+ ENV['SPAUX_HOME'] = @work_dir
43
+ end
44
+
45
+ def reconfigure
46
+ super
47
+ ::Chef::Config[:specific_recipes] = []
48
+ end
49
+
50
+ def parse_options(argv=ARGV)
51
+ argv = []
52
+ super
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,69 @@
1
+ require 'octokit'
2
+ require 'net/ssh'
3
+
4
+ class Spaux
5
+ class Chef
6
+ class Key
7
+ attr_accessor :work_dir
8
+ attr_accessor :raw_key
9
+ attr_accessor :config
10
+
11
+ DEFAULT_SPAUX_CONFIG = {
12
+ chef_private_key_gist_id: '16b65a73953427ce9c40',
13
+ private_key: '~/.ssh/id_rsa',
14
+ aes_key_size: 256,
15
+ aes_cipher_mode: :CBC
16
+ }
17
+
18
+ def initialize(config={})
19
+ @work_dir = ::File.join(ENV['PWD'], 'current')
20
+ @config = config.merge(DEFAULT_SPAUX_CONFIG)
21
+ @raw_key ||= get_raw_key
22
+ end
23
+
24
+ private
25
+ def get_raw_key
26
+ key_filename = 'encrypted.rb'
27
+ key_file = ::File.join(@work_dir, key_filename)
28
+
29
+ if !::File.exists?(key_file)
30
+ key = retrieve_key_from_gist(@config[:chef_private_key_gist_id])
31
+ begin
32
+ ::File.write(key_file, key)
33
+ rescue Exception => e
34
+ puts e.message
35
+ end
36
+ else
37
+ key = ::File.read(key_file)
38
+ end
39
+
40
+ key_hash = eval(key)
41
+ raw_key = decrypt_key(key_hash, @config[:private_key])
42
+ end
43
+
44
+ def retrieve_key_from_gist(gist)
45
+ client = Octokit::Client.new
46
+ key_gist = client.gist(gist)
47
+ key_filename = key_gist[:files].fields.first
48
+ key_resource = key_gist[:files][key_filename]
49
+ key_data = key_resource[:content]
50
+ end
51
+
52
+ def decrypt_key(key_data, rsa_key_filename)
53
+ rsa_key = Net::SSH::KeyFactory.load_private_key(rsa_key_filename)
54
+ iv = Base64.decode64(key_data[:iv])
55
+ sym_key = Base64.decode64(key_data[:key])
56
+ data = Base64.decode64(key_data[:data])
57
+
58
+ decipher = OpenSSL::Cipher::AES.new(@config[:aes_key_size],
59
+ @config[:aes_cipher_mode])
60
+ decipher.decrypt
61
+ decipher.iv = rsa_key.private_decrypt(iv)
62
+ decipher.key = rsa_key.private_decrypt(sym_key)
63
+ key = decipher.update(data) + decipher.final
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ Spaux::Chef::RawKey = Spaux::Chef::Key.new.raw_key
@@ -0,0 +1,32 @@
1
+ require 'chef'
2
+ require 'chef/application/client'
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
+ class ChefVault
20
+ class Item < Chef::DataBagItem
21
+ def secret
22
+ if @keys.include?(Chef::Config[:node_name])
23
+ private_key = OpenSSL::PKey::RSA.new(Chef::Config[:raw_key])
24
+ private_key.private_decrypt(Base64.decode64(@keys[Chef::Config[:node_name]]))
25
+ else
26
+ raise ChefVault::Exceptions::SecretDecryption,
27
+ "#{data_bag}/#{id} is not encrypted with your public key. "\
28
+ "Contact an administrator of the vault item to encrypt for you!"
29
+ end
30
+ end
31
+ end
32
+ end
data/lib/spaux/cli.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'thor'
2
+ require 'spaux'
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+
6
+ class Spaux
7
+ class CLI < Thor
8
+ desc 'converge', 'Run spaux chef client'
9
+ option :dir, :desc => 'Working directory', :banner => 'DIRECTORY'
10
+ option :current, :type => :boolean, :default => true,
11
+ :desc => 'Create and/or use a working directory in the current directory'
12
+ def converge
13
+ work_dir = options[:dir]
14
+ if not work_dir
15
+ if ENV['SPAUX_HOME']
16
+ work_dir = ENV['SPAUX_HOME']
17
+ elsif options[:current]
18
+ work_dir = ::File.join(ENV['PWD'], 'current')
19
+ else
20
+ work_dir = Dir.mktmpdir
21
+ end
22
+ end
23
+ FileUtils.mkdir_p work_dir
24
+
25
+ client = Spaux::Chef::Client.new(work_dir)
26
+ client.run
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ class Spaux
2
+ VERSION = '0.0.1'
3
+ end
data/lib/spaux.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'spaux/version'
2
+ require 'spaux/cli'
3
+ require 'spaux/chef/client'
4
+
5
+ class Spaux
6
+ end
data/spaux.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spaux/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spaux"
8
+ spec.version = Spaux::VERSION
9
+ spec.authors = ["Miguel Landaeta"]
10
+ spec.email = ["miguel@miguel.cc"]
11
+ spec.summary = %q{Spaux automation tasks}
12
+ spec.homepage = "https://api.qirtaiba.org/"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "thor"
21
+ spec.add_dependency "chef"
22
+ spec.add_dependency "octokit"
23
+ spec.add_dependency "net-ssh"
24
+ spec.add_dependency 'chef-provisioning', '~> 0.15.1'
25
+ spec.add_dependency 'chef-metal-fog'
26
+ spec.add_dependency 'chef-vault'
27
+ spec.add_development_dependency "bundler", "~> 1.7"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "pry"
31
+ end
@@ -0,0 +1,29 @@
1
+ require 'spaux'
2
+
3
+ # to-do: improve tests
4
+ describe Spaux::Chef::Client do
5
+ describe '#new' do
6
+ it 'has a work dir' do
7
+ client = Spaux::Chef::Client.new(Dir.mktmpdir)
8
+ expect(client).to respond_to(:work_dir)
9
+ end
10
+ it 'has a chef config' do
11
+ client = Spaux::Chef::Client.new(Dir.mktmpdir)
12
+ expect(client).to respond_to(:config)
13
+ end
14
+ it 'has a spaux config' do
15
+ client = Spaux::Chef::Client.new(Dir.mktmpdir)
16
+ expect(client).to respond_to(:spaux_config)
17
+ end
18
+ end
19
+ end
20
+
21
+ #describe Spaux::Chef::Key
22
+
23
+ describe Spaux::CLI do
24
+ describe '#converge' do
25
+ xit 'prints "chef client" in stdout' do
26
+ expect { Spaux::CLI.new.converge }.to output(/Starting Chef Client/).to_stdout
27
+ end
28
+ end
29
+ end
@@ -0,0 +1 @@
1
+ require 'spaux'
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spaux
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Miguel Landaeta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: chef
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: octokit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-ssh
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: chef-provisioning
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.15.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.15.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: chef-metal-fog
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: chef-vault
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '10.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description:
168
+ email:
169
+ - miguel@miguel.cc
170
+ executables:
171
+ - spaux
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".gitignore"
176
+ - Gemfile
177
+ - LICENSE.txt
178
+ - README.md
179
+ - Rakefile
180
+ - bin/spaux
181
+ - examples/attributes.json
182
+ - lib/spaux.rb
183
+ - lib/spaux/chef/client.rb
184
+ - lib/spaux/chef/key.rb
185
+ - lib/spaux/chef/monkey_patches.rb
186
+ - lib/spaux/cli.rb
187
+ - lib/spaux/version.rb
188
+ - spaux.gemspec
189
+ - spec/spaux_spec.rb
190
+ - spec/spec_helper.rb
191
+ homepage: https://api.qirtaiba.org/
192
+ licenses:
193
+ - MIT
194
+ metadata: {}
195
+ post_install_message:
196
+ rdoc_options: []
197
+ require_paths:
198
+ - lib
199
+ required_ruby_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ requirements: []
210
+ rubyforge_project:
211
+ rubygems_version: 2.2.2
212
+ signing_key:
213
+ specification_version: 4
214
+ summary: Spaux automation tasks
215
+ test_files:
216
+ - spec/spaux_spec.rb
217
+ - spec/spec_helper.rb