chef-readbag 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/bin/.gitkeep +0 -0
- data/chef-readbag.gemspec +23 -0
- data/lib/chef-readbag.rb +10 -0
- data/lib/chef-readbag/auth_credentials.rb +49 -0
- data/lib/chef-readbag/bag.rb +38 -0
- data/lib/chef-readbag/version.rb +5 -0
- metadata +90 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create use ruby-1.9.3@chef-readbag
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Neal Clark
|
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,39 @@
|
|
1
|
+
# Chef::Readbag
|
2
|
+
|
3
|
+
Get stuff out of chef databags.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'chef-readbag'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install chef-readbag
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Get stuff out of databags:
|
22
|
+
|
23
|
+
1.9.3-p194 :001 > require 'chef-readbag'
|
24
|
+
=> true
|
25
|
+
1.9.3-p194 :002 > bag = Chef::Readbag::Bag.new('chef-server:4000', 'example-client', 'path-to-example-client.pem')
|
26
|
+
=> #<Chef::Readbag::Bag:0x007fa04b2410d8 @host_and_port="chef-server:4000", @client_name="example-client",
|
27
|
+
@client_key_path='path-to-example-client.pem'>
|
28
|
+
1.9.3-p194 :003 > bag['hosts/project-name-app-servers']['production']
|
29
|
+
=> ["project-name-app1", "project-name-app2", "project-name-app3"]
|
30
|
+
|
31
|
+
I use it in capistrano.
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chef-readbag/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |g|
|
7
|
+
g.name = "chef-readbag"
|
8
|
+
g.version = Chef::Readbag::VERSION
|
9
|
+
g.authors = ["Neal Clark"]
|
10
|
+
g.email = ["nclark@thrownproject.com"]
|
11
|
+
g.description = %q{Get stuff out of chef databags.}
|
12
|
+
g.summary = %q{Get stuff out of chef databags. databags.}
|
13
|
+
g.homepage = %q{http://github.com/nclark/chef-readbag}
|
14
|
+
|
15
|
+
g.files = `git ls-files`.split($/)
|
16
|
+
g.executables = g.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
g.test_files = g.files.grep(%r{^(test|spec|features)/})
|
18
|
+
g.require_paths = ["lib"]
|
19
|
+
|
20
|
+
g.add_runtime_dependency 'mixlib-authentication', '>= 1.1.4'
|
21
|
+
g.add_runtime_dependency 'rest-client', '~> 1.6.7'
|
22
|
+
end
|
23
|
+
|
data/lib/chef-readbag.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# adapted from https://github.com/opscode/chef/blob/master/chef/lib/chef/rest/auth_credentials.rb
|
2
|
+
|
3
|
+
module Chef
|
4
|
+
module Readbag
|
5
|
+
class AuthCredentials
|
6
|
+
attr_reader :key_file, :client_name, :key, :raw_key
|
7
|
+
|
8
|
+
def initialize(client_name, key_file_path)
|
9
|
+
@client_name = client_name
|
10
|
+
@key_file = File.expand_path(key_file_path)
|
11
|
+
|
12
|
+
load_signing_key if sign_requests?
|
13
|
+
end
|
14
|
+
|
15
|
+
def sign_requests?
|
16
|
+
!!key_file
|
17
|
+
end
|
18
|
+
|
19
|
+
def signature_headers(request_params={})
|
20
|
+
raise ArgumentError, "Cannot sign the request without a client name, check that :node_name is assigned" if client_name.nil?
|
21
|
+
|
22
|
+
# params_in = {:http_method => :GET, :path => "/clients", :body => "", :host => "localhost"}
|
23
|
+
request_params = request_params.dup
|
24
|
+
request_params[:timestamp] = Time.now.utc.iso8601
|
25
|
+
request_params[:user_id] = @client_name
|
26
|
+
host = request_params.delete(:host) || "localhost"
|
27
|
+
|
28
|
+
sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(request_params)
|
29
|
+
signed = sign_obj.sign(key).merge({:host => host})
|
30
|
+
signed.inject({}){|memo, kv| memo["#{kv[0].to_s.upcase}"] = kv[1];memo}
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def load_signing_key
|
36
|
+
@raw_key = IO.read(key_file).strip
|
37
|
+
@key = OpenSSL::PKey::RSA.new(@raw_key)
|
38
|
+
rescue SystemCallError, IOError => e
|
39
|
+
puts("Failed to read the private key #{key_file}: #{e.inspect}")
|
40
|
+
raise Chef::Exceptions::PrivateKeyMissing, "I cannot read #{key_file}, which you told me to use to sign requests!"
|
41
|
+
rescue OpenSSL::PKey::RSAError
|
42
|
+
msg = "The file #{key_file} does not contain a correctly formatted private key.\n"
|
43
|
+
msg << "The key file should begin with '-----BEGIN RSA PRIVATE KEY-----' and end with '-----END RSA PRIVATE KEY-----'"
|
44
|
+
raise Chef::Exceptions::InvalidPrivateKey, msg
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Chef
|
2
|
+
module Readbag
|
3
|
+
class Bag
|
4
|
+
def initialize(host_and_port, client_name, client_key_path)
|
5
|
+
@host_and_port = host_and_port
|
6
|
+
@client_name = client_name
|
7
|
+
@client_key_path = client_key_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](bag_name)
|
11
|
+
@bag_name = bag_name
|
12
|
+
|
13
|
+
JSON.parse(RestClient.get(url, headers))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def path
|
19
|
+
"/data/#{@bag_name}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def url
|
23
|
+
"http://#{@host_and_port}/#{path}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def headers
|
27
|
+
signed_headers.merge('Accept' => 'application/json')
|
28
|
+
end
|
29
|
+
|
30
|
+
def signed_headers
|
31
|
+
credentials = Chef::Readbag::AuthCredentials.new(@client_name, @client_key_path)
|
32
|
+
request_params = { :http_method => :GET, :path => path, :body => "", :host => @host_and_port }
|
33
|
+
credentials.signature_headers(request_params)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-readbag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Neal Clark
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mixlib-authentication
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.1.4
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.1.4
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rest-client
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.6.7
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.6.7
|
46
|
+
description: Get stuff out of chef databags.
|
47
|
+
email:
|
48
|
+
- nclark@thrownproject.com
|
49
|
+
executables:
|
50
|
+
- .gitkeep
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- .rvmrc
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- bin/.gitkeep
|
61
|
+
- chef-readbag.gemspec
|
62
|
+
- lib/chef-readbag.rb
|
63
|
+
- lib/chef-readbag/auth_credentials.rb
|
64
|
+
- lib/chef-readbag/bag.rb
|
65
|
+
- lib/chef-readbag/version.rb
|
66
|
+
homepage: http://github.com/nclark/chef-readbag
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.24
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Get stuff out of chef databags. databags.
|
90
|
+
test_files: []
|