spice 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spice (0.2.0)
4
+ spice (0.4.0)
5
5
  mixlib-authentication
6
6
  rest-client
7
7
  yajl-ruby
@@ -9,8 +9,24 @@ PATH
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
+ abstract (1.0.0)
12
13
  addressable (2.2.2)
13
14
  builder (3.0.0)
15
+ bunny (0.6.0)
16
+ chef (0.9.12)
17
+ bunny (>= 0.6.0)
18
+ erubis
19
+ extlib
20
+ highline
21
+ json (>= 1.4.4, <= 1.4.6)
22
+ mixlib-authentication (>= 1.1.0)
23
+ mixlib-cli (>= 1.1.0)
24
+ mixlib-config (>= 1.1.2)
25
+ mixlib-log (>= 1.2.0)
26
+ moneta
27
+ ohai (>= 0.5.7)
28
+ rest-client (>= 1.0.4, < 1.7.0)
29
+ uuidtools
14
30
  crack (0.1.8)
15
31
  cucumber (0.10.0)
16
32
  builder (>= 2.1.2)
@@ -19,40 +35,57 @@ GEM
19
35
  json (~> 1.4.6)
20
36
  term-ansicolor (~> 1.0.5)
21
37
  diff-lcs (1.1.2)
38
+ erubis (2.6.6)
39
+ abstract (>= 1.0.0)
40
+ extlib (0.9.15)
22
41
  gherkin (2.3.2)
23
42
  json (~> 1.4.6)
24
43
  term-ansicolor (~> 1.0.5)
44
+ highline (1.6.1)
25
45
  json (1.4.6)
26
46
  mime-types (1.16)
27
47
  mixlib-authentication (1.1.4)
28
48
  mixlib-log
49
+ mixlib-cli (1.2.0)
50
+ mixlib-config (1.1.2)
29
51
  mixlib-log (1.2.0)
52
+ moneta (0.6.0)
53
+ ohai (0.5.8)
54
+ extlib
55
+ json (>= 1.4.4, <= 1.4.6)
56
+ mixlib-cli
57
+ mixlib-config
58
+ mixlib-log
59
+ systemu
30
60
  rcov (0.9.9)
31
61
  rest-client (1.6.1)
32
62
  mime-types (>= 1.16)
33
- rspec (2.4.0)
34
- rspec-core (~> 2.4.0)
35
- rspec-expectations (~> 2.4.0)
36
- rspec-mocks (~> 2.4.0)
37
- rspec-core (2.4.0)
38
- rspec-expectations (2.4.0)
63
+ rspec (2.5.0)
64
+ rspec-core (~> 2.5.0)
65
+ rspec-expectations (~> 2.5.0)
66
+ rspec-mocks (~> 2.5.0)
67
+ rspec-core (2.5.1)
68
+ rspec-expectations (2.5.0)
39
69
  diff-lcs (~> 1.1.2)
40
- rspec-mocks (2.4.0)
70
+ rspec-mocks (2.5.0)
71
+ systemu (1.2.0)
41
72
  term-ansicolor (1.0.5)
42
73
  timecop (0.3.5)
74
+ uuidtools (2.1.1)
43
75
  webmock (1.6.1)
44
76
  addressable (>= 2.2.2)
45
77
  crack (>= 0.1.7)
46
- yajl-ruby (0.7.9)
78
+ yajl-ruby (0.8.1)
47
79
  yard (0.6.4)
48
80
 
49
81
  PLATFORMS
50
82
  ruby
51
83
 
52
84
  DEPENDENCIES
85
+ chef
53
86
  cucumber (~> 0.10.0)
54
87
  rcov
55
- rspec (~> 2.4.0)
88
+ rspec (~> 2.5.0)
56
89
  spice!
57
90
  timecop (~> 0.3.5)
58
91
  webmock (~> 1.6.1)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # spice
2
2
 
