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,256 +0,0 @@
1
- # Copyright 2015 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 "json"
17
- require "uri"
18
-
19
- describe Gcloud::Storage::Bucket, :default_acl, :mock_storage do
20
- # Create a bucket object with the project's mocked connection object
21
- let(:bucket) { Gcloud::Storage::Bucket.from_gapi random_bucket_hash,
22
- storage.connection }
23
-
24
- it "retrieves the default ACL" do
25
- bucket_name = "found-bucket"
26
-
27
- mock_connection.get "/storage/v1/b/#{bucket_name}" do |env|
28
- [200, {"Content-Type"=>"application/json"},
29
- random_bucket_hash(bucket_name).to_json]
30
- end
31
-
32
- mock_connection.get "/storage/v1/b/#{bucket_name}/defaultObjectAcl" do |env|
33
- [200, {"Content-Type"=>"application/json"},
34
- random_default_acl_hash(bucket_name).to_json]
35
- end
36
-
37
- bucket = storage.find_bucket bucket_name
38
- bucket.name.must_equal bucket_name
39
- bucket.default_acl.owners.wont_be :empty?
40
- bucket.default_acl.writers.must_be :empty?
41
- bucket.default_acl.readers.wont_be :empty?
42
- end
43
-
44
- it "adds to the default ACL" do
45
- bucket_name = "found-bucket"
46
-
47
- mock_connection.get "/storage/v1/b/#{bucket_name}" do |env|
48
- [200, {"Content-Type"=>"application/json"},
49
- random_bucket_hash(bucket_name).to_json]
50
- end
51
-
52
- mock_connection.get "/storage/v1/b/#{bucket_name}/defaultObjectAcl" do |env|
53
- [200, {"Content-Type"=>"application/json"},
54
- random_default_acl_hash(bucket_name).to_json]
55
- end
56
-
57
- bucket = storage.find_bucket bucket_name
58
- bucket.name.must_equal bucket_name
59
- bucket.default_acl.owners.wont_be :empty?
60
- bucket.default_acl.writers.must_be :empty?
61
- bucket.default_acl.readers.wont_be :empty?
62
-
63
- writer_entity = "user-user@example.net"
64
- writer_acl = {
65
- "kind" => "storage#bucketAccessControl",
66
- "id" => "#{bucket_name}-UUID/#{writer_entity}",
67
- "selfLink" => "https://www.googleapis.com/storage/v1/b/#{bucket_name}-UUID/defaultObjectAcl/#{writer_entity}",
68
- "bucket" => "#{bucket_name}-UUID",
69
- "entity" => writer_entity,
70
- "email" => "user@example.net",
71
- "role" => "WRITER",
72
- "etag" => "CAE="
73
- }
74
-
75
- mock_connection.post "/storage/v1/b/#{bucket_name}/defaultObjectAcl" do |env|
76
- [200, {"Content-Type"=>"application/json"},
77
- writer_acl.to_json]
78
- end
79
-
80
- bucket.default_acl.add_writer writer_entity
81
- bucket.default_acl.owners.wont_be :empty?
82
- bucket.default_acl.writers.wont_be :empty?
83
- bucket.default_acl.readers.wont_be :empty?
84
- bucket.default_acl.writers.must_include writer_entity
85
- end
86
-
87
- it "removes from the default ACL" do
88
- bucket_name = "found-bucket"
89
-
90
- mock_connection.get "/storage/v1/b/#{bucket_name}" do |env|
91
- [200, {"Content-Type"=>"application/json"},
92
- random_bucket_hash(bucket_name).to_json]
93
- end
94
-
95
- mock_connection.get "/storage/v1/b/#{bucket_name}/defaultObjectAcl" do |env|
96
- [200, {"Content-Type"=>"application/json"},
97
- random_default_acl_hash(bucket_name).to_json]
98
- end
99
-
100
- bucket = storage.find_bucket bucket_name
101
- bucket.name.must_equal bucket_name
102
- bucket.default_acl.owners.wont_be :empty?
103
- bucket.default_acl.writers.must_be :empty?
104
- bucket.default_acl.readers.wont_be :empty?
105
-
106
- reader_entity = bucket.default_acl.readers.first
107
-
108
- mock_connection.delete "/storage/v1/b/#{bucket_name}/defaultObjectAcl/#{reader_entity}" do |env|
109
- [200, {"Content-Type"=>"application/json"}, ""]
110
- end
111
-
112
- bucket.default_acl.delete reader_entity
113
-
114
- bucket.default_acl.owners.wont_be :empty?
115
- bucket.default_acl.writers.must_be :empty?
116
- bucket.default_acl.readers.must_be :empty?
117
- end
118
-
119
- it "sets the predefined ACL rule authenticatedRead" do
120
- predefined_default_acl_update "authenticatedRead" do |acl|
121
- acl.authenticatedRead!
122
- end
123
- end
124
-
125
- it "sets the predefined ACL rule auth" do
126
- predefined_default_acl_update "authenticatedRead" do |acl|
127
- acl.auth!
128
- end
129
- end
130
-
131
- it "sets the predefined ACL rule auth_read" do
132
- predefined_default_acl_update "authenticatedRead" do |acl|
133
- acl.auth_read!
134
- end
135
- end
136
-
137
- it "sets the predefined ACL rule authenticated" do
138
- predefined_default_acl_update "authenticatedRead" do |acl|
139
- acl.authenticated!
140
- end
141
- end
142
-
143
- it "sets the predefined ACL rule authenticated_read" do
144
- predefined_default_acl_update "authenticatedRead" do |acl|
145
- acl.authenticated_read!
146
- end
147
- end
148
-
149
- it "sets the predefined ACL rule bucketOwnerFullControl" do
150
- predefined_default_acl_update "bucketOwnerFullControl" do |acl|
151
- acl.bucketOwnerFullControl!
152
- end
153
- end
154
-
155
- it "sets the predefined ACL rule owner_full" do
156
- predefined_default_acl_update "bucketOwnerFullControl" do |acl|
157
- acl.owner_full!
158
- end
159
- end
160
-
161
- it "sets the predefined ACL rule bucketOwnerRead" do
162
- predefined_default_acl_update "bucketOwnerRead" do |acl|
163
- acl.bucketOwnerRead!
164
- end
165
- end
166
-
167
- it "sets the predefined ACL rule owner_read" do
168
- predefined_default_acl_update "bucketOwnerRead" do |acl|
169
- acl.owner_read!
170
- end
171
- end
172
-
173
- it "sets the predefined ACL rule private" do
174
- predefined_default_acl_update "private" do |acl|
175
- acl.private!
176
- end
177
- end
178
-
179
- it "sets the predefined ACL rule projectPrivate" do
180
- predefined_default_acl_update "projectPrivate" do |acl|
181
- acl.projectPrivate!
182
- end
183
- end
184
-
185
- it "sets the predefined ACL rule project_private" do
186
- predefined_default_acl_update "projectPrivate" do |acl|
187
- acl.project_private!
188
- end
189
- end
190
-
191
- it "sets the predefined ACL rule publicRead" do
192
- predefined_default_acl_update "publicRead" do |acl|
193
- acl.publicRead!
194
- end
195
- end
196
-
197
- it "sets the predefined ACL rule public" do
198
- predefined_default_acl_update "publicRead" do |acl|
199
- acl.public!
200
- end
201
- end
202
-
203
- it "sets the predefined ACL rule public_read" do
204
- predefined_default_acl_update "publicRead" do |acl|
205
- acl.public_read!
206
- end
207
- end
208
-
209
- def predefined_default_acl_update acl_role
210
- mock_connection.patch "/storage/v1/b/#{bucket.name}" do |env|
211
- env.params["predefinedDefaultObjectAcl"].must_equal acl_role
212
- [200, {"Content-Type"=>"application/json"},
213
- random_bucket_hash(bucket.name).to_json]
214
- end
215
-
216
- yield bucket.default_acl
217
- end
218
-
219
- def random_default_acl_hash bucket_name
220
- {
221
- "kind" => "storage#objectAccessControls",
222
- "items" => [
223
- {
224
- "kind" => "storage#objectAccessControl",
225
- "entity" => "project-owners-1234567890",
226
- "role" => "OWNER",
227
- "projectTeam" => {
228
- "projectNumber" => "1234567890",
229
- "team" => "owners"
230
- },
231
- "etag" => "CAE="
232
- },
233
- {
234
- "kind" => "storage#objectAccessControl",
235
- "entity" => "project-editors-1234567890",
236
- "role" => "OWNER",
237
- "projectTeam" => {
238
- "projectNumber" => "1234567890",
239
- "team" => "editors"
240
- },
241
- "etag" => "CAE="
242
- },
243
- {
244
- "kind" => "storage#objectAccessControl",
245
- "entity" => "project-viewers-1234567890",
246
- "role" => "READER",
247
- "projectTeam" => {
248
- "projectNumber" => "1234567890",
249
- "team" => "viewers"
250
- },
251
- "etag" => "CAE="
252
- }
253
- ]
254
- }
255
- end
256
- end
@@ -1,221 +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 "json"
17
- require "uri"
18
-
19
- describe Gcloud::Storage::File, :mock_storage do
20
- # Create a bucket object with the project's mocked connection object
21
- let(:bucket) { Gcloud::Storage::Bucket.from_gapi random_bucket_hash("bucket"),
22
- storage.connection }
23
-
24
- # Create a file object with the project's mocked connection object
25
- let(:file) { Gcloud::Storage::File.from_gapi random_file_hash(bucket.name, "file.ext"),
26
- storage.connection }
27
-
28
- it "can delete itself" do
29
- mock_connection.delete "/storage/v1/b/#{bucket.name}/o/#{file.name}" do |env|
30
- [200, {"Content-Type"=>"application/json"}, ""]
31
- end
32
-
33
- file.delete
34
- end
35
-
36
- it "can download itself" do
37
- # Stub the md5 to match.
38
- def file.md5
39
- "X7A8HRvZUCT5gbq0KNDL8Q=="
40
- end
41
- mock_connection.get "/storage/v1/b/#{bucket.name}/o/#{file.name}?alt=media" do |env|
42
- [200, {"Content-Type"=>"text/plain"},
43
- "yay!"]
44
- end
45
-
46
- Tempfile.open "gcloud-ruby" do |tmpfile|
47
- file.download tmpfile
48
- File.read(tmpfile).must_equal "yay!"
49
- end
50
- end
51
-
52
- describe "verified downloads" do
53
- before do
54
- # Stub these values
55
- def file.md5; "md5="; end
56
- def file.crc32c; "crc32c="; end
57
- # Mock the download
58
- mock_connection.get "/storage/v1/b/#{bucket.name}/o/#{file.name}?alt=media" do |env|
59
- [200, {"Content-Type"=>"text/plain"},
60
- "The quick brown fox jumps over the lazy dog."]
61
- end
62
- end
63
-
64
- it "verifies m5d by default" do
65
- mocked_md5 = Minitest::Mock.new
66
- mocked_md5.expect :md5_mock, file.md5
67
- stubbed_md5 = lambda { |_| mocked_md5.md5_mock }
68
- stubbed_crc32c = lambda { |_| fail "Should not be called!" }
69
-
70
- Gcloud::Storage::File::Verifier.stub :md5_for, stubbed_md5 do
71
- Gcloud::Storage::File::Verifier.stub :crc32c_for, stubbed_crc32c do
72
- Tempfile.open "gcloud-ruby" do |tmpfile|
73
- file.download tmpfile
74
- end
75
- end
76
- end
77
- mocked_md5.verify
78
- end
79
-
80
- it "verifies m5d when specified" do
81
- mocked_md5 = Minitest::Mock.new
82
- mocked_md5.expect :md5_mock, file.md5
83
- stubbed_md5 = lambda { |_| mocked_md5.md5_mock }
84
- stubbed_crc32c = lambda { |_| fail "Should not be called!" }
85
-
86
- Gcloud::Storage::File::Verifier.stub :md5_for, stubbed_md5 do
87
- Gcloud::Storage::File::Verifier.stub :crc32c_for, stubbed_crc32c do
88
- Tempfile.open "gcloud-ruby" do |tmpfile|
89
- file.download tmpfile, verify: :md5
90
- end
91
- end
92
- end
93
- mocked_md5.verify
94
- end
95
-
96
- it "verifies crc32c when specified" do
97
- stubbed_md5 = lambda { |_| fail "Should not be called!" }
98
- mocked_crc32c = Minitest::Mock.new
99
- mocked_crc32c.expect :crc32c_mock, file.crc32c
100
- stubbed_crc32c = lambda { |_| mocked_crc32c.crc32c_mock }
101
-
102
- Gcloud::Storage::File::Verifier.stub :md5_for, stubbed_md5 do
103
- Gcloud::Storage::File::Verifier.stub :crc32c_for, stubbed_crc32c do
104
- Tempfile.open "gcloud-ruby" do |tmpfile|
105
- file.download tmpfile, verify: :crc32c
106
- end
107
- end
108
- end
109
- mocked_crc32c.verify
110
- end
111
-
112
- it "verifies m5d and crc32c when specified" do
113
- mocked_md5 = Minitest::Mock.new
114
- mocked_md5.expect :md5_mock, file.md5
115
- stubbed_md5 = lambda { |_| mocked_md5.md5_mock }
116
-
117
- mocked_crc32c = Minitest::Mock.new
118
- mocked_crc32c.expect :crc32c_mock, file.crc32c
119
- stubbed_crc32c = lambda { |_| mocked_crc32c.crc32c_mock }
120
-
121
- Gcloud::Storage::File::Verifier.stub :md5_for, stubbed_md5 do
122
- Gcloud::Storage::File::Verifier.stub :crc32c_for, stubbed_crc32c do
123
- Tempfile.open "gcloud-ruby" do |tmpfile|
124
- file.download tmpfile, verify: :all
125
- end
126
- end
127
- end
128
- mocked_md5.verify
129
- mocked_crc32c.verify
130
- end
131
-
132
- it "doesn't verify at all when specified" do
133
- stubbed_md5 = lambda { |_| fail "Should not be called!" }
134
- stubbed_crc32c = lambda { |_| fail "Should not be called!" }
135
-
136
- Gcloud::Storage::File::Verifier.stub :md5_for, stubbed_md5 do
137
- Gcloud::Storage::File::Verifier.stub :crc32c_for, stubbed_crc32c do
138
- Tempfile.open "gcloud-ruby" do |tmpfile|
139
- file.download tmpfile, verify: :none
140
- end
141
- end
142
- end
143
- end
144
-
145
- it "raises when verification fails" do
146
- mocked_md5 = Minitest::Mock.new
147
- mocked_md5.expect :md5_mock, "NOPE="
148
- stubbed_md5 = lambda { |_| mocked_md5.md5_mock }
149
- stubbed_crc32c = lambda { |_| fail "Should not be called!" }
150
-
151
- Gcloud::Storage::File::Verifier.stub :md5_for, stubbed_md5 do
152
- Gcloud::Storage::File::Verifier.stub :crc32c_for, stubbed_crc32c do
153
- Tempfile.open "gcloud-ruby" do |tmpfile|
154
- assert_raises Gcloud::Storage::FileVerificationError do
155
- file.download tmpfile
156
- end
157
- end
158
- end
159
- end
160
- mocked_md5.verify
161
- end
162
- end
163
-
164
- it "can copy itself in the same bucket" do
165
- mock_connection.post "/storage/v1/b/#{bucket.name}/o/#{file.name}/copyTo/b/#{bucket.name}/o/new-file.ext" do |env|
166
- [200, {"Content-Type"=>"application/json"},
167
- file.gapi.to_json]
168
- end
169
-
170
- file.copy "new-file.ext"
171
- end
172
-
173
- it "can copy itself in the same bucket with predefined ACL" do
174
- mock_connection.post "/storage/v1/b/#{bucket.name}/o/#{file.name}/copyTo/b/#{bucket.name}/o/new-file.ext" do |env|
175
- env.params["predefinedAcl"].must_equal "private"
176
- [200, {"Content-Type"=>"application/json"},
177
- file.gapi.to_json]
178
- end
179
-
180
- file.copy "new-file.ext", acl: "private"
181
- end
182
-
183
- it "can copy itself in the same bucket with ACL alias" do
184
- mock_connection.post "/storage/v1/b/#{bucket.name}/o/#{file.name}/copyTo/b/#{bucket.name}/o/new-file.ext" do |env|
185
- env.params["predefinedAcl"].must_equal "publicRead"
186
- [200, {"Content-Type"=>"application/json"},
187
- file.gapi.to_json]
188
- end
189
-
190
- file.copy "new-file.ext", acl: :public
191
- end
192
-
193
- it "can copy itself to a different bucket" do
194
- mock_connection.post "/storage/v1/b/#{bucket.name}/o/#{file.name}/copyTo/b/new-bucket/o/new-file.ext" do |env|
195
- [200, {"Content-Type"=>"application/json"},
196
- file.gapi.to_json]
197
- end
198
-
199
- file.copy "new-bucket", "new-file.ext"
200
- end
201
-
202
- it "can copy itself to a different bucket with predefined ACL" do
203
- mock_connection.post "/storage/v1/b/#{bucket.name}/o/#{file.name}/copyTo/b/new-bucket/o/new-file.ext" do |env|
204
- env.params["predefinedAcl"].must_equal "private"
205
- [200, {"Content-Type"=>"application/json"},
206
- file.gapi.to_json]
207
- end
208
-
209
- file.copy "new-bucket", "new-file.ext", acl: "private"
210
- end
211
-
212
- it "can copy itself to a different bucket with ACL alias" do
213
- mock_connection.post "/storage/v1/b/#{bucket.name}/o/#{file.name}/copyTo/b/new-bucket/o/new-file.ext" do |env|
214
- env.params["predefinedAcl"].must_equal "publicRead"
215
- [200, {"Content-Type"=>"application/json"},
216
- file.gapi.to_json]
217
- end
218
-
219
- file.copy "new-bucket", "new-file.ext", acl: :public
220
- end
221
- end