spice 0.4.1 → 0.4.2

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.
data/README.md CHANGED
@@ -17,6 +17,7 @@ Spice has five configuration variables:
17
17
  Spice.host # default: localhost
18
18
  Spice.port # default: 4000
19
19
  Spice.scheme # default: http
20
+ Spice.chef_version # default: 0.9.14. Should be set to the version you have
20
21
  Spice.client_name # default: nil. Must be set to a valid admin Chef client
21
22
  Spice.key_file # default: nil. Must be set to a file path
22
23
 
@@ -28,7 +29,7 @@ To connect to a Chef server at https://chef.example.com:5000 with the "admin" AP
28
29
  Spice.client_name = "admin"
29
30
  Spice.key_file = "/path/to/keyfile.pem"
30
31
 
31
- Say you had a Chef server (or Chef solo) running locally on port 4000 over HTTP, you only need to set your `client_name` and `key_file` path:
32
+ Say you had a Chef server v0.9.14 (or Chef solo) running locally on port 4000 over HTTP, you only need to set your `client_name` and `key_file` path:
32
33
 
33
34
  Spice.client_name = "admin"
34
35
  Spice.key_file = "/path/to/keyfile.pem"
data/lib/spice.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  require 'rest-client'
2
2
  require 'mixlib/authentication'
3
3
  require 'yajl'
4
+ require 'cgi'
4
5
 
5
6
  require 'spice/authentication'
6
7
  require 'spice/chef'
7
8
 
9
+ require 'spice/core_ext/hash'
10
+
8
11
  require 'spice/role'
9
12
  require 'spice/client'
10
13
  require 'spice/cookbook'
@@ -17,70 +20,77 @@ require 'spice/version'
17
20
  require 'spice/mock'
18
21
 
19
22
  module Spice
20
-
23
+
21
24
  class << self
22
25
  attr_writer :host, :port, :scheme, :url_path, :client_name, :connection, :key_file, :raw_key
23
-
26
+
24
27
  def default_host
25
28
  @default_host || "localhost"
26
29
  end
27
-
30
+
28
31
  def default_port
29
32
  @default_port || "4000"
30
33
  end
31
-
34
+
32
35
  def default_scheme
33
36
  @default_scheme || "http"
34
37
  end
35
-
38
+
36
39
  def default_url_path
37
40
  @default_url_path || ""
38
41
  end
39
-
42
+
40
43
  def host
41
44
  @host || default_host
42
45
  end
43
-
46
+
44
47
  def port
45
48
  @port || default_port
46
49
  end
47
-
50
+
48
51
  def scheme
49
52
  @scheme || default_scheme
50
53
  end
51
-
54
+
52
55
  def client_name
53
56
  @client_name
54
57
  end
55
-
58
+
56
59
  def key_file
57
60
  @key_file
58
61
  end
59
-
62
+
60
63
  def raw_key
61
64
  @raw_key
62
65
  end
63
-
66
+
64
67
  def key_file=(new_key_file)
65
68
  raw_key = File.read(new_key_file)
66
69
  assert_valid_key_format!(raw_key)
67
70
  @key_file = new_key_file
68
71
  @raw_key = raw_key
69
72
  end
73
+
74
+ def chef_version
75
+ @chef_version || "0.9.14"
76
+ end
70
77
 
78
+ def chef_version=(version)
79
+ @chef_version = version
80
+ end
71
81
 
72
82
  def url_path
73
83
  @url_path || default_url_path
74
84
  end
75
-
85
+
76
86
  def connection
77
87
  @connection
78
88
  end
79
89
 
80
90
  def connect!
81
91
  @connection = Connection.new(
82
- :url => "#{scheme}://#{host}:#{port}/#{url_path}",
83
- :client_name => client_name,
92
+ :url => "#{scheme}://#{host}:#{port}/#{url_path}",
93
+ :client_name => client_name,
84
94
  :key_file => key_file
85
95
  )
86
96
  end
@@ -93,17 +103,17 @@ module Spice
93
103
  @client_name = nil
94
104
  @connection = nil
95
105
  end
96
-
106
+
97
107
  def setup
98
108
  yield self
99
109
  end
100
-
110
+
101
111
  def mock
102
112
  Spice::Mock.setup_mock_client
103
113
  end
104
-
114
+
105
115
  private
106
-
116
+
107
117
  def assert_valid_key_format!(raw_key)
108
118
  unless (raw_key =~ /\A-----BEGIN RSA PRIVATE KEY-----$/) &&
109
119
  (raw_key =~ /^-----END RSA PRIVATE KEY-----\Z/)
