ridley 0.7.0.beta → 0.7.0.rc1

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.
Files changed (54) hide show
  1. data/README.md +51 -54
  2. data/lib/ridley.rb +7 -13
  3. data/lib/ridley/client.rb +251 -0
  4. data/lib/ridley/connection.rb +32 -188
  5. data/lib/ridley/middleware/chef_auth.rb +4 -1
  6. data/lib/ridley/resource.rb +36 -42
  7. data/lib/ridley/resources.rb +3 -0
  8. data/lib/ridley/resources/{client.rb → client_resource.rb} +7 -20
  9. data/lib/ridley/resources/cookbook_resource.rb +121 -0
  10. data/lib/ridley/resources/{data_bag_item.rb → data_bag_item_resource.rb} +52 -63
  11. data/lib/ridley/resources/data_bag_resource.rb +74 -0
  12. data/lib/ridley/resources/encrypted_data_bag_item_resource.rb +55 -0
  13. data/lib/ridley/resources/{environment.rb → environment_resource.rb} +8 -21
  14. data/lib/ridley/resources/{node.rb → node_resource.rb} +24 -37
  15. data/lib/ridley/resources/{role.rb → role_resource.rb} +1 -14
  16. data/lib/ridley/resources/sandbox_resource.rb +86 -0
  17. data/lib/ridley/resources/search.rb +24 -55
  18. data/lib/ridley/sandbox_uploader.rb +118 -0
  19. data/lib/ridley/ssh.rb +2 -2
  20. data/lib/ridley/ssh/worker.rb +2 -1
  21. data/lib/ridley/version.rb +1 -1
  22. data/ridley.gemspec +1 -1
  23. data/spec/acceptance/bootstrapping_spec.rb +1 -1
  24. data/spec/acceptance/client_resource_spec.rb +18 -20
  25. data/spec/acceptance/cookbook_resource_spec.rb +4 -22
  26. data/spec/acceptance/data_bag_item_resource_spec.rb +5 -7
  27. data/spec/acceptance/data_bag_resource_spec.rb +4 -6
  28. data/spec/acceptance/environment_resource_spec.rb +14 -16
  29. data/spec/acceptance/node_resource_spec.rb +12 -14
  30. data/spec/acceptance/role_resource_spec.rb +13 -15
  31. data/spec/acceptance/sandbox_resource_spec.rb +7 -9
  32. data/spec/acceptance/search_resource_spec.rb +6 -8
  33. data/spec/support/shared_examples/ridley_resource.rb +23 -22
  34. data/spec/unit/ridley/client_spec.rb +153 -0
  35. data/spec/unit/ridley/connection_spec.rb +8 -221
  36. data/spec/unit/ridley/resources/{client_spec.rb → client_resource_spec.rb} +4 -4
  37. data/spec/unit/ridley/resources/cookbook_resource_spec.rb +5 -0
  38. data/spec/unit/ridley/resources/{data_bag_item_spec.rb → data_bag_item_resource_spec.rb} +2 -2
  39. data/spec/unit/ridley/resources/{data_bag_spec.rb → data_bag_resource_spec.rb} +3 -3
  40. data/spec/unit/ridley/resources/{environment_spec.rb → environment_resource_spec.rb} +4 -4
  41. data/spec/unit/ridley/resources/{node_spec.rb → node_resource_spec.rb} +4 -4
  42. data/spec/unit/ridley/resources/{role_spec.rb → role_resource_spec.rb} +3 -3
  43. data/spec/unit/ridley/resources/sandbox_resource_spec.rb +172 -0
  44. data/spec/unit/ridley/resources/search_spec.rb +34 -30
  45. data/spec/unit/ridley/sandbox_uploader_spec.rb +99 -0
  46. data/spec/unit/ridley/ssh_spec.rb +2 -2
  47. data/spec/unit/ridley_spec.rb +4 -12
  48. metadata +36 -28
  49. data/lib/ridley/dsl.rb +0 -58
  50. data/lib/ridley/resources/cookbook.rb +0 -51
  51. data/lib/ridley/resources/data_bag.rb +0 -81
  52. data/lib/ridley/resources/encrypted_data_bag_item.rb +0 -54
  53. data/lib/ridley/resources/sandbox.rb +0 -154
  54. data/spec/unit/ridley/resources/cookbook_spec.rb +0 -5
