spice 1.0.0.rc → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +0 -14
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/TODO.md +2 -1
- data/lib/spice.rb +47 -72
- data/lib/spice/authentication.rb +23 -45
- data/lib/spice/base.rb +104 -0
- data/lib/spice/client.rb +8 -48
- data/lib/spice/config.rb +37 -19
- data/lib/spice/connection.rb +33 -117
- data/lib/spice/connection/clients.rb +26 -6
- data/lib/spice/connection/cookbooks.rb +19 -14
- data/lib/spice/connection/data_bags.rb +31 -20
- data/lib/spice/connection/environments.rb +6 -7
- data/lib/spice/connection/nodes.rb +23 -6
- data/lib/spice/connection/roles.rb +5 -5
- data/lib/spice/connection/search.rb +12 -12
- data/lib/spice/cookbook.rb +3 -29
- data/lib/spice/cookbook_version.rb +9 -61
- data/lib/spice/core_ext/array.rb +7 -0
- data/lib/spice/core_ext/enumerable.rb +11 -0
- data/lib/spice/core_ext/hash.rb +49 -0
- data/lib/spice/core_ext/mash.rb +219 -0
- data/lib/spice/data_bag.rb +3 -37
- data/lib/spice/data_bag_item.rb +7 -47
- data/lib/spice/environment.rb +12 -27
- data/lib/spice/error.rb +22 -10
- data/lib/spice/identity_map.rb +8 -0
- data/lib/spice/node.rb +13 -34
- data/lib/spice/request.rb +73 -11
- data/lib/spice/response/parse_json.rb +8 -3
- data/lib/spice/role.rb +8 -33
- data/lib/spice/version.rb +1 -1
- data/spec/fixtures/client.pem +27 -0
- data/spec/fixtures/clients/create.json +4 -0
- data/spec/fixtures/clients/index.json +5 -0
- data/spec/fixtures/clients/reregister.json +5 -0
- data/spec/fixtures/clients/show.json +8 -0
- data/spec/fixtures/clients/update.json +5 -0
- data/spec/fixtures/cookbook_versions/show.json +108 -0
- data/spec/fixtures/cookbook_versions/update.json +62 -0
- data/spec/fixtures/cookbooks/index-0.10.json +28 -0
- data/spec/fixtures/cookbooks/index-0.9.json +4 -0
- data/spec/fixtures/cookbooks/show-0.10.json +15 -0
- data/spec/fixtures/cookbooks/show-apache2-0.9.json +5 -0
- data/spec/fixtures/cookbooks/show-unicorn-0.9.json +5 -0
- data/spec/fixtures/data_bag_items/create.json +1 -0
- data/spec/fixtures/data_bag_items/show.json +4 -0
- data/spec/fixtures/data_bag_items/update.json +4 -0
- data/spec/fixtures/data_bags/create.json +3 -0
- data/spec/fixtures/data_bags/index.json +3 -0
- data/spec/fixtures/data_bags/show.json +3 -0
- data/spec/fixtures/environments/cookbook.json +15 -0
- data/spec/fixtures/environments/cookbooks.json +28 -0
- data/spec/fixtures/environments/create.json +1 -0
- data/spec/fixtures/environments/delete.json +8 -0
- data/spec/fixtures/environments/index.json +3 -0
- data/spec/fixtures/environments/show.json +8 -0
- data/spec/fixtures/environments/update.json +8 -0
- data/spec/fixtures/nodes/cookbooks.json +41 -0
- data/spec/fixtures/nodes/create.json +1 -0
- data/spec/fixtures/nodes/delete.json +17 -0
- data/spec/fixtures/nodes/index.json +3 -0
- data/spec/fixtures/nodes/show.json +17 -0
- data/spec/fixtures/nodes/update.json +13 -0
- data/spec/fixtures/roles/create.json +1 -0
- data/spec/fixtures/roles/delete.json +11 -0
- data/spec/fixtures/roles/index.json +3 -0
- data/spec/fixtures/roles/show.json +12 -0
- data/spec/fixtures/roles/update.json +11 -0
- data/spec/fixtures/search/client.json +1 -0
- data/spec/fixtures/search/data_bag.json +1 -0
- data/spec/fixtures/search/environment.json +1 -0
- data/spec/fixtures/search/node.json +1 -0
- data/spec/fixtures/search/role.json +1 -0
- data/spec/spec_helper.rb +5 -4
- data/spec/spice/base_spec.rb +34 -0
- data/spec/spice/client_spec.rb +0 -61
- data/spec/spice/config_spec.rb +14 -0
- data/spec/spice/connection/clients_spec.rb +82 -0
- data/spec/spice/connection/cookbooks_spec.rb +86 -0
- data/spec/spice/connection/data_bags_spec.rb +126 -0
- data/spec/spice/connection_spec.rb +63 -0
- data/spec/spice/cookbook_spec.rb +0 -61
- data/spec/spice/data_bag_item_spec.rb +7 -0
- data/spec/spice/data_bag_spec.rb +0 -160
- data/spec/spice/environment_spec.rb +0 -89
- data/spec/spice/node_spec.rb +0 -74
- data/spec/spice/role_spec.rb +0 -61
- data/spec/spice_spec.rb +8 -116
- data/spec/support/helpers.rb +58 -0
- data/spice.gemspec +13 -15
- metadata +227 -87
- data/.watchr +0 -22
- data/lib/spice/connection/authentication.rb +0 -47
- data/lib/spice/mock.rb +0 -46
- data/lib/spice/persistence.rb +0 -62
- data/spec/spice/chef_spec.rb +0 -52
- data/spec/spice/search_spec.rb +0 -2
- data/spec/support/chef_requests.rb +0 -0
- data/spec/support/client_requests.rb +0 -95
- data/spec/support/cookbook_requests.rb +0 -95
- data/spec/support/data_bag_item_requests.rb +0 -138
- data/spec/support/data_bag_requests.rb +0 -95
- data/spec/support/environment_requests.rb +0 -221
- data/spec/support/node_requests.rb +0 -138
- data/spec/support/respond_with_matcher.rb +0 -53
- data/spec/support/role_requests.rb +0 -95
@@ -1,95 +0,0 @@
|
|
1
|
-
def stub_data_bag_list
|
2
|
-
stub_request(:get, "http://localhost:4000/data").
|
3
|
-
to_return(
|
4
|
-
:status => 200,
|
5
|
-
:body => data_bag_list_response
|
6
|
-
)
|
7
|
-
end
|
8
|
-
|
9
|
-
def stub_data_bag_show(status=200)
|
10
|
-
case status
|
11
|
-
when 200
|
12
|
-
stub_request(:get, "http://localhost:4000/data/users").
|
13
|
-
to_return(
|
14
|
-
:status => status,
|
15
|
-
:body => data_bag_show_response
|
16
|
-
)
|
17
|
-
when 404
|
18
|
-
stub_request(:get, "http://localhost:4000/data/users").
|
19
|
-
to_return(
|
20
|
-
:status => status,
|
21
|
-
:body => data_bag_not_found
|
22
|
-
)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def stub_data_bag_create(status=201)
|
27
|
-
case status
|
28
|
-
when 201
|
29
|
-
stub_request(:post, "http://localhost:4000/data").
|
30
|
-
with(
|
31
|
-
:body => data_bag_create_payload ).
|
32
|
-
to_return(
|
33
|
-
:status => status,
|
34
|
-
:body => data_bag_create_response
|
35
|
-
)
|
36
|
-
when 409
|
37
|
-
stub_request(:post, "http://localhost:4000/data").
|
38
|
-
with(
|
39
|
-
:body => data_bag_create_payload ).
|
40
|
-
to_return(
|
41
|
-
:status => status,
|
42
|
-
:body => data_bag_conflict
|
43
|
-
)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def stub_data_bag_delete(status=200)
|
48
|
-
case status
|
49
|
-
when 200
|
50
|
-
stub_request(:delete, "http://localhost:4000/data/users").
|
51
|
-
with(:body => "").
|
52
|
-
to_return(
|
53
|
-
:status => status,
|
54
|
-
:body => data_bag_delete_response
|
55
|
-
)
|
56
|
-
when 404
|
57
|
-
stub_request(:delete, "http://localhost:4000/data/users").
|
58
|
-
with(:body => "").
|
59
|
-
to_return(
|
60
|
-
:status => status,
|
61
|
-
:body => data_bag_not_found
|
62
|
-
)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# payloads and responses
|
67
|
-
|
68
|
-
def data_bag_list_response
|
69
|
-
{ "users" => "http://localhost:4000/data/users",
|
70
|
-
"applications" => "http://localhost:4000/data/applications" }
|
71
|
-
end
|
72
|
-
|
73
|
-
def data_bag_show_response
|
74
|
-
{ "adam" => "http://localhost:4000/data/users/adam" }
|
75
|
-
end
|
76
|
-
|
77
|
-
def data_bag_delete_response
|
78
|
-
{ "name" => "users", "json_class" => "Chef::DataBag", "chef_type" => "data_bag" }
|
79
|
-
end
|
80
|
-
|
81
|
-
def data_bag_not_found
|
82
|
-
{ "error" => [ "Could not load data bag users" ] }
|
83
|
-
end
|
84
|
-
|
85
|
-
def data_bag_conflict
|
86
|
-
{ "error" => [ "Data bag already exists" ] }
|
87
|
-
end
|
88
|
-
|
89
|
-
def data_bag_create_payload
|
90
|
-
{ "name" => "users" }
|
91
|
-
end
|
92
|
-
|
93
|
-
def data_bag_create_response
|
94
|
-
{ "uri" => "http://localhost:4000/data/users" }
|
95
|
-
end
|
@@ -1,221 +0,0 @@
|
|
1
|
-
def stub_environment_list
|
2
|
-
stub_request(:get, "http://localhost:4000/environments").
|
3
|
-
to_return(
|
4
|
-
:status => 200,
|
5
|
-
:body => environment_list_response
|
6
|
-
)
|
7
|
-
end
|
8
|
-
|
9
|
-
def stub_environment_show(status=200)
|
10
|
-
case status
|
11
|
-
when 200
|
12
|
-
stub_request(:get, "http://localhost:4000/environments/dev").
|
13
|
-
to_return(
|
14
|
-
:status => status,
|
15
|
-
:body => environment_show_response
|
16
|
-
)
|
17
|
-
when 404
|
18
|
-
stub_request(:get, "http://localhost:4000/environments/dev").
|
19
|
-
to_return(
|
20
|
-
:status => status,
|
21
|
-
:body => environment_not_found
|
22
|
-
)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def stub_environment_create(status=201)
|
27
|
-
case status
|
28
|
-
when 201
|
29
|
-
stub_request(:post, "http://localhost:4000/environments").
|
30
|
-
with(
|
31
|
-
:body => environment_create_payload ).
|
32
|
-
to_return(
|
33
|
-
:status => status,
|
34
|
-
:body => environment_create_response
|
35
|
-
)
|
36
|
-
when 409
|
37
|
-
stub_request(:post, "http://localhost:4000/environments").
|
38
|
-
with(
|
39
|
-
:body => environment_create_payload ).
|
40
|
-
to_return(
|
41
|
-
:status => status,
|
42
|
-
:body => environment_conflict
|
43
|
-
)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def stub_environment_update(status=200)
|
48
|
-
case status
|
49
|
-
when 200
|
50
|
-
stub_request(:post, "http://localhost:4000/environments/dev").
|
51
|
-
with(
|
52
|
-
:body => environment_udpate_payload ).
|
53
|
-
to_return(
|
54
|
-
:status => status,
|
55
|
-
:body => environment_update_response
|
56
|
-
)
|
57
|
-
when 404
|
58
|
-
stub_request(:post, "http://localhost:4000/environments/dev").
|
59
|
-
with(
|
60
|
-
:body => environment_update_payload ).
|
61
|
-
to_return(
|
62
|
-
:status => status,
|
63
|
-
:body => environment_not_found
|
64
|
-
)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def stub_environment_delete(status=200)
|
69
|
-
case status
|
70
|
-
when 200
|
71
|
-
stub_request(:delete, "http://localhost:4000/environments/dev").
|
72
|
-
with(:body => "").
|
73
|
-
to_return(
|
74
|
-
:status => status,
|
75
|
-
:body => environment_delete_response
|
76
|
-
)
|
77
|
-
when 404
|
78
|
-
stub_request(:delete, "http://localhost:4000/environments/dev").
|
79
|
-
with(:body => "").
|
80
|
-
to_return(
|
81
|
-
:status => status,
|
82
|
-
:body => environment_not_found
|
83
|
-
)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def stub_environment_cookbooks_list
|
88
|
-
stub_request(:get, "http://localhost:4000/environments/dev/cookbooks").
|
89
|
-
to_return(
|
90
|
-
:status => 200,
|
91
|
-
:body => environment_cookbooks_list_response
|
92
|
-
)
|
93
|
-
end
|
94
|
-
|
95
|
-
def stub_environment_cookbook_show(status=200)
|
96
|
-
case status
|
97
|
-
when 200
|
98
|
-
stub_request(:get, "http://localhost:4000/environments/dev/cookbooks/apache").
|
99
|
-
to_return(
|
100
|
-
:status => status,
|
101
|
-
:body => environment_cookbook_show_response
|
102
|
-
)
|
103
|
-
when 404
|
104
|
-
stub_request(:get, "http://localhost:4000/environments/dev/cookbooks/apache").
|
105
|
-
to_return(
|
106
|
-
:status => status,
|
107
|
-
:body => environment_not_found
|
108
|
-
)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
# payloads and responses
|
114
|
-
|
115
|
-
def environment_list_response
|
116
|
-
{ "webserver" => "http://localhost:4000/environments/webserver" }
|
117
|
-
end
|
118
|
-
|
119
|
-
def environment_show_response
|
120
|
-
{
|
121
|
-
"name" => "dev",
|
122
|
-
"attributes" => {
|
123
|
-
},
|
124
|
-
"json_class" => "Chef::Environment",
|
125
|
-
"description" => "",
|
126
|
-
"cookbook_versions" => {
|
127
|
-
},
|
128
|
-
"chef_type" => "environment"
|
129
|
-
}
|
130
|
-
end
|
131
|
-
|
132
|
-
def environment_create_response
|
133
|
-
{ "uri" => "http://localhost:4000/environments/dev" }
|
134
|
-
end
|
135
|
-
|
136
|
-
def environment_delete_response
|
137
|
-
{
|
138
|
-
"name" => "dev",
|
139
|
-
"attributes" => {
|
140
|
-
},
|
141
|
-
"json_class" => "Chef::Environment",
|
142
|
-
"description" => "",
|
143
|
-
"cookbook_versions" => {
|
144
|
-
},
|
145
|
-
"chef_type" => "environment"
|
146
|
-
}
|
147
|
-
end
|
148
|
-
|
149
|
-
def environment_update_response
|
150
|
-
{
|
151
|
-
"name" => "dev",
|
152
|
-
"attributes" => {
|
153
|
-
},
|
154
|
-
"json_class" => "Chef::Environment",
|
155
|
-
"description" => "The Dev Environment",
|
156
|
-
"cookbook_versions" => {
|
157
|
-
},
|
158
|
-
"chef_type" => "environment"
|
159
|
-
}
|
160
|
-
end
|
161
|
-
|
162
|
-
|
163
|
-
def environment_cookbooks_list_response
|
164
|
-
{
|
165
|
-
"apache2" => {
|
166
|
-
"url" => "http://localhost:4000/cookbooks/apache2",
|
167
|
-
"versions" => [
|
168
|
-
{ "url" => "http://localhost:4000/cookbooks/apache2/5.1.0", "version" => "5.1.0" },
|
169
|
-
{ "url" => "http://localhost:4000/cookbooks/apache2/4.2.0", "version" => "4.2.0" }
|
170
|
-
]
|
171
|
-
},
|
172
|
-
"nginx" => {
|
173
|
-
"url" => "http://localhost:4000/cookbooks/nginx",
|
174
|
-
"versions" => [
|
175
|
-
{ "url" => "http://localhost:4000/cookbooks/nginx/1.0.0", "version" => "1.0.0" },
|
176
|
-
{ "url" => "http://localhost:4000/cookbooks/nginx/0.3.0", "version" => "0.3.0" }
|
177
|
-
]
|
178
|
-
}
|
179
|
-
}
|
180
|
-
end
|
181
|
-
|
182
|
-
def environment_cookbook_show_response
|
183
|
-
{
|
184
|
-
"apache2" => {
|
185
|
-
"url" => "http://localhost:4000/cookbooks/apache2",
|
186
|
-
"versions" => [
|
187
|
-
{ "url" => "http://localhost:4000/cookbooks/apache2/5.1.0", "version" => "5.1.0" },
|
188
|
-
{"url" => "http://localhost:4000/cookbooks/apache2/4.2.0", "version" => "4.2.0" }
|
189
|
-
]
|
190
|
-
}
|
191
|
-
}
|
192
|
-
end
|
193
|
-
|
194
|
-
def environment_not_found
|
195
|
-
{ "error" => [ "Could not load environment env" ] }
|
196
|
-
end
|
197
|
-
|
198
|
-
def environment_cookbook_not_found
|
199
|
-
{ "error" => [ "Could not load environment env cookbook apache" ] }
|
200
|
-
end
|
201
|
-
|
202
|
-
def environment_conflict
|
203
|
-
{ "error" => [ "environments bag already exists" ] }
|
204
|
-
end
|
205
|
-
|
206
|
-
def environment_create_payload
|
207
|
-
{
|
208
|
-
"name" => "dev",
|
209
|
-
"attributes" => {
|
210
|
-
},
|
211
|
-
"json_class" => "Chef::Environment",
|
212
|
-
"description" => "",
|
213
|
-
"cookbook_versions" => {
|
214
|
-
},
|
215
|
-
"chef_type" => "environment"
|
216
|
-
}
|
217
|
-
end
|
218
|
-
|
219
|
-
def environment_update_payload
|
220
|
-
{ "description" => "The Dev Environment" }
|
221
|
-
end
|
@@ -1,138 +0,0 @@
|
|
1
|
-
def stub_node_list
|
2
|
-
stub_request(:get, "http://localhost:4000/nodes").
|
3
|
-
to_return(
|
4
|
-
:status => 200,
|
5
|
-
:body => node_list_response
|
6
|
-
)
|
7
|
-
end
|
8
|
-
|
9
|
-
def stub_node_show(status=200)
|
10
|
-
case status
|
11
|
-
when 200
|
12
|
-
stub_request(:get, "http://localhost:4000/nodes/testnode").
|
13
|
-
to_return(
|
14
|
-
:status => status,
|
15
|
-
:body => node_show_response
|
16
|
-
)
|
17
|
-
when 404
|
18
|
-
stub_request(:get, "http://localhost:4000/nodes/testnode").
|
19
|
-
to_return(
|
20
|
-
:status => status,
|
21
|
-
:body => node_not_found
|
22
|
-
)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def stub_node_create(status=201)
|
27
|
-
case status
|
28
|
-
when 201
|
29
|
-
stub_request(:post, "http://localhost:4000/nodes").
|
30
|
-
with(
|
31
|
-
:body => node_create_payload ).
|
32
|
-
to_return(
|
33
|
-
:status => status,
|
34
|
-
:body => node_create_response
|
35
|
-
)
|
36
|
-
when 409
|
37
|
-
stub_request(:post, "http://localhost:4000/nodes").
|
38
|
-
with(
|
39
|
-
:body => node_create_payload ).
|
40
|
-
to_return(
|
41
|
-
:status => status,
|
42
|
-
:body => node_conflict
|
43
|
-
)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def stub_node_create_with_run_list
|
48
|
-
stub_request(:post, "http://localhost:4000/nodes").
|
49
|
-
with(
|
50
|
-
:body => node_create_payload_with_run_list ).
|
51
|
-
to_return(
|
52
|
-
:status => 201,
|
53
|
-
:body => node_create_response_with_run_list
|
54
|
-
)
|
55
|
-
end
|
56
|
-
|
57
|
-
def stub_node_delete(status=200)
|
58
|
-
case status
|
59
|
-
when 200
|
60
|
-
stub_request(:delete, "http://localhost:4000/nodes/testnode").
|
61
|
-
with(:body => "").
|
62
|
-
to_return(
|
63
|
-
:status => status,
|
64
|
-
:body => node_delete_response
|
65
|
-
)
|
66
|
-
when 404
|
67
|
-
stub_request(:delete, "http://localhost:4000/nodes/testnode").
|
68
|
-
with(:body => "").
|
69
|
-
to_return(
|
70
|
-
:status => status,
|
71
|
-
:body => node_not_found
|
72
|
-
)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# payloads and responses
|
77
|
-
|
78
|
-
def node_list_response
|
79
|
-
{ "testnode" => "http://localhost:4000/nodes/testnode" }
|
80
|
-
end
|
81
|
-
|
82
|
-
def node_show_response
|
83
|
-
{ "adam" => "http://localhost:4000/nodes/testnode" }
|
84
|
-
end
|
85
|
-
|
86
|
-
def node_delete_response
|
87
|
-
{
|
88
|
-
"normal" => {},
|
89
|
-
"name" => "foo",
|
90
|
-
"override" => {},
|
91
|
-
"default" => {},
|
92
|
-
"json_class" => "Chef::Node",
|
93
|
-
"automatic" => {},
|
94
|
-
"run_list" => [],
|
95
|
-
"chef_type" => "node"
|
96
|
-
}
|
97
|
-
end
|
98
|
-
|
99
|
-
def node_not_found
|
100
|
-
{ "error" => [ "Could not load node testnode" ] }
|
101
|
-
end
|
102
|
-
|
103
|
-
def node_conflict
|
104
|
-
{ "error" => [ "Node already exists" ] }
|
105
|
-
end
|
106
|
-
|
107
|
-
def node_create_payload
|
108
|
-
{
|
109
|
-
"name" => "testnode",
|
110
|
-
"chef_type" => "node",
|
111
|
-
"json_class" => "Chef::Node",
|
112
|
-
"attributes" => {},
|
113
|
-
"overrides" => {},
|
114
|
-
"defaults" => {},
|
115
|
-
"run_list" => []
|
116
|
-
}
|
117
|
-
end
|
118
|
-
|
119
|
-
def node_create_payload_with_run_list
|
120
|
-
{
|
121
|
-
"name" => "testnode",
|
122
|
-
"chef_type" => "node",
|
123
|
-
"json_class" => "Chef::Node",
|
124
|
-
"attributes" => {},
|
125
|
-
"overrides" => {},
|
126
|
-
"defaults" => {},
|
127
|
-
"run_list" => [ "recipe[unicorn]" ]
|
128
|
-
}
|
129
|
-
end
|
130
|
-
|
131
|
-
def node_create_response_with_run_list
|
132
|
-
{ "uri" => "http://localhost:4000/nodes/testnode" }
|
133
|
-
end
|
134
|
-
|
135
|
-
def node_create_response
|
136
|
-
{ "private_key"=>"-----BEGIN RSA PRIVATE KEY-----",
|
137
|
-
"uri"=>"http://localhost:4000/nodes/testnode" }
|
138
|
-
end
|