3
- Spice is a zesty Chef API wrapper. It's primary purpose is to let you easily integrate your apps with a (Chef)[http://opscode.com/chef] server easily. Spice provides support for the [entire released Chef API](http://wiki.opscode.com/display/chef/Server+API)
3
+ Spice is a zesty Chef API wrapper. Its primary purpose is to let you easily integrate your apps with a (Chef)[http://opscode.com/chef] server easily. Spice provides support for the [Chef API](http://wiki.opscode.com/display/chef/Server+API)
4
4
 
5
5
  ## Installation
6
6
 
@@ -81,6 +81,10 @@ Scope out [the official Chef API docs](http://wiki.opscode.com/display/chef/Serv
81
81
  TODO
82
82
 
83
83
 
84
+ ### Contributors
85
+
86
+ * Ian Meyer (https://github.com/imeyer), added Opscode Platform support
87
+
84
88
  ## Contributing to spice
85
89
 
86
90
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/lib/spice.rb CHANGED
@@ -1,7 +1,7 @@
1
- require 'bundler'
2
- Bundler.require
3
-
4
1
  require 'rest-client'
2
+ require 'mixlib/authentication'
3
+ require 'yajl'
4
+
5
5
  require 'spice/authentication'
6
6
  require 'spice/chef'
7
7
  require 'spice/role'
@@ -12,12 +12,13 @@ require 'spice/data_bag'
12
12
  require 'spice/node'
13
13
  require 'spice/connection'
14
14
 
15
+ require 'spice/version'
15
16
  require 'spice/mock'
16
17
 
17
18
  module Spice
18
19
 
19
20
  class << self
20
- attr_writer :host, :port, :scheme, :client_name, :connection, :key_file, :raw_key
21
+ attr_writer :host, :port, :scheme, :url_path, :client_name, :connection, :key_file, :raw_key
21
22
 
22
23
  def default_host
23
24
  @default_host || "localhost"
@@ -31,6 +32,10 @@ module Spice
31
32
  @default_scheme || "http"
32
33
  end
33
34
 
35
+ def default_url_path
36
+ @default_url_path || ""
37
+ end
38
+
34
39
  def host
35
40
  @host || default_host
36
41
  end
@@ -62,6 +67,11 @@ module Spice
62
67
  @raw_key = raw_key
63
68
  end
64
69
 
70
+
71
+ def url_path
72
+ @url_path || default_url_path
73
+ end
74
+
65
75
  def connection
66
76
  @connection
67
77
  end
@@ -82,7 +92,6 @@ module Spice
82
92
  @key_file = nil
83
93
  @client_name = nil
84
94
  @connection = nil
85
- puts "Spice is reset"
86
95
  end
87
96
 
88
97
  def setup
@@ -1,5 +1,6 @@
1
1
  require 'openssl'
2
2
  require 'mixlib/authentication/signedheaderauth'
3
+ require 'chef/version'
3
4
 
4
5
  module Spice
5
6
  class Authentication
@@ -23,6 +24,9 @@ module Spice
23
24
  sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(request_params)
24
25
  signed = sign_obj.sign(key).merge({:host => host})
25
26
  signed.inject({}){|memo, kv| memo["#{kv[0].to_s.upcase}"] = kv[1];memo}
27
+ # Platform requires X-Chef-Version header
28
+ version = { "X-Chef-Version" => ::Chef::VERSION }
29
+ signed.merge!(version)
26
30
  end
27
31
 
28
32
  private
@@ -10,8 +10,7 @@ module Spice
10
10
  @host = endpoint.host
11
11
  @scheme = endpoint.scheme
12
12
  @port = endpoint.port
13
- @path = endpoint.path
14
- @path = URI.parse(@url).path
13
+ @url_path = endpoint.path
15
14
  @auth_credentials = Authentication.new(options[:client_name], options[:key_file])
16
15
  @sign_on_redirect, @sign_request = true, true
17
16
  end
@@ -20,7 +19,7 @@ module Spice
20
19
  begin
21
20
  RestClient.get(
22
21
  "#{@url}#{path}",
23
- build_headers(:GET, path, headers)
22
+ build_headers(:GET, "#{@url_path}#{path}", headers)
24
23
  )
25
24
  rescue => e
26
25
  e.response
@@ -32,7 +31,7 @@ module Spice
32
31
  RestClient.post(
33
32
  "#{@url}#{path}",
34
33
  JSON.generate(payload),
35
- build_headers(:POST, path, headers, JSON.generate(payload))
34
+ build_headers(:POST, "#{@url_path}#{path}", headers, JSON.generate(payload))
36
35
  )
37
36
  rescue => e
38
37
  e.response
@@ -44,7 +43,7 @@ module Spice
44
43
  RestClient.put(
45
44
  "#{@url}#{path}",
46
45
  JSON.generate(payload),
47
- build_headers(:PUT, path, headers, JSON.generate(payload))
46
+ build_headers(:PUT, "#{@url_path}#{path}", headers, JSON.generate(payload))
48
47
  )
49
48
  rescue => e
50
49
  e.response
@@ -55,7 +54,7 @@ module Spice
55
54
  begin
56
55
  RestClient.delete(
57
56
  "#{@url}#{path}",
58
- build_headers(:DELETE, path, headers)
57
+ build_headers(:DELETE, "#{@url_path}#{path}", headers)
59
58
  )
60
59
  rescue => e
61
60
  e.response
@@ -73,7 +72,7 @@ module Spice
73
72
  :http_method => method,
74
73
  :path => path,
75
74
  :body => json_body,
76
- :host => "#{@scheme}://#{@host}:#{@port}#{@path}"
75
+ :host => "#{@host}:#{@port}"
77
76
  }
78
77
  request_params[:body] ||= ""
79
78
  auth_credentials.signature_headers(request_params)
data/lib/spice/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spice
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -21,10 +21,10 @@ module Spice
21
21
  :headers => {})
22
22
  end
23
23
  it "should return a list of all clients" do
24
- clients.length.should == 2
24
+ JSON.parse(clients).length.should == 2
25
25
  end
26
26
  it "should provide valid client" do
27
- clients["testclient"].should == "http://localhost:4000/clients/testclient"
27
+ clients["testclient"].should == "testclient"
28
28
  end
29
29
  end
30
30
 
@@ -40,11 +40,11 @@ module Spice
40
40
  )