@@ -4,235 +4,22 @@ describe Ridley::Connection do
4
4
  let(:server_url) { "https://api.opscode.com" }
5
5
  let(:client_name) { "reset" }
6
6
  let(:client_key) { fixtures_path.join("reset.pem").to_s }
7
- let(:organization) { "vialstudios" }
8
- let(:encrypted_data_bag_secret_path) { fixtures_path.join("reset.pem").to_s }
9
-
10
- let(:config) do
11
- {
12
- server_url: server_url,
13
- client_name: client_name,
14
- client_key: client_key,
15
- organization: organization,
16
- encrypted_data_bag_secret_path: encrypted_data_bag_secret_path
17
- }
18
- end
19
-
20
- it "exposes its options publicly" do
21
- described_class::OPTIONS.should be_a Array
22
- end
23
-
24
- describe "ClassMethods" do
25
- subject { Ridley::Connection }
26
-
27
- describe "::initialize" do
28
- let(:server_url) { "https://api.opscode.com/some_path" }
29
-
30
- describe "parsing the 'server_url' option" do
31
- before(:each) do
32
- @conn = subject.new(
33
- server_url: server_url,
34
- client_name: client_name,
35
- client_key: client_key
36
- )
37
- end
38
-
39
- it "assigns a 'host' attribute from the given 'server_url' option" do
40
- @conn.host.should eql("api.opscode.com")
41
- end
42
-
43
- it "assigns a 'scheme' attribute from the given 'server_url' option" do
44
- @conn.scheme.should eql("https")
45
- end
46
-
47
- it "sets a 'path_prefix' to the root of the given 'server_url' option" do
48
- @conn.path_prefix.should eql("/")
49
- end
50
- end
51
-
52
- describe "specifying an 'organization' option" do
53
- before(:each) do
54
- @conn = subject.new(
55
- server_url: server_url,
56
- client_name: client_name,
57
- client_key: client_key,
58
- organization: organization
59
- )
60
- end
61
-
62
- it "assigns the value of the 'organization' option to an 'organization' attribute" do
63
- @conn.organization.should eql(organization)
64
- end
65
-
66
- it "sets the 'path_prefix' of the connection the organization sub URI" do
67
- @conn.path_prefix.should eql("/organizations/#{organization}")
68
- end
69
- end
70
-
71
- describe "with a server_url containing an organization" do
72
- before(:each) do
73
- @conn = subject.new(
74
- server_url: "#{server_url}/organizations/#{organization}",
75
- client_name: client_name,
76
- client_key: client_key
77
- )
78
- end
79
-
80
- it "gets the host data from the server_url" do
81
- @conn.host.should eql("api.opscode.com")
82
- @conn.scheme.should eql("https")
83
- end
84
-
85
- it "assigns the value of the 'organization' option to an 'organization' attribute" do
86
- @conn.organization.should eql(organization)
87
- end
88
-
89
- it "sets the 'path_prefix' of the connection the organization sub URI" do
90
- @conn.path_prefix.should eql("/organizations/#{organization}")
91
- end
92
- end
93
-
94
- it "raises 'ArgumentError' if a value for server_url is not given" do
95
- lambda {
96
- subject.new(
97
- client_name: client_name,
98
- client_key: client_key
99
- )
100
- }.should raise_error(ArgumentError, "Missing required option(s): 'server_url'")
101
- end
102
-
103
- it "raises if a value for client_name is not given" do
104
- lambda {
105
- subject.new(
106
- server_url: server_url,
107
- client_key: client_key
108
- )
109
- }.should raise_error(ArgumentError, "Missing required option(s): 'client_name'")
110
- end
111
-
112
- it "raises if a value for client_key is not given" do
113
- lambda {
114
- subject.new(
115
- server_url: server_url,
116
- client_name: client_name
117
- )
118
- }.should raise_error(ArgumentError, "Missing required option(s): 'client_key'")
119
- end
120
-
121
- it "raises a ClientKeyFileNotFound if the filepath for client_key is not found" do
122
- config[:client_key] = "/tmp/nofile.xxsa"
123
-
124
- lambda {
125
- subject.new(config)
126
- }.should raise_error(Ridley::Errors::ClientKeyFileNotFound)
127
- end
128
-
129
- it "expands the path of the client_key" do
130
- config[:client_key] = "~/"
131
-
132
- subject.new(config).client_key.should_not == "~/"
133
- end
134
- end
135
-
136
- describe "::sync" do
137
- it "raises a Ridley::Errors::InternalError if no block is given" do
138
- lambda {
139
- subject.sync(config)
140
- }.should raise_error(Ridley::Errors::InternalError)
141
- end
142
- end
143
- end
144
7
 
