gcloud 0.1.0 → 0.1.1

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 (67) hide show
  1. checksums.yaml +13 -5
  2. data/AUTHENTICATION.md +71 -0
  3. data/CHANGELOG.md +5 -0
  4. data/README.md +10 -15
  5. data/lib/gcloud.rb +30 -0
  6. data/lib/gcloud/backoff.rb +3 -0
  7. data/lib/gcloud/credentials.rb +47 -30
  8. data/lib/gcloud/datastore.rb +246 -15
  9. data/lib/gcloud/datastore/connection.rb +4 -2
  10. data/lib/gcloud/datastore/credentials.rb +3 -1
  11. data/lib/gcloud/datastore/dataset.rb +130 -25
  12. data/lib/gcloud/datastore/dataset/lookup_results.rb +1 -0
  13. data/lib/gcloud/datastore/dataset/query_results.rb +7 -5
  14. data/lib/gcloud/datastore/entity.rb +99 -17
  15. data/lib/gcloud/datastore/errors.rb +13 -2
  16. data/lib/gcloud/datastore/key.rb +133 -2
  17. data/lib/gcloud/datastore/properties.rb +6 -1
  18. data/lib/gcloud/datastore/proto.rb +2 -1
  19. data/lib/gcloud/datastore/query.rb +4 -4
  20. data/lib/gcloud/datastore/transaction.rb +3 -0
  21. data/lib/gcloud/storage.rb +280 -13
  22. data/lib/gcloud/storage/bucket.rb +248 -11
  23. data/lib/gcloud/storage/bucket/acl.rb +631 -4
  24. data/lib/gcloud/storage/bucket/list.rb +1 -0
  25. data/lib/gcloud/storage/connection.rb +1 -0
  26. data/lib/gcloud/storage/credentials.rb +3 -1
  27. data/lib/gcloud/storage/errors.rb +9 -1
  28. data/lib/gcloud/storage/file.rb +231 -6
  29. data/lib/gcloud/storage/file/acl.rb +365 -2
  30. data/lib/gcloud/storage/file/list.rb +1 -0
  31. data/lib/gcloud/storage/file/verifier.rb +1 -0
  32. data/lib/gcloud/storage/project.rb +119 -10
  33. data/lib/gcloud/version.rb +18 -3
  34. metadata +33 -80
  35. data/.gemtest +0 -0
  36. data/.rubocop.yml +0 -17
  37. data/Manifest.txt +0 -66
  38. data/Rakefile +0 -35
  39. data/gcloud.gemspec +0 -63
  40. data/rakelib/console.rake +0 -28
  41. data/rakelib/manifest.rake +0 -24
  42. data/rakelib/proto.rake +0 -17
  43. data/rakelib/rubocop.rake +0 -17
  44. data/rakelib/test.rake +0 -144
  45. data/test/gcloud/datastore/proto/test_cursor.rb +0 -36
  46. data/test/gcloud/datastore/proto/test_direction.rb +0 -60
  47. data/test/gcloud/datastore/proto/test_operator.rb +0 -76
  48. data/test/gcloud/datastore/proto/test_value.rb +0 -231
  49. data/test/gcloud/datastore/test_connection.rb +0 -93
  50. data/test/gcloud/datastore/test_credentials.rb +0 -38
  51. data/test/gcloud/datastore/test_dataset.rb +0 -413
  52. data/test/gcloud/datastore/test_entity.rb +0 -161
  53. data/test/gcloud/datastore/test_entity_exclude.rb +0 -225
  54. data/test/gcloud/datastore/test_key.rb +0 -189
  55. data/test/gcloud/datastore/test_query.rb +0 -271
  56. data/test/gcloud/datastore/test_transaction.rb +0 -121
  57. data/test/gcloud/storage/test_backoff.rb +0 -127
  58. data/test/gcloud/storage/test_bucket.rb +0 -270
  59. data/test/gcloud/storage/test_bucket_acl.rb +0 -253
  60. data/test/gcloud/storage/test_default_acl.rb +0 -256
  61. data/test/gcloud/storage/test_file.rb +0 -221
  62. data/test/gcloud/storage/test_file_acl.rb +0 -367
  63. data/test/gcloud/storage/test_project.rb +0 -180
  64. data/test/gcloud/storage/test_storage.rb +0 -29
  65. data/test/gcloud/storage/test_verifier.rb +0 -62
  66. data/test/gcloud/test_version.rb +0 -8
  67. data/test/helper.rb +0 -91