41
41
  end
42
42
  it "should return a list of all nodes" do
43
- nodes.length.should == 1
43
+ JSON.parse(nodes).length.should == 1
44
44
  # nodes.first["testnode"].should == "http://localhost:4000/nodes/testnode"
45
45
  end
46
46
  it "should provide valid node" do
47
- nodes["testnode"].should == "http://localhost:4000/nodes/testnode"
47
+ nodes["testnode"].should == "testnode"
48
48
  end
49
49
  end
50
50
 
@@ -59,10 +59,10 @@ module Spice
59
59
  )
60
60
  end
61
61
  it "should return a list of all data bags" do
62
- data_bags.length.should == 1
62
+ JSON.parse(data_bags).length.should == 1
63
63
  end
64
64
  it "should provide valid data" do
65
- data_bags["testdata"].should == "http://localhost:4000/data/testdata"
65
+ data_bags["testdata"].should == "testdata"
66
66
  end
67
67
  end
68
68
 
@@ -72,15 +72,15 @@ module Spice
72
72
  stub_request(:get, "http://localhost:4000/roles").
73
73
  to_return(
74
74
  :status => 200,
75
- :body => '{"testrole":"http://localhost:4000/roles/testrole"}',
75
+ :body => '{"testrole":"testrole"}',
76
76
  :headers => {}
77
77
  )
78
78
  end
79
79
  it "should return a list of all roles" do
80
- roles.length.should == 1
80
+ JSON.parse(roles).length.should == 1
81
81
  end
82
82
  it "should provide valid role" do
83
- roles["testrole"].should == "http://localhost:4000/roles/testrole"
83
+ roles["testrole"].should == "testrole"
84
84
  end
85
85
  end
86
86
 
@@ -95,10 +95,10 @@ module Spice
95
95
  )
96
96
  end
97
97
  it "should return a list of all cookbooks" do
98
- cookbooks.length.should == 1
98
+ JSON.parse(cookbooks).length.should == 1
99
99
  end
100
100
  it "should provide valid cookbook" do
101
- cookbooks["testcookbook"].should == "http://localhost:4000/cookbooks/testcookbook"
101
+ cookbooks["testcookbook"].should == "testcookbook"
102
102
  end
103
103
  end
104
104
  end
data/spec/spice_spec.rb CHANGED
@@ -28,7 +28,16 @@ describe "Spice" do
28
28
  lambda { Spice.default_scheme = "ftp" }.should raise_error
29
29
  end
30
30
  end
31
-
31
+
32
+ describe ".default_url_path" do
33
+ it "should default to ''" do
34
+ Spice.default_url_path.should == ""
35
+ end
36
+ it "should not be settable" do
37
+ lambda { Spice.default_url_path = "/woohah" }.should raise_error
38
+ end
39
+ end
40
+
32
41
  describe ".host" do
33
42
  it "should default to 'localhost' if not set" do
34
43
  Spice.host.should == "localhost"