145
8
  subject do
146
- Ridley::Connection.new(config)
9
+ described_class.new(server_url, client_name, client_key)
147
10
  end
148
11
 
149
- describe "#sync" do
150
- it "raises a Ridley::Errors::InternalError if no block is given" do
151
- lambda {
152
- subject.sync
153
- }.should raise_error(Ridley::Errors::InternalError)
154
- end
155
-
156
- describe "HTTP Request" do
157
- describe "#get" do
158
- it "appends the given path to the connection's server_uri path and sends a get request to it" do
159
- stub_request(:get, subject.build_url("cookbooks")).
160
- to_return(status: 200, body: "{}")
161
-
162
- subject.get("cookbooks")
163
- end
164
- end
165
-
166
- describe "#put" do
167
- it "appends the given path to the connection's server_uri path and sends a put request to it" do
168
- stub_request(:put, subject.build_url("cookbooks")).
169
- with(body: "content").
170
- to_return(status: 200, body: "{}")
171
-
172
- subject.put("cookbooks", "content")
173
- end
174
- end
175
-
176
- describe "#post" do
177
- it "appends the given path to the connection's server_uri path and sends a post request to it" do
178
- stub_request(:post, subject.build_url("cookbooks")).
179
- with(body: "content").
180
- to_return(status: 200, body: "{}")
181
-
182
- subject.post("cookbooks", "content")
183
- end
184
- end
185
-
186
- describe "#delete" do
187
- it "appends the given path to the connection's server_uri path and sends a delete request to it" do
188
- stub_request(:delete, subject.build_url("cookbooks/nginx")).
189
- to_return(status: 200, body: "{}")
190
-
191
- subject.delete("cookbooks/nginx")
192
- end
193
- end
194
- end
195
-
196
- describe "api_type" do
197
- it "returns :foss if the organization is not set" do
198
- subject.stub(:organization).and_return(nil)
199
-
200
- subject.api_type.should eql(:foss)
201
- end
202
-
203
- it "returns :hosted if the organization is set" do
204
- subject.stub(:organization).and_return("vialstudios")
205
-
206
- subject.api_type.should eql(:hosted)
207
- end
208
- end
209
- end
210
-
211
- describe "#encrypted_data_bag_secret" do
212
- it "returns a string" do
213
- subject.encrypted_data_bag_secret.should be_a(String)
214
- end
215
-
216
- context "when a encrypted_data_bag_secret_path is not provided" do
217
- before(:each) do
218
- subject.stub(:encrypted_data_bag_secret_path) { nil }
219
- end
12
+ describe "#api_type" do
13
+ it "returns :foss if the organization is not set" do
14
+ subject.stub(:organization).and_return(nil)
220
15
 
221
- it "returns nil" do
222
- subject.encrypted_data_bag_secret.should be_nil
223
- end
16
+ subject.api_type.should eql(:foss)
224
17
  end
225
18
 
226
- context "when the file is not found at the given encrypted_data_bag_secret_path" do
227
- before(:each) do
228
- subject.stub(:encrypted_data_bag_secret_path) { fixtures_path.join("not.txt").to_s }
229
- end
19
+ it "returns :hosted if the organization is set" do
20
+ subject.stub(:organization).and_return("vialstudios")
230
21
 