@@ -1,38 +0,0 @@
1
- # Copyright 2014 Google Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require "helper"
16
- require "gcloud/datastore"
17
-
18
- describe Gcloud::Datastore::Credentials do
19
- let(:keyfile_json) do
20
- { client_email: "test@example.net",
21
- private_key: OpenSSL::PKey::RSA.new(32).to_s }.to_json
22
- end
23
-
24
- it "creates a Signet client and fetches access token" do
25
- credz = nil
26
- client_mock = Minitest::Mock.new
27
- client_mock.expect :fetch_access_token!, true
28
- Signet::OAuth2::Client.stub :new, client_mock do
29
- File.stub :file?, true do
30
- File.stub :read, keyfile_json do
31
- credz = Gcloud::Datastore::Credentials.new "fake.json"
32
- end
33
- end
34
- end
35
- client_mock.verify
36
- credz.must_respond_to :sign_http_request
37
- end
38
- end
@@ -1,413 +0,0 @@
1
- # Copyright 2014 Google Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require "helper"
16
- require "gcloud/datastore"
17
-
18
- describe Gcloud::Datastore::Dataset do
19
- let(:project) { "my-todo-project" }
20
- let(:credentials) { OpenStruct.new }
21
- let(:dataset) { Gcloud::Datastore::Dataset.new project, credentials }
22
- let(:allocate_ids_response) do
23
- Gcloud::Datastore::Proto::AllocateIdsResponse.new.tap do |response|
24
- response.key = []
25
- response.key << Gcloud::Datastore::Key.new("ds-test", 1234).to_proto
26
- end
27
- end
28
- let(:commit_response) do
29
- Gcloud::Datastore::Proto::CommitResponse.new.tap do |response|
30
- response.mutation_result = Gcloud::Datastore::Proto::MutationResult.new
31
- end
32
- end
33
- let(:lookup_response) do
34
- Gcloud::Datastore::Proto::LookupResponse.new.tap do |response|
35
- response.found = 2.times.map do
36
- Gcloud::Datastore::Proto::EntityResult.new.tap do |er|
37
- er.entity = Gcloud::Datastore::Entity.new.tap do |e|
38
- e.key = Gcloud::Datastore::Key.new "ds-test", "thingie"
39
- e["name"] = "thingamajig"
40
- end.to_proto
41
- end
42
- end
43
- end
44
- end
45
- let(:run_query_response) do
46
- Gcloud::Datastore::Proto::RunQueryResponse.new.tap do |response|
47
- response.batch = Gcloud::Datastore::Proto::QueryResultBatch.new.tap do |batch|
48
- batch.entity_result = 2.times.map do
49
- Gcloud::Datastore::Proto::EntityResult.new.tap do |er|
50
- er.entity = Gcloud::Datastore::Entity.new.tap do |e|
51
- e.key = Gcloud::Datastore::Key.new "ds-test", "thingie"
52
- e["name"] = "thingamajig"
53
- end.to_proto
54
- end
55
- end
56
- batch.end_cursor = Gcloud::Datastore::Proto.decode_cursor query_cursor
57
- end
58
- end
59
- end
60
- let(:begin_transaction_response) do
61
- Gcloud::Datastore::Proto::BeginTransactionResponse.new.tap do |response|
62
- response.transaction = "giterdone"
63
- end
64
- end
65
- let(:query_cursor) { "c3VwZXJhd2Vzb21lIQ==" }
66
-
67
- before do
68
- dataset.connection = Minitest::Mock.new
69
- end
70
-
71
- after do
72
- dataset.connection.verify
73
- end
74
-
75
- it "allocate_ids returns complete keys" do
76
- dataset.connection.expect :allocate_ids,
77
- allocate_ids_response,
78
- [Gcloud::Datastore::Proto::Key]
79
-
80
- incomplete_key = Gcloud::Datastore::Key.new "ds-test"
81
- incomplete_key.must_be :incomplete?
82
- returned_keys = dataset.allocate_ids incomplete_key
83
- returned_keys.count.must_equal 1
84
- returned_keys.first.must_be_kind_of Gcloud::Datastore::Key
85
- returned_keys.first.must_be :complete?
86
- end
87
-
88
- it "allocate_ids raises when not given an incomplete key" do
89
- complete_key = Gcloud::Datastore::Key.new "ds-test", 789
90
- complete_key.must_be :complete?
91
- assert_raises Gcloud::Datastore::Error do
92
- dataset.allocate_ids complete_key
93
- end
94
- end
95
-
96
- it "save will persist entities" do
97
- dataset.connection.expect :commit,
98
- commit_response,
99
- [Gcloud::Datastore::Proto::Mutation]
100
-
101
- entity = Gcloud::Datastore::Entity.new.tap do |e|
102
- e.key = Gcloud::Datastore::Key.new "ds-test", "thingie"
103
- e["name"] = "thingamajig"
104
- end
105
- dataset.save entity
106
- end
107
-
108
- it "find can take a kind and id" do
109
- dataset.connection.expect :lookup,
110
- lookup_response,
111
- [Gcloud::Datastore::Proto::Key]
112
-
113
- entity = dataset.find "ds-test", 123
114
- entity.must_be_kind_of Gcloud::Datastore::Entity
115
- end
116
-
117
- it "find can take a kind and name" do
118
- dataset.connection.expect :lookup,
119
- lookup_response,
120
- [Gcloud::Datastore::Proto::Key]
121
-
122
- entity = dataset.find "ds-test", "thingie"
123
- entity.must_be_kind_of Gcloud::Datastore::Entity
124
- end
125
-
126
- it "find can take a key" do
127
- dataset.connection.expect :lookup,
128
- lookup_response,
129
- [Gcloud::Datastore::Proto::Key]
130
-
131
- key = Gcloud::Datastore::Key.new "ds-test", "thingie"
132
- entity = dataset.find key
133
- entity.must_be_kind_of Gcloud::Datastore::Entity
134
- end
135
-
136
- it "find is aliased to get" do
137
- dataset.connection.expect :lookup,
138
- lookup_response,
139
- [Gcloud::Datastore::Proto::Key]
140
-
141
- entity = dataset.get "ds-test", 123
142
- entity.must_be_kind_of Gcloud::Datastore::Entity
143
- end
144
-
145
- it "find_all takes several keys" do
146
- dataset.connection.expect :lookup,
147
- lookup_response,
148
- [Gcloud::Datastore::Proto::Key,
149
- Gcloud::Datastore::Proto::Key]
150
-
151
- key = Gcloud::Datastore::Key.new "ds-test", "thingie"
152
- entities = dataset.find_all key, key
153
- entities.count.must_equal 2
154
- entities.deferred.count.must_equal 0
155
- entities.missing.count.must_equal 0
156
- entities.each do |entity|
157
- entity.must_be_kind_of Gcloud::Datastore::Entity
158
- end
159
- end
160
-
161
- it "find_all is aliased to lookup" do
162
- dataset.connection.expect :lookup,
163
- lookup_response,
164
- [Gcloud::Datastore::Proto::Key,
165
- Gcloud::Datastore::Proto::Key]
166
-
167
- key = Gcloud::Datastore::Key.new "ds-test", "thingie"
168
- entities = dataset.lookup key, key
169
- entities.count.must_equal 2
170
- entities.deferred.count.must_equal 0
171
- entities.missing.count.must_equal 0
172
- entities.each do |entity|
173
- entity.must_be_kind_of Gcloud::Datastore::Entity
174
- end
175
- end
176
-
177
- describe "find_all result object" do
178
- let(:lookup_response_deferred) do
179
- lookup_response.tap do |response|
180
- response.deferred = 2.times.map do
181
- Gcloud::Datastore::Key.new("ds-test", "thingie").to_proto
182
- end
183
- end
184
- end
185
-
186
- let(:lookup_response_missing) do
187
- lookup_response.tap do |response|
188
- response.missing = 2.times.map do
189
- Gcloud::Datastore::Proto::EntityResult.new.tap do |er|
190
- er.entity = Gcloud::Datastore::Entity.new.tap do |e|
191
- e.key = Gcloud::Datastore::Key.new "ds-test", "thingie"
192
- e["name"] = "thingamajig"
193
- end.to_proto
194
- end
195
- end
196
- end
197
- end
198
-
199
- it "contains deferred entities" do
200
- dataset.connection.expect :lookup,
201
- lookup_response_deferred,
202
- [Gcloud::Datastore::Proto::Key,
203
- Gcloud::Datastore::Proto::Key]
204
-
205
- key = Gcloud::Datastore::Key.new "ds-test", "thingie"
206
- entities = dataset.find_all key, key
207
- entities.count.must_equal 2
208
- entities.deferred.count.must_equal 2
209
- entities.missing.count.must_equal 0
210
- entities.each do |entity|
211
- entity.must_be_kind_of Gcloud::Datastore::Entity
212
- end
213
- entities.deferred.each do |deferred_key|
214
- deferred_key.must_be_kind_of Gcloud::Datastore::Key
215
- end
216
- end
217
-
218
- it "contains missing entities" do
219
- dataset.connection.expect :lookup,
220
- lookup_response_missing,
221
- [Gcloud::Datastore::Proto::Key,
222
- Gcloud::Datastore::Proto::Key]
223
-
224
- key = Gcloud::Datastore::Key.new "ds-test", "thingie"
225
- entities = dataset.find_all key, key
226
- entities.count.must_equal 2
227
- entities.deferred.count.must_equal 0
228
- entities.missing.count.must_equal 2
229
- entities.each do |entity|
230
- entity.must_be_kind_of Gcloud::Datastore::Entity
231
- end
232
- entities.missing.each do |entity|
233
- entity.must_be_kind_of Gcloud::Datastore::Entity
234
- end
235
- end
236
- end
237
-
238
- it "delete with entity will call commit" do
239
- dataset.connection.expect :commit,
240
- commit_response,
241
- [Gcloud::Datastore::Proto::Mutation]
242
-
243
- entity = Gcloud::Datastore::Entity.new.tap do |e|
244
- e.key = Gcloud::Datastore::Key.new "ds-test", "thingie"
245
- e["name"] = "thingamajig"
246
- end
247
- dataset.delete entity
248
- end
249
-
250
- it "delete with key will call commit" do
251
- dataset.connection.expect :commit,
252
- commit_response,
253
- [Gcloud::Datastore::Proto::Mutation]
254
-
255
- key = Gcloud::Datastore::Key.new "ds-test", "thingie"
256
- dataset.delete key
257
- end
258
-
259
- it "run will fulfill a query" do
260
- dataset.connection.expect :run_query,
261
- run_query_response,
262
- [Gcloud::Datastore::Proto::Query]
263
-
264
- query = Gcloud::Datastore::Query.new.kind("User")
265
- entities = dataset.run query
266
- entities.count.must_equal 2
267
- entities.each do |entity|
268
- entity.must_be_kind_of Gcloud::Datastore::Entity
269
- end
270
- entities.cursor.must_equal query_cursor
271
- entities.more_results.must_be :nil?
272
- refute entities.not_finished?
273
- refute entities.more_after_limit?
274
- refute entities.no_more?
275
- end
276
-
277
- it "run_query will fulfill a query" do
278
- dataset.connection.expect :run_query,
279
- run_query_response,
280
- [Gcloud::Datastore::Proto::Query]
281
-
282
- query = Gcloud::Datastore::Query.new.kind("User")
283
- entities = dataset.run_query query
284
- entities.count.must_equal 2
285
- entities.each do |entity|
286
- entity.must_be_kind_of Gcloud::Datastore::Entity
287
- end
288
- entities.cursor.must_equal query_cursor
289
- entities.more_results.must_be :nil?
290
- refute entities.not_finished?
291
- refute entities.more_after_limit?
292
- refute entities.no_more?
293
- end
294
-
295
- describe "query result object" do
296
- let(:run_query_response_not_finished) do
297
- run_query_response.tap do |response|
298
- response.batch.more_results =
299
- Gcloud::Datastore::Proto::QueryResultBatch::MoreResultsType::NOT_FINISHED
300
- end
301
- end
302
- let(:run_query_response_more_after_limit) do
303
- run_query_response.tap do |response|
304
- response.batch.more_results =
305
- Gcloud::Datastore::Proto::QueryResultBatch::MoreResultsType::MORE_RESULTS_AFTER_LIMIT
306
- end
307
- end
308
- let(:run_query_response_no_more) do
309
- run_query_response.tap do |response|
310
- response.batch.more_results =
311
- Gcloud::Datastore::Proto::QueryResultBatch::MoreResultsType::NO_MORE_RESULTS
312
- end
313
- end
314
-
315
- it "has more_results not_finished" do
316
- dataset.connection.expect :run_query,
317
- run_query_response_not_finished,
318
- [Gcloud::Datastore::Proto::Query]
319
-
320
- query = Gcloud::Datastore::Query.new.kind("User")
321
- entities = dataset.run query
322
- entities.count.must_equal 2
323
- entities.each do |entity|
324
- entity.must_be_kind_of Gcloud::Datastore::Entity
325
- end
326
- entities.cursor.must_equal query_cursor
327
- entities.more_results.must_equal "NOT_FINISHED"
328
- assert entities.not_finished?
329
- refute entities.more_after_limit?
330
- refute entities.no_more?
331
- end
332
-
333
- it "has more_results more_after_limit" do
334
- dataset.connection.expect :run_query,
335
- run_query_response_more_after_limit,
336
- [Gcloud::Datastore::Proto::Query]
337
-
338
- query = Gcloud::Datastore::Query.new.kind("User")
339
- entities = dataset.run query
340
- entities.count.must_equal 2
341
- entities.each do |entity|
342
- entity.must_be_kind_of Gcloud::Datastore::Entity
343
- end
344
- entities.cursor.must_equal query_cursor
345
- entities.more_results.must_equal "MORE_RESULTS_AFTER_LIMIT"
346
- refute entities.not_finished?
347
- assert entities.more_after_limit?
348
- refute entities.no_more?
349
- end
350
-
351
- it "has more_results no_more" do
352
- dataset.connection.expect :run_query,
353
- run_query_response_no_more,
354
- [Gcloud::Datastore::Proto::Query]
355
-
356
- query = Gcloud::Datastore::Query.new.kind("User")
357
- entities = dataset.run query
358
- entities.count.must_equal 2
359
- entities.each do |entity|
360
- entity.must_be_kind_of Gcloud::Datastore::Entity
361
- end
362
- entities.cursor.must_equal query_cursor
363
- entities.more_results.must_equal "NO_MORE_RESULTS"
364
- refute entities.not_finished?
365
- refute entities.more_after_limit?
366
- assert entities.no_more?
367
- end
368
- end
369
-
370
-
371
- it "transaction will return a Transaction" do
372
- dataset.connection.expect :begin_transaction,
373
- begin_transaction_response
374
-
375
- tx = dataset.transaction
376
- tx.must_be_kind_of Gcloud::Datastore::Transaction
377
- tx.id.must_equal "giterdone"
378
- end
379
-
380
- it "transaction will commit with a block" do
381
- dataset.connection.expect :begin_transaction,
382
- begin_transaction_response
383
- dataset.connection.expect :commit,
384
- commit_response,
385
- [Gcloud::Datastore::Proto::Mutation,
386
- String]
387
-
388
- entity = Gcloud::Datastore::Entity.new.tap do |e|
389
- e.key = Gcloud::Datastore::Key.new "ds-test", "thingie"
390
- e["name"] = "thingamajig"
391
- end
392
- dataset.transaction do |tx|
393
- tx.save entity
394
- end
395
- end
396
-
397
- it "transaction will wrap errors in TransactionError" do
398
- dataset.connection.expect :begin_transaction,
399
- begin_transaction_response
400
- dataset.connection.expect :rollback, nil, [String]
401
-
402
- error = assert_raises Gcloud::Datastore::TransactionError do
403
- dataset.transaction do |tx|
404
- fail "This error should be wrapped by TransactionError."
405
- end
406
- end
407
-
408
- error.wont_be :nil?
409
- error.message.must_equal "Transaction failed to commit."
410
- error.inner.wont_be :nil?
411
- error.inner.message.must_equal "This error should be wrapped by TransactionError."
412
- end
413
- end