@@ -1,6 +1,5 @@
1
1
  require 'openssl'
2
2
  require 'mixlib/authentication/signedheaderauth'
3
- require 'chef/version'
4
3
 
5
4
  module Spice
6
5
  class Authentication
@@ -25,7 +24,7 @@ module Spice
25
24
  signed = sign_obj.sign(key).merge({:host => host})
26
25
  signed.inject({}){|memo, kv| memo["#{kv[0].to_s.upcase}"] = kv[1];memo}
27
26
  # Platform requires X-Chef-Version header
28
- version = { "X-Chef-Version" => ::Chef::VERSION }
27
+ version = { "X-Chef-Version" => Spice.chef_version }
29
28
  signed.merge!(version)
30
29
  end
31
30
 
@@ -0,0 +1,11 @@
1
+ class Hash
2
+ def symbolize_keys!
3
+ keys.each do |key|
4
+ self[(key.to_sym rescue key) || key] = delete(key)
5
+ end
6
+ self
7
+ end
8
+ def symbolize_keys
9
+ dup.symbolize_keys!
10
+ end
11
+ end
data/lib/spice/search.rb CHANGED
@@ -1,20 +1,23 @@
1
1
  module Spice
2
2
  class Search < Spice::Chef
3
- INDEXES = %w(node role client users)
4
-
5
- INDEXES.each do |index|
6
- define_method index do |options|
7
- options ||= {}
8
- options.symbolize_keys!
9
-
10
- type = index
11
- query = options[:q] || '*:*'
12
- sort = options[:sort] || "X_CHEF_id_CHEF_X asc"
13
- start = options[:start] || 0
14
- rows = options[:rows] || 1000
15
-
16
- connection.get("/search/#{index}?q=#{escape(query)}&sort=#{escape(sort)}&start=#{escape(start)}&rows=#{escape(rows)}")
17
- end
3
+ def self.search(index, options={})
4
+ options = {:q => options} if options.is_a? String
5
+ options.symbolize_keys!
6
+
7
+ options[:q] ||= '*:*'
8
+ options[:sort] ||= "X_CHEF_id_CHEF_X asc"
9
+ options[:start] ||= 0
10
+ options[:rows] ||= 1000
11
+
12
+ # clean up options hash
13
+ options.delete_if{|k,v| !%w(q sort start rows).include?(k.to_s)}
14
+
15
+ params = options.collect{ |k, v| "#{k}=#{CGI::escape(v.to_s)}"}.join("&")
16
+ connection.get("/search/#{CGI::escape(index.to_s)}?#{params}")
17
+ end
18
+
19
+ def self.method_missing(*args, &block)
20
+ self.search(*args, &block)
18
21
  end
19
22
  end
20
- end
23
+ end
data/lib/spice/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spice
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -7,8 +7,8 @@ require 'rspec'
7
7
  require 'webmock/rspec'
8
8
  require 'timecop'
9
9
  require 'rest-client'
10
- require 'spice'
11
10
 
11
+ require 'spice'
12
12
  # Requires supporting files with custom matchers and macros, etc,
13
13
  # in ./support/ and its subdirectories.
14
14
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
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 server easily. Spice provides support for the entire released Chef API}
13
+ s.description = %q{Spice is a zesty Chef API wrapper. Its 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
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: spice
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.1
5
+ version: 0.4.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dan Ryan
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-23 00:00:00 -07:00
13
+ date: 2011-03-28 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -123,7 +123,7 @@ dependencies:
123
123
  version: "0"
124
124
  type: :development
125
125
  version_requirements: *id010
126
- 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
126
+ description: Spice is a zesty Chef API wrapper. Its primary purpose is to let you easily integrate your apps with a Chef server easily. Spice provides support for the entire released Chef API
127
127
  email:
128
128
  - hi@iamdanryan.com
129
129
  executables: []
@@ -154,6 +154,7 @@ files:
154
154
  - lib/spice/client.rb
155
155
  - lib/spice/connection.rb
156
156
  - lib/spice/cookbook.rb
157
+ - lib/spice/core_ext/hash.rb
157
158
  - lib/spice/data_bag.rb
158
159
  - lib/spice/mock.rb
159
160
  - lib/spice/node.rb
@@ -203,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
204
  requirements: []
204
205
 
205
206
  rubyforge_project: spice
206
- rubygems_version: 1.5.3
207
+ rubygems_version: 1.6.2
207
208
  signing_key:
208
209
  specification_version: 3
209
210
  summary: Chef API wrapper