@@ -59,7 +68,18 @@ describe "Spice" do
59
68
  end
60
69
  end
61
70
 
71
+ describe ".url_path" do
72
+ it "should default to '' if not set" do
73
+ Spice.url_path.should == ""
74
+ end
75
+ it "should be settable" do
76
+ Spice.url_path = "/woohah"
77
+ Spice.url_path.should == "/woohah"
78
+ end
79
+ end
80
+
62
81
  describe ".client_name" do
82
+ before { Spice.reset! }
63
83
  it "should not have a default" do
64
84
  Spice.client_name.should be_nil
65
85
  end
@@ -70,12 +90,14 @@ describe "Spice" do
70
90
  end
71
91
 
72
92
  describe ".key_file" do
93
+ before { Spice.reset! }
94
+
73
95
  it "should not have a default" do
74
96
  Spice.key_file.should be_nil
75
97
  end
76
98
  it "should be settable" do
77
99
  Spice.key_file = "/tmp/keyfile.pem"
78
- Spice.key_file.should == File.read("/tmp/keyfile.pem")
100
+ Spice.key_file.should == "/tmp/keyfile.pem"
79
101
  end
80
102
  it "should raise exception if it does not exist" do
81
103
  lambda { Spice.key_file = "/tmp/badkey.pem" }.should raise_error(Errno::ENOENT)
@@ -83,6 +105,8 @@ describe "Spice" do
83
105
  end
84
106
 
85
107
  describe ".connection" do
108
+ before { Spice.reset! }
109
+
86
110
  it "should not have a default" do
87
111
  Spice.connection.should be_nil
88
112
  end
data/spice.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.email = ["hi@iamdanryan.com"]
11
11
  s.homepage = "http://github.com/danryan/spice"
12
12
  s.summary = %q{Chef API wrapper}
13
- s.description = %q{Spice is a zesty Chef API wrapper. It's primary purpose is to let you easily integrate your apps with a (Chef)[http://opscode.com/chef] server easily. Spice provides support for the [entire released Chef API](http://wiki.opscode.com/display/chef/Server+API)}
13
+ s.description = %q{Spice is a zesty Chef API wrapper. It's primary purpose is to let you easily integrate your apps with a Chef server easily. Spice provides support for the entire released Chef API}
14
14
 
15
15
  s.rubyforge_project = "spice"
16
16
 
@@ -19,11 +19,12 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency "yajl-ruby"
20
20
 
21
21
  s.add_development_dependency "yard", "~> 0.6.4"
22
- s.add_development_dependency "rspec", "~> 2.4.0"
22
+ s.add_development_dependency "rspec", "~> 2.5.0"
23
23
  s.add_development_dependency "cucumber", "~> 0.10.0"
24
24
  s.add_development_dependency "webmock", "~> 1.6.1"
25
25
  s.add_development_dependency "timecop", "~> 0.3.5"
26
26
  s.add_development_dependency "rcov"
27
+ s.add_development_dependency "chef"
27
28
 
28
29
  s.files = `git ls-files`.split("\n")
29
30
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
7
+ - 4
8
8
  - 0
9
- version: 0.3.0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dan Ryan
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-25 00:00:00 -05:00
17
+ date: 2011-02-27 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -81,9 +81,9 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  segments:
83
83
  - 2
84
- - 4
84
+ - 5
85
85
  - 0
86
- version: 2.4.0
86
+ version: 2.5.0
87
87
  type: :development
88
88
  version_requirements: *id005
89
89
  - !ruby/object:Gem::Dependency
@@ -144,7 +144,20 @@ dependencies:
144
144
  version: "0"
145
145
  type: :development
146
146
  version_requirements: *id009
147
- description: Spice is a zesty Chef API wrapper. It's primary purpose is to let you easily integrate your apps with a (Chef)[http://opscode.com/chef] server easily. Spice provides support for the [entire released Chef API](http://wiki.opscode.com/display/chef/Server+API)
147
+ - !ruby/object:Gem::Dependency
148
+ name: chef
149
+ prerelease: false
150
+ requirement: &id010 !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ type: :development
159
+ version_requirements: *id010
160
+ description: Spice is a zesty Chef API wrapper. It's primary purpose is to let you easily integrate your apps with a Chef server easily. Spice provides support for the entire released Chef API
148
161
  email:
149
162
  - hi@iamdanryan.com
150
163
  executables: []