spice 0.0.1.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
File without changes
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ spice (0.0.1.alpha)
5
+ mixlib-authentication
6
+ rest-client
7
+ yajl-ruby
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ diff-lcs (1.1.2)
13
+ mime-types (1.16)
14
+ mixlib-authentication (1.1.4)
15
+ mixlib-log
16
+ mixlib-log (1.2.0)
17
+ rest-client (1.6.1)
18
+ mime-types (>= 1.16)
19
+ rspec (2.4.0)
20
+ rspec-core (~> 2.4.0)
21
+ rspec-expectations (~> 2.4.0)
22
+ rspec-mocks (~> 2.4.0)
23
+ rspec-core (2.4.0)
24
+ rspec-expectations (2.4.0)
25
+ diff-lcs (~> 1.1.2)
26
+ rspec-mocks (2.4.0)
27
+ yajl-ruby (0.7.8)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ mixlib-authentication
34
+ rest-client
35
+ rspec (= 2.4.0)
36
+ spice!
37
+ yajl-ruby
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Dan Ryan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Notes.md ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ = spice
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to spice
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Dan Ryan. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
File without changes
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+ begin
3
+ Bundler.setup(:default, :development)
4
+ rescue Bundler::BundlerError => e
5
+ $stderr.puts e.message
6
+ $stderr.puts "Run `bundle install` to install missing gems"
7
+ exit e.status_code
8
+ end
9
+
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
11
+ require 'spice'
12
+
13
+ require 'rspec/expectations'
@@ -0,0 +1,49 @@
1
+ require 'openssl'
2
+ require 'mixlib/authentication/signedheaderauth'
3
+
4
+ module Spice
5
+ class Authentication
6
+ attr_reader :key_file, :client_name, :key, :raw_key
7
+
8
+ def initialize(client_name=nil, key_file=nil)
9
+ @client_name, @key_file = client_name, key_file
10
+ load_signing_key if sign_requests?
11
+ end
12
+
13
+ def sign_requests?
14
+ !!key_file
15
+ end
16
+
17
+ def signature_headers(request_params={})
18
+ request_params = request_params.dup
19
+ request_params[:timestamp] = Time.now.utc.iso8601
20
+ request_params[:user_id] = client_name
21
+ host = request_params.delete(:host) || "localhost"
22
+
23
+ sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(request_params)
24
+ signed = sign_obj.sign(key).merge({:host => host})
25
+ signed.inject({}){|memo, kv| memo["#{kv[0].to_s.upcase}"] = kv[1];memo}
26
+ end
27
+
28
+ private
29
+
30
+ def load_signing_key
31
+ begin
32
+ @raw_key = IO.read(key_file, :mode => "r").strip
33
+ rescue SystemCallError, IOError => e
34
+ raise IOError, "Unable to read #{key_file}"
35
+ end
36
+ assert_valid_key_format!(@raw_key)
37
+ @key = OpenSSL::PKey::RSA.new(@raw_key)
38
+ end
39
+
40
+ def assert_valid_key_format!(raw_key)
41
+ unless (raw_key =~ /\A-----BEGIN RSA PRIVATE KEY-----$/) &&
42
+ (raw_key =~ /^-----END RSA PRIVATE KEY-----\Z/)
43
+ msg = "The file #{key_file} does not contain a correctly formatted private key.\n"
44
+ msg << "The key file should begin with '-----BEGIN RSA PRIVATE KEY-----' and end with '-----END RSA PRIVATE KEY-----'"
45
+ raise ArgumentError, msg
46
+ end
47
+ end
48
+ end
49
+ end
data/lib/spice/chef.rb ADDED
@@ -0,0 +1,43 @@
1
+ module Spice
2
+ class Chef
3
+ attr_accessor :host, :client_name, :key_file, :port, :path, :scheme, :connection
4
+
5
+
6
+ def initialize(options={})
7
+ @@client_name ||= @client_name = options[:client_name]
8
+ @@key_file ||= @key_file = options[:key_file]
9
+ @@host ||= @host = options[:host] || 'localhost'
10
+ @@port ||= @port = options[:port] || 4000
11
+ @@path ||= @path = options[:path] || '/'
12
+ @@scheme ||= @scheme = options[:scheme] || 'http'
13
+ @@connection ||= @connection = Connection.new(
14
+ :url => "#{@scheme}://#{@host}:#{@port}#{@path}",
15
+ :client_name => options[:client_name],
16
+ :key_file => options[:key_file]
17
+ )
18
+ @default_headers = options[:headers] || {}
19
+ @sign_on_redirect, @sign_request = true, true
20
+ end
21
+
22
+ def connection
23
+ @@connection
24
+ end
25
+
26
+ def self.connection
27
+ @@connection
28
+ end
29
+
30
+ def clients
31
+ Client.all
32
+ end
33
+
34
+ def nodes
35
+ Node.all
36
+ end
37
+
38
+ def data_bags
39
+ DataBag.all
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,38 @@
1
+ module Spice
2
+ class Client < Spice::Chef
3
+ def self.all(options={})
4
+ if options[:complete]
5
+ results = []
6
+ connection.get("/clients").map { |c| c[0] }.each do |client|
7
+ results << connection.get("/clients/#{client}")
8
+ end
9
+ results
10
+ else
11
+ connection.get("/clients")
12
+ end
13
+ end
14
+
15
+ def self.[](name)
16
+ connection.get("/clients/#{name}")
17
+ end
18
+
19
+ def self.show(options={})
20
+ name = options.delete(:name)
21
+ connection.get("/clients/#{name}")
22
+ end
23
+
24
+ def self.create(options={})
25
+ connection.post("/clients", options)
26
+ end
27
+
28
+ def self.update(options={})
29
+ name = options.delete(:name)
30
+ connection.put("/clients/#{name}", options)
31
+ end
32
+
33
+ def self.delete(options={})
34
+ name = options.delete(:name)
35
+ connection.delete("/clients/#{name}")
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,83 @@
1
+ require 'rest-client'
2
+
3
+ module Spice
4
+ class Connection
5
+ attr_accessor :client_name, :key_file, :auth_credentials, :url, :path, :port, :scheme
6
+
7
+ def initialize(options={})
8
+ endpoint = URI.parse(options[:url])
9
+ @url = options[:url]
10
+ @host = endpoint.host
11
+ @scheme = endpoint.scheme
12
+ @port = endpoint.port
13
+ @path = endpoint.path
14
+ @path = URI.parse(@url).path
15
+ @auth_credentials = Authentication.new(options[:client_name], options[:key_file])
16
+ @sign_on_redirect, @sign_request = true, true
17
+ end
18
+
19
+ def get(path, headers={})
20
+ response = RestClient::Request.execute(
21
+ :method => :GET,
22
+ :url => "#{@url}#{path}",
23
+ :headers => build_headers(:GET, path, headers)
24
+ )
25
+ JSON.parse(response)
26
+ end
27
+
28
+ def post(path, payload, headers={})
29
+ response = RestClient::Request.execute(
30
+ :method => :POST,
31
+ :url => "#{@url}#{path}",
32
+ :headers => build_headers(:POST, path, headers, JSON.generate(payload)),
33
+ :payload => JSON.generate(payload)
34
+ )
35
+ JSON.parse(response)
36
+ end
37
+
38
+ def put(path, payload, headers={})
39
+ response = RestClient::Request.execute(
40
+ :method => :PUT,
41
+ :url => "#{@url}#{path}",
42
+ :headers => build_headers(:PUT, path, headers, JSON.generate(payload)),
43
+ :payload => JSON.generate(payload)
44
+ )
45
+ JSON.parse(response)
46
+ end
47
+
48
+ def delete(path, payload, headers={})
49
+ response = RestClient::Request.execute(
50
+ :method => :DELETE,
51
+ :url => "#{@url}#{path}",
52
+ :headers => build_headers(:DELETE, path, headers, JSON.generate(payload)),
53
+ :payload => JSON.generate(payload)
54
+ )
55
+ JSON.parse(response)
56
+ end
57
+
58
+ def sign_requests?
59
+ auth_credentials.sign_requests? && @sign_request
60
+ end
61
+
62
+ private
63
+
64
+ def authentication_headers(method, path, json_body=nil)
65
+ request_params = {
66
+ :http_method => method,
67
+ :path => path,
68
+ :body => json_body,
69
+ :host => "#{@scheme}://#{@host}:#{@port}#{@path}"
70
+ }
71
+ request_params[:body] ||= ""
72
+ auth_credentials.signature_headers(request_params)
73
+ end
74
+
75
+ def build_headers(method, path, headers={}, json_body=false)
76
+ headers['Accept'] = "application/json"
77
+ headers["Content-Type"] = 'application/json' if json_body
78
+ headers['Content-Length'] = json_body.bytesize.to_s if json_body
79
+ headers.merge!(authentication_headers(method, path, json_body)) if sign_requests?
80
+ headers
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,30 @@
1
+ module Spice
2
+ class Cookbook < Spice::Chef
3
+ def self.all(options={})
4
+ connection.get("/cookbooks").map { |c| c[0] }
5
+ end
6
+
7
+ def self.[](name)
8
+ connection.get("/cookbooks/#{name}")
9
+ end
10
+
11
+ def self.show(options={})
12
+ name = options.delete(:name)
13
+ connection.get("/cookbooks/#{name}")
14
+ end
15
+
16
+ def self.create(options={})
17
+ connection.post("/cookbooks", options)
18
+ end
19
+
20
+ def self.update(options={})
21
+ name = options.delete(:name)
22
+ connection.put("/cookbooks/#{name}", options)
23
+ end
24
+
25
+ def self.delete(options={})
26
+ name = options.delete(:name)
27
+ connection.delete("/cookbooks/#{name}")
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ module Spice
2
+ class DataBag < Spice::Chef
3
+ def self.all(options={})
4
+ connection.get("/data")
5
+ end
6
+
7
+ def self.[](name)
8
+ connection.get("/data/#{name}")
9
+ end
10
+
11
+ def self.show(options={})
12
+ name = options.delete(:name)
13
+ connection.get("/data/#{name}")
14
+ end
15
+
16
+ def self.create(options={})
17
+ connection.post("/data", options)
18
+ end
19
+
20
+ def self.update(options={})
21
+ name = options.delete(:name)
22
+ connection.put("/data/#{name}", options)
23
+ end
24
+
25
+ def self.delete(options={})
26
+ name = options.delete(:name)
27
+ connection.delete("/data/#{name}")
28
+ end
29
+ end
30
+ end
data/lib/spice/node.rb ADDED
@@ -0,0 +1,30 @@
1
+ module Spice
2
+ class Node < Spice::Chef
3
+ def self.all(options={})
4
+ connection.get("/nodes")
5
+ end
6
+
7
+ def self.[](name)
8
+ connection.get("/nodes/#{name}")
9
+ end
10
+
11
+ def self.show(options={})
12
+ name = options.delete(:name)
13
+ connection.get("/nodes/#{name}")
14
+ end
15
+
16
+ def self.create(options={})
17
+ connection.post("/nodes", options)
18
+ end
19
+
20
+ def self.update(options={})
21
+ name = options.delete(:name)
22
+ connection.put("/nodes/#{name}", options)
23
+ end
24
+
25
+ def self.delete(options={})
26
+ name = options.delete(:name)
27
+ connection.delete("/nodes/#{name}")
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Spice
2
+ VERSION = "0.0.1.alpha.2"
3
+ end
data/lib/spice.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'yajl/json_gem'
2
+ require 'rest-client'
3
+
4
+ require 'spice/authentication'
5
+ require 'spice/chef'
6
+
7
+ require 'spice/client'
8
+ require 'spice/cookbook'
9
+ require 'spice/data_bag'
10
+ require 'spice/node'
11
+ require 'spice/connection'
12
+
13
+ module Spice
14
+ end
Binary file
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'spice'
5
+
6
+ require 'rest-client'
7
+ require 'mixlib-authentication'
8
+ # Requires supporting files with custom matchers and macros, etc,
9
+ # in ./support/ and its subdirectories.
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+
14
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Spice" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spice.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "spice/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "spice"
7
+ s.version = Spice::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Dan Ryan"]
10
+ s.email = ["hi@iamdanryan.com"]
11
+ s.homepage = "http://github.com/danryan/spice"
12
+ s.summary = %q{Chef API wrapper}
13
+ s.description = %q{A zesty Chef API wrapper}
14
+
15
+ s.rubyforge_project = "spice"
16
+
17
+ s.add_dependency "rest-client"
18
+ s.add_dependency "mixlib-authentication"
19
+ s.add_dependency "yajl-ruby"
20
+
21
+ s.add_development_dependency "rspec", "2.4.0"
22
+
23
+ s.files = `git ls-files`.split("\n")
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ["lib"]
27
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spice
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ - alpha
10
+ - 2
11
+ version: 0.0.1.alpha.2
12
+ platform: ruby
13
+ authors:
14
+ - Dan Ryan
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-01-08 00:00:00 -05:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rest-client
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: mixlib-authentication
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: yajl-ruby
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ type: :runtime
60
+ version_requirements: *id003
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ prerelease: false
64
+ requirement: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - "="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 2
71
+ - 4
72
+ - 0
73
+ version: 2.4.0
74
+ type: :development
75
+ version_requirements: *id004
76
+ description: A zesty Chef API wrapper
77
+ email:
78
+ - hi@iamdanryan.com
79
+ executables: []
80
+
81
+ extensions: []
82
+
83
+ extra_rdoc_files: []
84
+
85
+ files:
86
+ - .document
87
+ - .gitignore
88
+ - .rspec
89
+ - Gemfile
90
+ - Gemfile.lock
91
+ - LICENSE.txt
92
+ - Notes.md
93
+ - README.md
94
+ - Rakefile
95
+ - features/spice.feature
96
+ - features/step_definitions/spice_steps.rb
97
+ - features/support/env.rb
98
+ - lib/spice.rb
99
+ - lib/spice/authentication.rb
100
+ - lib/spice/chef.rb
101
+ - lib/spice/client.rb
102
+ - lib/spice/connection.rb
103
+ - lib/spice/cookbook.rb
104
+ - lib/spice/data_bag.rb
105
+ - lib/spice/node.rb
106
+ - lib/spice/version.rb
107
+ - pkg/spice-0.0.1.alpha.1.gem
108
+ - spec/spec_helper.rb
109
+ - spec/spice_spec.rb
110
+ - spice.gemspec
111
+ has_rdoc: true
112
+ homepage: http://github.com/danryan/spice
113
+ licenses: []
114
+
115
+ post_install_message:
116
+ rdoc_options: []
117
+
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">"
132
+ - !ruby/object:Gem::Version
133
+ segments:
134
+ - 1
135
+ - 3
136
+ - 1
137
+ version: 1.3.1
138
+ requirements: []
139
+
140
+ rubyforge_project: spice
141
+ rubygems_version: 1.3.7
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Chef API wrapper
145
+ test_files:
146
+ - features/spice.feature
147
+ - features/step_definitions/spice_steps.rb
148
+ - features/support/env.rb
149
+ - spec/spec_helper.rb
150
+ - spec/spice_spec.rb