spice 0.8.0 → 1.0.0.pre
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/.gitignore +1 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +6 -6
- data/README.md +5 -63
- data/lib/spice.rb +56 -151
- data/lib/spice/client.rb +23 -36
- data/lib/spice/config.rb +52 -0
- data/lib/spice/connection.rb +89 -74
- data/lib/spice/connection/authentication.rb +47 -0
- data/lib/spice/connection/clients.rb +15 -0
- data/lib/spice/connection/cookbooks.rb +42 -0
- data/lib/spice/connection/data_bags.rb +35 -0
- data/lib/spice/connection/environments.rb +16 -0
- data/lib/spice/connection/nodes.rb +15 -0
- data/lib/spice/connection/roles.rb +15 -0
- data/lib/spice/connection/search.rb +49 -0
- data/lib/spice/cookbook.rb +13 -30
- data/lib/spice/cookbook_version.rb +43 -0
- data/lib/spice/data_bag.rb +17 -121
- data/lib/spice/data_bag_item.rb +35 -0
- data/lib/spice/environment.rb +15 -79
- data/lib/spice/error.rb +30 -0
- data/lib/spice/node.rb +19 -36
- data/lib/spice/persistence.rb +42 -0
- data/lib/spice/request.rb +27 -0
- data/lib/spice/request/auth.rb +14 -0
- data/lib/spice/response/client_error.rb +30 -0
- data/lib/spice/response/parse_json.rb +24 -0
- data/lib/spice/role.rb +18 -25
- data/lib/spice/version.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- data/spice.gemspec +4 -3
- metadata +65 -42
- data/lib/spice/core_ext/hash.rb +0 -21
- data/lib/spice/search.rb +0 -23
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spice/persistence'
|
2
|
+
|
3
|
+
module Spice
|
4
|
+
class CookbookVersion
|
5
|
+
include Toy::Store
|
6
|
+
include Spice::Persistence
|
7
|
+
extend Spice::Persistence
|
8
|
+
store :memory, {}
|
9
|
+
endpoint "cookbooks"
|
10
|
+
|
11
|
+
attribute :name, String
|
12
|
+
attribute :version, String
|
13
|
+
attribute :definitions, Array, :default => []
|
14
|
+
attribute :attributes, Array, :default => []
|
15
|
+
attribute :files, Array, :default => []
|
16
|
+
attribute :providers, Array, :default => []
|
17
|
+
attribute :metadata, Hash, :default => {}
|
18
|
+
attribute :libraries, Array, :default => []
|
19
|
+
attribute :templates, Array, :default => []
|
20
|
+
attribute :resources, Array, :default => []
|
21
|
+
attribute :attributes, Array, :default => []
|
22
|
+
attribute :json_class, String, :default => "Chef::CookbookVersion"
|
23
|
+
attribute :cookbook_name, String
|
24
|
+
attribute :version, String
|
25
|
+
attribute :recipes, Array, :default => []
|
26
|
+
attribute :root_files, Array, :default => []
|
27
|
+
attribute :chef_type, String, :default => "cookbook_version"
|
28
|
+
|
29
|
+
validates_presence_of :name
|
30
|
+
|
31
|
+
def do_post
|
32
|
+
connection.put("/cookbooks/#{cookbook_name}/#{version}", attributes)
|
33
|
+
end
|
34
|
+
|
35
|
+
def do_put
|
36
|
+
connection.put("/cookbooks/#{cookbook_name}/#{version}", attributes)
|
37
|
+
end
|
38
|
+
|
39
|
+
def do_delete
|
40
|
+
connection.delete("/cookbooks/#{cookbook_name}/#{version}")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/spice/data_bag.rb
CHANGED
@@ -1,132 +1,28 @@
|
|
1
|
+
require 'spice/persistence'
|
2
|
+
|
1
3
|
module Spice
|
2
|
-
class DataBag
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
connection.get("/data")
|
9
|
-
end
|
10
|
-
|
11
|
-
# An alternative format for showing the contents of a data bag
|
12
|
-
# @example Retrieve the id and uri of items in a data bag called "users"
|
13
|
-
# Spice::DataBag["users"] # => {"adam":"http://localhost:4000/data/users/adam"}
|
14
|
-
def self.[](name)
|
15
|
-
connection.get("/data/#{name}")
|
16
|
-
end
|
4
|
+
class DataBag
|
5
|
+
include Toy::Store
|
6
|
+
include Spice::Persistence
|
7
|
+
extend Spice::Persistence
|
8
|
+
store :memory, {}
|
9
|
+
endpoint "data"
|
17
10
|
|
18
|
-
|
19
|
-
|
20
|
-
# Spice::DataBag.show(:name => "users") # => {"adam":"http://localhost:4000/data/users/adam"}
|
21
|
-
#
|
22
|
-
# @param [Hash] options The options hash
|
23
|
-
# @option options [String] :name The name of your data bag
|
24
|
-
def self.show(options={})
|
25
|
-
raise ArgumentError, "Option :name must be present" unless options[:name]
|
26
|
-
name = options.delete(:name)
|
27
|
-
connection.get("/data/#{name}")
|
28
|
-
end
|
29
|
-
|
30
|
-
# Create a a new data bag
|
31
|
-
#
|
32
|
-
# @example
|
33
|
-
# Spice::DataBag.create(:name => "users")
|
34
|
-
#
|
35
|
-
# @param [Hash] options the options hash from which to create a data bag
|
36
|
-
# @option options [String] :name The name of your data bag
|
11
|
+
attribute :name, String
|
12
|
+
attribute :items, Array, :default => []
|
37
13
|
|
38
|
-
|
39
|
-
connection.post("/data", options)
|
40
|
-
end
|
41
|
-
|
42
|
-
# Delete a data bag
|
43
|
-
#
|
44
|
-
# @example
|
45
|
-
# Spice::DataBag.delete(:name => "users")
|
46
|
-
#
|
47
|
-
# @param [Hash] options the options hash from which to delete a data bag
|
48
|
-
# @option options [String] :name The name of your data bag
|
14
|
+
validates_presence_of :name
|
49
15
|
|
50
|
-
def self.
|
51
|
-
|
52
|
-
name = options.delete(:name)
|
53
|
-
connection.delete("/data/#{name}", options)
|
16
|
+
def self.all
|
17
|
+
connection.data_bags
|
54
18
|
end
|
55
19
|
|
56
|
-
|
57
|
-
|
58
|
-
# @example
|
59
|
-
# Spice::DataBag.show_item(:name => "users", :id => "adam")
|
60
|
-
#
|
61
|
-
# @param [Hash] options the options hash from which to create a data bag
|
62
|
-
# @option options [String] :name The name of your data bag
|
63
|
-
# @option options [String] :id The id of the data bag item
|
64
|
-
|
65
|
-
def self.show_item(options={})
|
66
|
-
raise ArgumentError, "Option :name must be present" unless options[:name]
|
67
|
-
raise ArgumentError, "Option :id must be present" unless options[:id]
|
68
|
-
name = options.delete(:name)
|
69
|
-
id = options.delete(:id)
|
70
|
-
connection.get("/data/#{name}/#{id}", options)
|
71
|
-
end
|
72
|
-
|
73
|
-
# Creates a data bag item
|
74
|
-
#
|
75
|
-
# @example
|
76
|
-
# Spice::DataBag.create_item(:name => "users", :id => "adam", :title => "Supreme Awesomer")
|
77
|
-
#
|
78
|
-
# @param [Hash] options the options hash from which to create a data bag
|
79
|
-
# @option options [String] :name The name of your data bag
|
80
|
-
# @option options [String] :id The id of the data bag item
|
81
|
-
#
|
82
|
-
# Any additional keys in the options hash will be used as attributes
|
83
|
-
# to be stored in the data bag item
|
84
|
-
|
85
|
-
def self.create_item(options={})
|
86
|
-
raise ArgumentError, "Option :name must be present" unless options[:name]
|
87
|
-
raise ArgumentError, "Option :id must be present" unless options[:id]
|
88
|
-
name = options.delete(:name)
|
89
|
-
connection.post("/data/#{name}", options)
|
90
|
-
|
20
|
+
def self.get(name)
|
21
|
+
connection.data_bag(name)
|
91
22
|
end
|
92
23
|
|
93
|
-
|
94
|
-
|
95
|
-
# @example
|
96
|
-
# Spice::DataBag.update_item(:name => "users", :id => "adam", :title => "Supreme Awesomer")
|
97
|
-
#
|
98
|
-
# @param [Hash] options the options hash from which to update a data bag
|
99
|
-
# @option options [String] :name The name of your data bag
|
100
|
-
# @option options [String] :id The id of the data bag item
|
101
|
-
#
|
102
|
-
# Any additional keys in the options hash will be used as attributes
|
103
|
-
# to be stored in the data bag item
|
104
|
-
|
105
|
-
def self.update_item(options={})
|
106
|
-
raise ArgumentError, "Option :name must be present" unless options[:name]
|
107
|
-
raise ArgumentError, "Option :id must be present" unless options[:id]
|
108
|
-
name = options.delete(:name)
|
109
|
-
id = options.delete(:id)
|
110
|
-
connection.put("/data/#{name}/#{id}", options)
|
111
|
-
end
|
112
|
-
|
113
|
-
# Delete a data bag item
|
114
|
-
#
|
115
|
-
# @example
|
116
|
-
# Spice::DataBag.delete_item(:name => "users", :id => "adam")
|
117
|
-
#
|
118
|
-
# @param [Hash] options the options hash from which to delete a data bag
|
119
|
-
# @option options [String] :name The name of your data bag
|
120
|
-
# @option options [String] :id The id of the data bag item
|
121
|
-
#
|
122
|
-
|
123
|
-
def self.delete_item(options={})
|
124
|
-
raise ArgumentError, "Option :name must be present" unless options[:name]
|
125
|
-
raise ArgumentError, "Option :id must be present" unless options[:id]
|
126
|
-
name = options.delete(:name)
|
127
|
-
id = options.delete(:id)
|
128
|
-
connection.delete("/data/#{name}/#{id}", options)
|
129
|
-
|
24
|
+
def do_post
|
25
|
+
response = connection.post("/data", attributes)
|
130
26
|
end
|
131
27
|
end
|
132
28
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Spice
|
2
|
+
class DataBagItem
|
3
|
+
include Toy::Store
|
4
|
+
include Spice::Persistence
|
5
|
+
extend Spice::Persistence
|
6
|
+
store :memory, {}
|
7
|
+
endpoint "data"
|
8
|
+
|
9
|
+
attribute :_id, String
|
10
|
+
attribute :data, Hash, :default => {}
|
11
|
+
attribute :name, String
|
12
|
+
|
13
|
+
validates_presence_of :_id, :name, :data
|
14
|
+
|
15
|
+
def self.get(name, id)
|
16
|
+
connection.data_bag_item(name, id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def do_post
|
20
|
+
attrs = data.dup
|
21
|
+
attrs['id'] = attributes['_id']
|
22
|
+
connection.post("/data/#{name}", attrs)
|
23
|
+
end
|
24
|
+
|
25
|
+
def do_put
|
26
|
+
attrs = data.dup
|
27
|
+
attrs['id'] = attributes['_id']
|
28
|
+
connection.put("/data/#{name}/#{_id}", attrs)
|
29
|
+
end
|
30
|
+
|
31
|
+
def do_delete
|
32
|
+
connection.delete("/data/#{name}/#{_id}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/spice/environment.rb
CHANGED
@@ -1,85 +1,21 @@
|
|
1
|
-
|
2
|
-
class Environment < Spice::Chef
|
3
|
-
# Get a list of all data bags in the following syntax
|
4
|
-
# Spice::Environment.all
|
5
|
-
#
|
6
|
-
# @param [Hash] options the options hash. Currently does nothing
|
7
|
-
def self.all(options={})
|
8
|
-
connection.get("/environments")
|
9
|
-
end
|
10
|
-
|
11
|
-
# An alternative format for showing the contents of a data bag
|
12
|
-
# @example Retrieve the id and uri of items in a data bag called "users"
|
13
|
-
# Spice::Environment["users"] # => {"adam":"http://localhost:4000/data/users/adam"}
|
14
|
-
def self.[](name)
|
15
|
-
connection.get("/environments/#{name}")
|
16
|
-
end
|
17
|
-
|
18
|
-
# Show the contents of a data bag
|
19
|
-
# @example Retrieve the id and uri of items in a data bag called "users"
|
20
|
-
# Spice::Environment.show(:name => "users") # => {"adam":"http://localhost:4000/data/users/adam"}
|
21
|
-
#
|
22
|
-
# @param [Hash] options The options hash
|
23
|
-
# @option options [String] :name The name of your data bag
|
24
|
-
def self.show(options={})
|
25
|
-
raise ArgumentError, "Option :name must be present" unless options[:name]
|
26
|
-
name = options.delete(:name)
|
27
|
-
connection.get("/environments/#{name}")
|
28
|
-
end
|
29
|
-
|
30
|
-
# Create a a new data bag
|
31
|
-
#
|
32
|
-
# @example
|
33
|
-
# Spice::Environment.create(:name => "users")
|
34
|
-
#
|
35
|
-
# @param [Hash] options the options hash from which to create a data bag
|
36
|
-
# @option options [String] :name The name of your data bag
|
37
|
-
|
38
|
-
def self.create(options={})
|
39
|
-
options[:chef_type] ||= "environment"
|
40
|
-
options[:json_class] ||= "Chef::Environment"
|
41
|
-
options[:attributes] ||= {}
|
42
|
-
options[:description] ||= ""
|
43
|
-
options[:cookbook_versions] ||= {}
|
44
|
-
connection.post("/environments", options)
|
45
|
-
end
|
46
|
-
|
47
|
-
# Delete a data bag
|
48
|
-
#
|
49
|
-
# @example
|
50
|
-
# Spice::Environment.delete(:name => "users")
|
51
|
-
#
|
52
|
-
# @param [Hash] options the options hash from which to delete a data bag
|
53
|
-
# @option options [String] :name The name of your data bag
|
1
|
+
require 'spice/persistence'
|
54
2
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
#
|
63
|
-
# @example
|
64
|
-
# Spice::Environment.show_item(:name => "users", :id => "adam")
|
65
|
-
#
|
66
|
-
# @param [Hash] options the options hash from which to create a data bag
|
67
|
-
# @option options [String] :name The name of your data bag
|
68
|
-
# @option options [String] :id The id of the data bag item
|
3
|
+
module Spice
|
4
|
+
class Environment
|
5
|
+
include Toy::Store
|
6
|
+
include Spice::Persistence
|
7
|
+
extend Spice::Persistence
|
8
|
+
store :memory, {}
|
9
|
+
endpoint "environments"
|
69
10
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
11
|
+
attribute :name, String
|
12
|
+
attribute :description, String
|
13
|
+
attribute :attrs, Hash, :default => {}
|
14
|
+
attribute :json_class, String, :default => "Chef::Environment"
|
15
|
+
attribute :chef_type, String, :default => "environment"
|
16
|
+
attribute :cookbook_versions, Hash, :default => {}
|
77
17
|
|
78
|
-
|
79
|
-
raise ArgumentError, "Option :name must be present" unless options[:name]
|
80
|
-
name = options.delete(:name)
|
81
|
-
connection.get("/environments/#{name}/cookbooks", options)
|
82
|
-
end
|
18
|
+
validates_presence_of :name, :description
|
83
19
|
|
84
20
|
end
|
85
21
|
end
|
data/lib/spice/error.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Spice
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :http_headers
|
4
|
+
|
5
|
+
def initialize(message, http_headers)
|
6
|
+
@http_headers = Hash[http_headers]
|
7
|
+
super(message)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
class BadRequest < Error
|
13
|
+
end
|
14
|
+
|
15
|
+
class Unauthorized < Error
|
16
|
+
end
|
17
|
+
|
18
|
+
class Forbidden < Error
|
19
|
+
end
|
20
|
+
|
21
|
+
class NotFound < Error
|
22
|
+
end
|
23
|
+
|
24
|
+
class NotAcceptable < Error
|
25
|
+
end
|
26
|
+
|
27
|
+
class Conflict < Error
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/spice/node.rb
CHANGED
@@ -1,40 +1,23 @@
|
|
1
|
+
require 'spice/persistence'
|
2
|
+
|
1
3
|
module Spice
|
2
|
-
class Node
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
class Node
|
5
|
+
include Toy::Store
|
6
|
+
include Spice::Persistence
|
7
|
+
extend Spice::Persistence
|
8
|
+
store :memory, {}
|
9
|
+
endpoint "nodes"
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
raise ArgumentError, "Option :name must be present" unless options[:name]
|
19
|
-
options[:chef_type] ||= "node"
|
20
|
-
options[:json_class] ||= "Chef::Node"
|
21
|
-
options[:attributes] ||= {}
|
22
|
-
options[:overrides] ||= {}
|
23
|
-
options[:defaults] ||={}
|
24
|
-
options[:run_list] ||= []
|
25
|
-
connection.post("/nodes", options)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.update(options={})
|
29
|
-
raise ArgumentError, "Option :name must be present" unless options[:name]
|
30
|
-
name = options.delete(:name)
|
31
|
-
connection.put("/nodes/#{name}", options)
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.delete(options={})
|
35
|
-
raise ArgumentError, "Option :name must be present" unless options[:name]
|
36
|
-
name = options.delete(:name)
|
37
|
-
connection.delete("/nodes/#{name}", options)
|
38
|
-
end
|
11
|
+
attribute :name, String
|
12
|
+
attribute :chef_type, String, :default => "node"
|
13
|
+
attribute :json_class, String, :default => "Chef::Node"
|
14
|
+
attribute :normal, Hash, :default => {}
|
15
|
+
attribute :override, Hash, :default => {}
|
16
|
+
attribute :default, Hash, :default => {}
|
17
|
+
attribute :automatic, Hash, :default => {}
|
18
|
+
attribute :run_list, Array, :default => []
|
19
|
+
|
20
|
+
validates_presence_of :name
|
21
|
+
|
39
22
|
end
|
40
23
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Spice
|
2
|
+
module Persistence
|
3
|
+
def self.included(base)
|
4
|
+
base.after_create :do_post
|
5
|
+
base.after_update :do_put
|
6
|
+
base.after_destroy :do_delete
|
7
|
+
end
|
8
|
+
|
9
|
+
def endpoint(ep=nil)
|
10
|
+
@endpoint = ep if !ep.nil?
|
11
|
+
@endpoint
|
12
|
+
end
|
13
|
+
|
14
|
+
def all(options={})
|
15
|
+
connection.send(endpoint, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(options)
|
19
|
+
connection.send(endpoint, options).first
|
20
|
+
end
|
21
|
+
|
22
|
+
def connection
|
23
|
+
Spice.connection
|
24
|
+
end
|
25
|
+
|
26
|
+
def do_post
|
27
|
+
response = connection.post("/#{self.class.endpoint}", attributes)
|
28
|
+
update_attributes(response.body)
|
29
|
+
response = connection.get("/#{self.class.endpoint}/#{name}")
|
30
|
+
update_attributes(response.body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def do_put
|
34
|
+
connection.put("/#{self.class.endpoint}/#{name}", attributes)
|
35
|
+
end
|
36
|
+
|
37
|
+
def do_delete
|
38
|
+
connection.delete("/#{self.class.endpoint}/#{name}")
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|