231
- it "raises an EncryptedDataBagSecretNotFound erorr" do
232
- lambda {
233
- subject.encrypted_data_bag_secret
234
- }.should raise_error(Ridley::Errors::EncryptedDataBagSecretNotFound)
235
- end
22
+ subject.api_type.should eql(:hosted)
236
23
  end
237
24
  end
238
25
  end
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Ridley::Client do
4
- it_behaves_like "a Ridley Resource", Ridley::Client
3
+ describe Ridley::ClientResource do
4
+ it_behaves_like "a Ridley Resource", Ridley::ClientResource
5
5
 
6
6
  let(:connection) { double('connection') }
7
7
 
8
8
  describe "ClassMethods" do
9
- subject { Ridley::Client }
9
+ subject { Ridley::ClientResource }
10
10
 
11
11
  describe "::regenerate_key" do
12
12
  let(:client) { double('client', name: "ridley-test") }
@@ -28,7 +28,7 @@ describe Ridley::Client do
28
28
  end
29
29
 
30
30
  subject do
31
- Ridley::Client.new(connection, name: "ridley-test", admin: false)
31
+ Ridley::ClientResource.new(connection, name: "ridley-test", admin: false)
32
32
  end
33
33
 
34
34
  describe "#regenerate_key" do
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ridley::CookbookResource do
4
+ pending
5
+ end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Ridley::DataBagItem do
3
+ describe Ridley::DataBagItemResource do
4
4
  let(:connection) { double('connection') }
5
5
  let(:data_bag) { double('data_bag') }
6
6
 
7
- subject { Ridley::DataBagItem.new(connection, data_bag) }
7
+ subject { Ridley::DataBagItemResource.new(connection, data_bag) }
8
8
 
9
9
  describe "::from_hash" do
10
10
  context "when JSON has a 'raw_data' field" do
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Ridley::DataBag do
4
- it_behaves_like "a Ridley Resource", Ridley::DataBag
3
+ describe Ridley::DataBagResource do
4
+ it_behaves_like "a Ridley Resource", Ridley::DataBagResource
5
5
 
6
6
  let(:connection) { double('connection') }
7
7
 
8
8
  describe "ClassMethods" do
9
- subject { Ridley::DataBag }
9
+ subject { Ridley::DataBagResource }
10
10
 
11
11
  describe "::create_item" do
12
12
  pending
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Ridley::Environment do
4
- it_behaves_like "a Ridley Resource", Ridley::Environment
3
+ describe Ridley::EnvironmentResource do
4
+ it_behaves_like "a Ridley Resource", Ridley::EnvironmentResource
5
5
 
6
6
  let(:connection) { double("connection") }
7
7
 
@@ -34,7 +34,7 @@ describe Ridley::Environment do
34
34
  end
35
35
 
36
36
  describe "ClassMethods" do
37
- subject { Ridley::Environment }
37
+ subject { Ridley::EnvironmentResource }
38
38
 
39
39
  describe "::initialize" do
40
40
  before(:each) do
@@ -73,7 +73,7 @@ describe Ridley::Environment do
73
73
 
74
74
  let(:connection) { double('connection') }
75
75
 
76
- subject { Ridley::Environment.new(connection) }
76
+ subject { Ridley::EnvironmentResource.new(connection) }
77
77
 
78
78
  describe "#set_override_attribute" do
79
79
  it "sets an override node attribute at the nested path" do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Ridley::Node do
4
- it_behaves_like "a Ridley Resource", Ridley::Node
3
+ describe Ridley::NodeResource do
4
+ it_behaves_like "a Ridley Resource", Ridley::NodeResource
5
5
 
6
6
  let(:connection) do
7
7
  double('conn',
@@ -15,7 +15,7 @@ describe Ridley::Node do
15
15
  end
16
16
 
17
17
  describe "ClassMethods" do
18
- subject { Ridley::Node }
18
+ subject { Ridley::NodeResource }
19
19
 
20
20
  describe "::bootstrap" do
21
21
  let(:boot_options) do
@@ -48,7 +48,7 @@ describe Ridley::Node do
48
48
  end
49
49
  end
50
50
 
51
- subject { Ridley::Node.new(connection) }
51
+ subject { Ridley::NodeResource.new(connection) }
52
52
 
53
53
  describe "#set_chef_attribute" do
54
54
  it "sets an normal node attribute at the nested path" do
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Ridley::Role do
4
- it_behaves_like "a Ridley Resource", Ridley::Role
3
+ describe Ridley::RoleResource do
4
+ it_behaves_like "a Ridley Resource", Ridley::RoleResource
5
5
 
6
6
  let(:connection) { double("connection") }
7
7
 
8
- subject { Ridley::Role.new(connection) }
8
+ subject { Ridley::RoleResource.new(connection) }
9
9
 
10
10
  describe "#set_override_attribute" do
11
11
  it "sets an override node attribute at the nested path" do
@@ -0,0 +1,172 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ridley::SandboxResource do
4
+ let(:server_url) { "https://api.opscode.com/organizations/vialstudios" }
5
+ let(:client_name) { "reset" }
6
+ let(:client_key) { "/Users/reset/.chef/reset.pem" }
7
+
8
+ let(:sandbox) do
9
+ Ridley.new(
10
+ server_url: server_url,
11
+ client_name: client_name,
12
+ client_key: client_key
13
+ ).sandbox
14
+ end
15
+
16
+ describe "ClassMethods" do
17
+ describe "::create" do
18
+ let(:checksums) { Hash.new }
19
+
20
+ before(:each) do
21
+ stub_request(:post, File.join(server_url, "sandboxes")).
22
+ with(body: MultiJson.encode(checksums: checksums)).
23
+ to_return(status: 200, body: {
24
+ uri: "https://api.opscode.com/organizations/vialstudios/sandboxes/bd091b150b0a4578b97771af6abf3e05",
25
+ checksums: {},
26
+ sandbox_id: "bd091b150b0a4578b97771af6abf3e05"
27
+ })
28
+ end
29
+
30
+ subject { sandbox.create }
31
+
32
+ it "returns a SandboxResource" do
33
+ subject.should be_a(Ridley::SandboxResource)
34
+ end
35
+
36
+ it "has an 'is_completed' value of false" do
37
+ subject.is_completed.should be_false
38
+ end
39
+
40
+ it "has an empty Hash of checksums" do
41
+ subject.checksums.should be_a(Hash)
42
+ subject.checksums.should be_empty
43
+ end
44
+
45
+ it "has a value for 'uri'" do
46
+ subject.uri.should eql("https://api.opscode.com/organizations/vialstudios/sandboxes/bd091b150b0a4578b97771af6abf3e05")
47
+ end
48
+
49
+ it "has a sandbox_id" do
50
+ subject.sandbox_id.should eql("bd091b150b0a4578b97771af6abf3e05")
51
+ end
52
+
53
+ context "when given an array of checksums" do
54
+ let(:checksums) do
55
+ {
56
+ "385ea5490c86570c7de71070bce9384a" => nil,
57
+ "f6f73175e979bd90af6184ec277f760c" => nil,
58
+ "2e03dd7e5b2e6c8eab1cf41ac61396d5" => nil
59
+ }
60
+ end
61
+ let(:checksum_array) { checksums.keys }
62
+
63
+ before(:each) do
64
+ stub_request(:post, File.join(server_url, "sandboxes")).
65
+ with(body: MultiJson.encode(checksums: checksums)).
66
+ to_return(status: 200, body: {
67
+ "uri" => "https://api.opscode.com/organizations/vialstudios/sandboxes/bd091b150b0a4578b97771af6abf3e05",
68
+ "checksums" => {
69
+ "385ea5490c86570c7de71070bce9384a" => {
70
+ "url" => "https://s3.amazonaws.com/opscode-platform-production-data/organization",
71
+ "needs_upload" => true
72
+ },
73
+ "f6f73175e979bd90af6184ec277f760c" => {
74
+ "url" => "https://s3.amazonaws.com/opscode-platform-production-data/organization",
75
+ "needs_upload" => true
76
+ },
77
+ "2e03dd7e5b2e6c8eab1cf41ac61396d5" => {
78
+ "url" => "https://s3.amazonaws.com/opscode-platform-production-data/organization",
79
+ "needs_upload" => true
80
+ },
81
+ },
82
+ "sandbox_id" => "bd091b150b0a4578b97771af6abf3e05"
83
+ })
84
+ end
85
+
86
+ subject { sandbox.create(checksum_array) }
87
+
88
+ it "has a Hash of checksums with each of the given checksum ids" do
89
+ subject.checksums.should have(checksum_array.length).checksums
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ subject do
96
+ sandbox.new(
97
+ "uri" => "https://api.opscode.com/organizations/vialstudios/sandboxes/bd091b150b0a4578b97771af6abf3e05",
98
+ "checksums" => {
99
+ "385ea5490c86570c7de71070bce9384a" => {
100
+ "url" => "https://s3.amazonaws.com/opscode-platform-production-data/organization",
101
+ "needs_upload" => true
102
+ },
103
+ "f6f73175e979bd90af6184ec277f760c" => {
104
+ "url" => "https://s3.amazonaws.com/opscode-platform-production-data/organization",
105
+ "needs_upload" => true
106
+ },
107
+ "2e03dd7e5b2e6c8eab1cf41ac61396d5" => {
108
+ "url" => "https://s3.amazonaws.com/opscode-platform-production-data/organization",
109
+ "needs_upload" => true
110
+ },
111
+ },
112
+ "sandbox_id" => "bd091b150b0a4578b97771af6abf3e05"
113
+ )
114
+ end
115
+
116
+ describe "#commit" do
117
+ context "on successful commit" do
118
+ before(:each) do
119
+ stub_request(:put, File.join(server_url, "sandboxes", "bd091b150b0a4578b97771af6abf3e05")).
120
+ with(body: MultiJson.encode(is_completed: true)).
121
+ to_return(status: 200, body: {
122
+ is_completed: true,
123
+ _rev: "1-bbc8a96f7486aeba2b562d382142fd68",
124
+ create_time: "2013-01-16T01:43:43+00:00",
125
+ guid: "bd091b150b0a4578b97771af6abf3e05",
126
+ json_class: "Chef::Sandbox",
127
+ name: "bd091b150b0a4578b97771af6abf3e05",
128
+ checksums: [],
129
+ chef_type: "sandbox"
130
+ })
131
+ end
132
+
133
+ it "has an 'is_completed' value of true" do
134
+ subject.commit
135
+
136
+ subject.is_completed.should be_true
137
+ end
138
+ end
139
+
140
+ context "on commit failure" do
141
+ before(:each) do
142
+ stub_request(:put, File.join(server_url, "sandboxes", "bd091b150b0a4578b97771af6abf3e05")).
143
+ with(body: MultiJson.encode(is_completed: true)).
144
+ to_return(status: 200, body: {
145
+ is_completed: false,
146
+ _rev: "1-bbc8a96f7486aeba2b562d382142fd68",
147
+ create_time: "2013-01-16T01:43:43+00:00",
148
+ guid: "bd091b150b0a4578b97771af6abf3e05",
149
+ json_class: "Chef::Sandbox",
150
+ name: "bd091b150b0a4578b97771af6abf3e05",
151
+ checksums: [],
152
+ chef_type: "sandbox"
153
+ })
154
+ end
155
+
156
+ it "has an 'is_completed' value of false" do
157
+ subject.commit
158
+
159
+ subject.is_completed.should be_false
160
+ end
161
+ end
162
+ end
163
+
164
+ describe "#upload" do
165
+ it "delegates self to SandboxUploader.upload" do
166
+ checksums = double('checksums')
167
+ Ridley::SandboxUploader.should_receive(:upload).with(subject, checksums)
168
+
169
+ subject.upload(checksums)
170
+ end
171
+ end
172
+ end