google-cloud-storage 1.19.0 → 1.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/LOGGING.md +1 -1
- data/lib/google/cloud/storage/bucket.rb +10 -5
- data/lib/google/cloud/storage/file.rb +2 -2
- data/lib/google/cloud/storage/file/signer_v4.rb +4 -3
- data/lib/google/cloud/storage/hmac_key.rb +316 -0
- data/lib/google/cloud/storage/hmac_key/list.rb +182 -0
- data/lib/google/cloud/storage/project.rb +86 -0
- data/lib/google/cloud/storage/service.rb +66 -2
- data/lib/google/cloud/storage/version.rb +1 -1
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95278f620e42cb0c09f509e972b2aac94204cd0435a7b824d561903d7dc3f455
|
4
|
+
data.tar.gz: 04410bfcf4d0cf2ce2b4b0db9e4f653122a7dded2ce460dac8ba5a97fc288a74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45c6bcb301c44151f4069cf648420f4b411e2662e843cc965105b8bf7f4e3a5f9072aaada1437ecda3df64fffcc4975a96694703f812278f37a24f5820df5d32
|
7
|
+
data.tar.gz: 9204c51ae1a9e967714db5fdee82f3f33c21cc879ccc7530013c861d1f015960ee6783f92dd37d96f5b3c07164314755d93dd7380a7deac75fd8ffe118f96de2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 1.20.0 / 2019-08-08
|
4
|
+
|
5
|
+
* Add HmacKey
|
6
|
+
* Add Project#create_hmac_key, Project#hmac_key, and Project#hmac_keys.
|
7
|
+
* Update documentation listings of current and legacy storage classes.
|
8
|
+
* Fix File#download to use generation from current File object.
|
9
|
+
|
3
10
|
### 1.19.0 / 2019-07-11
|
4
11
|
|
5
12
|
* Add Bucket#location_type
|
data/LOGGING.md
CHANGED
@@ -6,7 +6,7 @@ Client](https://github.com/google/google-api-ruby-client/blob/master/README.md#l
|
|
6
6
|
library. The logger that you set may be a Ruby stdlib
|
7
7
|
[`Logger`](https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html) as
|
8
8
|
shown below, or a
|
9
|
-
[`Google::Cloud::Logging::Logger`](https://googleapis.
|
9
|
+
[`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
|
10
10
|
that will write logs to [Stackdriver
|
11
11
|
Logging](https://cloud.google.com/logging/).
|
12
12
|
|
@@ -357,8 +357,9 @@ module Google
|
|
357
357
|
##
|
358
358
|
# The bucket's storage class. This defines how objects in the bucket are
|
359
359
|
# stored and determines the SLA and the cost of storage. Values include
|
360
|
-
# `
|
361
|
-
# `DURABLE_REDUCED_AVAILABILITY
|
360
|
+
# `STANDARD`, `NEARLINE`, and `COLDLINE`. `REGIONAL`,`MULTI_REGIONAL`,
|
361
|
+
# and `DURABLE_REDUCED_AVAILABILITY` are supported as legacy storage
|
362
|
+
# classes.
|
362
363
|
#
|
363
364
|
# @return [String]
|
364
365
|
#
|
@@ -370,8 +371,10 @@ module Google
|
|
370
371
|
# Updates the bucket's storage class. This defines how objects in the
|
371
372
|
# bucket are stored and determines the SLA and the cost of storage.
|
372
373
|
# Accepted values include `:standard`, `:nearline`, and `:coldline`, as
|
373
|
-
# well as the equivalent strings returned by {Bucket#storage_class}.
|
374
|
-
#
|
374
|
+
# well as the equivalent strings returned by {Bucket#storage_class}.
|
375
|
+
# `:multi_regional`, `:regional`, and `durable_reduced_availability`
|
376
|
+
# are accepted as legacy storage classes. For more information, see
|
377
|
+
# [Storage
|
375
378
|
# Classes](https://cloud.google.com/storage/docs/storage-classes).
|
376
379
|
#
|
377
380
|
# @param [Symbol, String] new_storage_class Storage class of the bucket.
|
@@ -1137,7 +1140,9 @@ module Google
|
|
1137
1140
|
# Determines how the file is stored and determines the SLA and the
|
1138
1141
|
# cost of storage. Accepted values include `:standard`, `:nearline`,
|
1139
1142
|
# and `:coldline`, as well as the equivalent strings returned by
|
1140
|
-
# {#storage_class}.
|
1143
|
+
# {#storage_class}. `:multi_regional`, `:regional`, and
|
1144
|
+
# `durable_reduced_availability` are accepted legacy storage classes.
|
1145
|
+
# For more information, see [Storage
|
1141
1146
|
# Classes](https://cloud.google.com/storage/docs/storage-classes)
|
1142
1147
|
# and [Per-Object Storage
|
1143
1148
|
# Class](https://cloud.google.com/storage/docs/per-object-storage-class).
|
@@ -937,8 +937,8 @@ module Google
|
|
937
937
|
end
|
938
938
|
file, resp =
|
939
939
|
service.download_file bucket, name, path,
|
940
|
-
|
941
|
-
user_project: user_project
|
940
|
+
generation: generation, key: encryption_key,
|
941
|
+
range: range, user_project: user_project
|
942
942
|
# FIX: downloading with encryption key will return nil
|
943
943
|
file ||= ::File.new path
|
944
944
|
verify = :none if range
|
@@ -122,9 +122,10 @@ module Google
|
|
122
122
|
def canonical_and_signed_headers headers
|
123
123
|
# Headers needs to be in alpha order.
|
124
124
|
canonical_headers = headers || {}
|
125
|
-
|
126
|
-
|
127
|
-
|
125
|
+
headers_arr = canonical_headers.map do |k, v|
|
126
|
+
[k.downcase, v.strip.gsub(/[^\S\t]+/, " ").gsub(/\t+/, "\t")]
|
127
|
+
end
|
128
|
+
canonical_headers = Hash[headers_arr]
|
128
129
|
canonical_headers["host"] = "storage.googleapis.com"
|
129
130
|
|
130
131
|
canonical_headers = canonical_headers.sort_by do |k, _|
|
@@ -0,0 +1,316 @@
|
|
1
|
+
# Copyright 2019 Google LLC
|
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
|
+
# https://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
|
+
|
16
|
+
require "google/cloud/storage/hmac_key/list"
|
17
|
+
|
18
|
+
module Google
|
19
|
+
module Cloud
|
20
|
+
module Storage
|
21
|
+
##
|
22
|
+
# # HmacKey
|
23
|
+
#
|
24
|
+
# Represents the metadata for an HMAC key, and also includes the key's
|
25
|
+
# secret if returned by the {Project#create_hmac_key} creation method.
|
26
|
+
#
|
27
|
+
# @see https://cloud.google.com/storage/docs/migrating#migration-simple
|
28
|
+
# Migrating from Amazon S3 to Cloud Storage - Simple migration
|
29
|
+
#
|
30
|
+
# @attr_reader [String, nil] secret HMAC secret key material, or `nil` if
|
31
|
+
# the key was not returned by the {Project#create_hmac_key} creation
|
32
|
+
# method.
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# require "google/cloud/storage"
|
36
|
+
#
|
37
|
+
# storage = Google::Cloud::Storage.new
|
38
|
+
#
|
39
|
+
# service_account_email = "my_account@developer.gserviceaccount.com"
|
40
|
+
# hmac_key = storage.create_hmac_key service_account_email
|
41
|
+
# hmac_key.secret # ...
|
42
|
+
#
|
43
|
+
# hmac_key = storage.hmac_key hmac_key.access_id
|
44
|
+
# hmac_key.secret # nil
|
45
|
+
#
|
46
|
+
# hmac_key.inactive!
|
47
|
+
# hmac_key.delete
|
48
|
+
#
|
49
|
+
class HmacKey
|
50
|
+
##
|
51
|
+
# @private The Connection object.
|
52
|
+
attr_accessor :service
|
53
|
+
|
54
|
+
##
|
55
|
+
# @private The Google API Client object.
|
56
|
+
attr_accessor :gapi
|
57
|
+
|
58
|
+
##
|
59
|
+
# @private A boolean value or a project ID string to indicate the
|
60
|
+
# project to be billed for operations.
|
61
|
+
attr_accessor :user_project
|
62
|
+
|
63
|
+
attr_reader :secret
|
64
|
+
|
65
|
+
##
|
66
|
+
# @private Creates an HmacKey object.
|
67
|
+
def initialize
|
68
|
+
@bucket = nil
|
69
|
+
@service = nil
|
70
|
+
@gapi = nil
|
71
|
+
@user_project = nil
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# The ID of the HMAC Key.
|
76
|
+
#
|
77
|
+
# @return [String]
|
78
|
+
#
|
79
|
+
def access_id
|
80
|
+
@gapi.access_id
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# A URL that can be used to access the HMAC key using the REST API.
|
85
|
+
#
|
86
|
+
# @return [String]
|
87
|
+
#
|
88
|
+
def api_url
|
89
|
+
@gapi.self_link
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# Creation time of the HMAC key.
|
94
|
+
#
|
95
|
+
# @return [String]
|
96
|
+
#
|
97
|
+
def created_at
|
98
|
+
@gapi.time_created
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# HTTP 1.1 Entity tag for the HMAC key.
|
103
|
+
#
|
104
|
+
# @return [String]
|
105
|
+
#
|
106
|
+
def etag
|
107
|
+
@gapi.etag
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# The ID of the HMAC key, including the Project ID and the Access ID.
|
112
|
+
#
|
113
|
+
# @return [String]
|
114
|
+
#
|
115
|
+
def id
|
116
|
+
@gapi.id
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# Project ID owning the service account to which the key authenticates.
|
121
|
+
#
|
122
|
+
# @return [String]
|
123
|
+
#
|
124
|
+
def project_id
|
125
|
+
@gapi.project_id
|
126
|
+
end
|
127
|
+
|
128
|
+
##
|
129
|
+
# The email address of the key's associated service account.
|
130
|
+
#
|
131
|
+
# @return [String]
|
132
|
+
#
|
133
|
+
def service_account_email
|
134
|
+
@gapi.service_account_email
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# The state of the key. Can be one of `ACTIVE`, `INACTIVE`, or
|
139
|
+
# `DELETED`.
|
140
|
+
#
|
141
|
+
# @return [String]
|
142
|
+
#
|
143
|
+
def state
|
144
|
+
@gapi.state
|
145
|
+
end
|
146
|
+
|
147
|
+
##
|
148
|
+
# Last modification time of the HMAC key metadata.
|
149
|
+
#
|
150
|
+
# @return [String]
|
151
|
+
#
|
152
|
+
def updated_at
|
153
|
+
@gapi.updated
|
154
|
+
end
|
155
|
+
|
156
|
+
##
|
157
|
+
# Whether the state of the HMAC key is `ACTIVE`.
|
158
|
+
#
|
159
|
+
# @return [Boolean]
|
160
|
+
#
|
161
|
+
def active?
|
162
|
+
state == "ACTIVE"
|
163
|
+
end
|
164
|
+
|
165
|
+
##
|
166
|
+
# Updates the state of the HMAC key to `ACTIVE`.
|
167
|
+
#
|
168
|
+
# @return [Google::Cloud::Storage::HmacKey] Returns the HMAC key for
|
169
|
+
# method chaining.
|
170
|
+
#
|
171
|
+
# @example
|
172
|
+
# require "google/cloud/storage"
|
173
|
+
#
|
174
|
+
# storage = Google::Cloud::Storage.new
|
175
|
+
#
|
176
|
+
# hmac_key = storage.hmac_keys.first
|
177
|
+
#
|
178
|
+
# hmac_key.active!
|
179
|
+
# hmac_key.state # "ACTIVE"
|
180
|
+
#
|
181
|
+
def active!
|
182
|
+
put_gapi! "ACTIVE"
|
183
|
+
self
|
184
|
+
end
|
185
|
+
|
186
|
+
##
|
187
|
+
# Whether the state of the HMAC key is `INACTIVE`.
|
188
|
+
#
|
189
|
+
# @return [Boolean]
|
190
|
+
#
|
191
|
+
def inactive?
|
192
|
+
state == "INACTIVE"
|
193
|
+
end
|
194
|
+
|
195
|
+
##
|
196
|
+
# Updates the state of the HMAC key to `INACTIVE`.
|
197
|
+
#
|
198
|
+
# @return [Google::Cloud::Storage::HmacKey] Returns the HMAC key for
|
199
|
+
# method chaining.
|
200
|
+
#
|
201
|
+
# @example
|
202
|
+
# require "google/cloud/storage"
|
203
|
+
#
|
204
|
+
# storage = Google::Cloud::Storage.new
|
205
|
+
#
|
206
|
+
# hmac_key = storage.hmac_keys.first
|
207
|
+
#
|
208
|
+
# hmac_key.inactive!
|
209
|
+
# hmac_key.state # "INACTIVE"
|
210
|
+
#
|
211
|
+
def inactive!
|
212
|
+
put_gapi! "INACTIVE"
|
213
|
+
self
|
214
|
+
end
|
215
|
+
|
216
|
+
##
|
217
|
+
# Whether the state of the HMAC key is `DELETED`.
|
218
|
+
#
|
219
|
+
# @return [Boolean]
|
220
|
+
#
|
221
|
+
def deleted?
|
222
|
+
state == "DELETED"
|
223
|
+
end
|
224
|
+
|
225
|
+
##
|
226
|
+
# Deletes the HMAC key, and loads the new state of the HMAC key,
|
227
|
+
# which will be `DELETED`.
|
228
|
+
#
|
229
|
+
# The API call to delete the HMAC key may be retried under certain
|
230
|
+
# conditions. See {Google::Cloud#storage} to control this behavior.
|
231
|
+
#
|
232
|
+
# @return [Google::Cloud::Storage::HmacKey] Returns the HMAC key for
|
233
|
+
# method chaining.
|
234
|
+
#
|
235
|
+
# @example
|
236
|
+
# require "google/cloud/storage"
|
237
|
+
#
|
238
|
+
# storage = Google::Cloud::Storage.new
|
239
|
+
#
|
240
|
+
# hmac_key = storage.hmac_keys.first
|
241
|
+
#
|
242
|
+
# hmac_key.inactive!.delete!
|
243
|
+
#
|
244
|
+
def delete!
|
245
|
+
ensure_service!
|
246
|
+
@service.delete_hmac_key access_id,
|
247
|
+
project_id: project_id,
|
248
|
+
user_project: @user_project
|
249
|
+
@gapi = @service.get_hmac_key access_id, project_id: project_id,
|
250
|
+
user_project: @user_project
|
251
|
+
self
|
252
|
+
end
|
253
|
+
alias delete delete!
|
254
|
+
|
255
|
+
##
|
256
|
+
# Reloads the HMAC key with current data from the Storage service.
|
257
|
+
#
|
258
|
+
def reload!
|
259
|
+
ensure_service!
|
260
|
+
@gapi = service.get_hmac_key access_id, project_id: project_id,
|
261
|
+
user_project: user_project
|
262
|
+
self
|
263
|
+
end
|
264
|
+
alias refresh! reload!
|
265
|
+
|
266
|
+
##
|
267
|
+
# @private New HmacKey from a Google::Apis::StorageV1::HmacKey object.
|
268
|
+
#
|
269
|
+
# @param [Google::Apis::StorageV1::HmacKey] gapi
|
270
|
+
#
|
271
|
+
#
|
272
|
+
def self.from_gapi gapi, service, user_project: nil
|
273
|
+
hmac_key = from_gapi_metadata gapi.metadata,
|
274
|
+
service,
|
275
|
+
user_project: user_project
|
276
|
+
hmac_key.tap do |f|
|
277
|
+
f.instance_variable_set :@secret, gapi.secret
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
##
|
282
|
+
# @private New HmacKey from a Google::Apis::StorageV1::HmacKeyMetadata
|
283
|
+
# object.
|
284
|
+
#
|
285
|
+
# @param [Google::Apis::StorageV1::HmacKeyMetadata] gapi
|
286
|
+
#
|
287
|
+
#
|
288
|
+
def self.from_gapi_metadata gapi, service, user_project: nil
|
289
|
+
new.tap do |f|
|
290
|
+
f.gapi = gapi
|
291
|
+
f.service = service
|
292
|
+
f.user_project = user_project
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
protected
|
297
|
+
|
298
|
+
##
|
299
|
+
# Raise an error unless an active service is available.
|
300
|
+
def ensure_service!
|
301
|
+
raise "Must have active connection" unless service
|
302
|
+
end
|
303
|
+
|
304
|
+
def put_gapi! new_state
|
305
|
+
ensure_service!
|
306
|
+
put_gapi = @gapi.dup
|
307
|
+
put_gapi.state = new_state
|
308
|
+
@gapi = service.update_hmac_key access_id, put_gapi,
|
309
|
+
project_id: project_id,
|
310
|
+
user_project: @user_project
|
311
|
+
self
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
# Copyright 2019 Google LLC
|
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
|
+
# https://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
|
+
|
16
|
+
require "delegate"
|
17
|
+
|
18
|
+
module Google
|
19
|
+
module Cloud
|
20
|
+
module Storage
|
21
|
+
class HmacKey
|
22
|
+
##
|
23
|
+
# HmacKey::List is a special case Array with additional values.
|
24
|
+
class List < DelegateClass(::Array)
|
25
|
+
##
|
26
|
+
# If not empty, indicates that there are more HMAC keys
|
27
|
+
# that match the request and this value should be passed to
|
28
|
+
# the next {Google::Cloud::Storage::Project#hmac_keys} to continue.
|
29
|
+
attr_accessor :token
|
30
|
+
|
31
|
+
##
|
32
|
+
# @private Create a new HmacKey::List with an array of values.
|
33
|
+
def initialize arr = []
|
34
|
+
super arr
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Whether there is a next page of HMAC keys.
|
39
|
+
#
|
40
|
+
# @return [Boolean]
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# require "google/cloud/storage"
|
44
|
+
#
|
45
|
+
# storage = Google::Cloud::Storage.new
|
46
|
+
#
|
47
|
+
# hmac_keys = storage.hmac_keys
|
48
|
+
# if hmac_keys.next?
|
49
|
+
# next_hmac_keys = hmac_keys.next
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
def next?
|
53
|
+
!token.nil?
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Retrieve the next page of HMAC keys.
|
58
|
+
#
|
59
|
+
# @return [HmacKey::List]
|
60
|
+
#
|
61
|
+
# @example
|
62
|
+
# require "google/cloud/storage"
|
63
|
+
#
|
64
|
+
# storage = Google::Cloud::Storage.new
|
65
|
+
#
|
66
|
+
# hmac_keys = storage.hmac_keys
|
67
|
+
# if hmac_keys.next?
|
68
|
+
# next_hmac_keys = hmac_keys.next
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
def next
|
72
|
+
return nil unless next?
|
73
|
+
ensure_service!
|
74
|
+
gapi = @service.list_hmac_keys \
|
75
|
+
service_account_email: @service_account_email,
|
76
|
+
show_deleted_keys: @show_deleted_keys, token: @token, max: @max,
|
77
|
+
user_project: @user_project
|
78
|
+
|
79
|
+
HmacKey::List.from_gapi \
|
80
|
+
gapi, @service,
|
81
|
+
service_account_email: @service_account_email,
|
82
|
+
show_deleted_keys: @show_deleted_keys, max: @max,
|
83
|
+
user_project: @user_project
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Retrieves remaining results by repeatedly invoking {#next} until
|
88
|
+
# {#next?} returns `false`. Calls the given block once for each
|
89
|
+
# result, which is passed as the argument to the block.
|
90
|
+
#
|
91
|
+
# An Enumerator is returned if no block is given.
|
92
|
+
#
|
93
|
+
# This method will make repeated API calls until all remaining results
|
94
|
+
# are retrieved. (Unlike `#each`, for example, which merely iterates
|
95
|
+
# over the results returned by a single API call.) Use with caution.
|
96
|
+
#
|
97
|
+
# @param [Integer] request_limit The upper limit of API requests to
|
98
|
+
# make to load all HMAC keys. Default is no limit.
|
99
|
+
# @yield [key] The block for accessing each HMAC key.
|
100
|
+
# @yieldparam [HmacKey] key The HMAC key object.
|
101
|
+
#
|
102
|
+
# @return [Enumerator]
|
103
|
+
#
|
104
|
+
# @example Iterating each HMAC key by passing a block:
|
105
|
+
# require "google/cloud/storage"
|
106
|
+
#
|
107
|
+
# storage = Google::Cloud::Storage.new
|
108
|
+
#
|
109
|
+
# hmac_keys = storage.hmac_keys
|
110
|
+
# hmac_keys.all do |key|
|
111
|
+
# puts key.access_id
|
112
|
+
# end
|
113
|
+
#
|
114
|
+
# @example Using the enumerator by not passing a block:
|
115
|
+
# require "google/cloud/storage"
|
116
|
+
#
|
117
|
+
# storage = Google::Cloud::Storage.new
|
118
|
+
#
|
119
|
+
# hmac_keys = storage.hmac_keys
|
120
|
+
# all_names = hmac_keys.all.map do |key|
|
121
|
+
# key.access_id
|
122
|
+
# end
|
123
|
+
#
|
124
|
+
# @example Limit the number of API calls made:
|
125
|
+
# require "google/cloud/storage"
|
126
|
+
#
|
127
|
+
# storage = Google::Cloud::Storage.new
|
128
|
+
#
|
129
|
+
# hmac_keys = storage.hmac_keys
|
130
|
+
# hmac_keys.all(request_limit: 10) do |key|
|
131
|
+
# puts key.access_id
|
132
|
+
# end
|
133
|
+
#
|
134
|
+
def all request_limit: nil
|
135
|
+
request_limit = request_limit.to_i if request_limit
|
136
|
+
unless block_given?
|
137
|
+
return enum_for :all, request_limit: request_limit
|
138
|
+
end
|
139
|
+
results = self
|
140
|
+
loop do
|
141
|
+
results.each { |r| yield r }
|
142
|
+
if request_limit
|
143
|
+
request_limit -= 1
|
144
|
+
break if request_limit < 0
|
145
|
+
end
|
146
|
+
break unless results.next?
|
147
|
+
results = results.next
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
##
|
152
|
+
# @private New HmacKey::List from a Google API Client
|
153
|
+
# Google::Apis::StorageV1::HmacKeysMetadata object.
|
154
|
+
def self.from_gapi gapi_list, service, service_account_email: nil,
|
155
|
+
show_deleted_keys: nil, max: nil, user_project: nil
|
156
|
+
hmac_keys = new(Array(gapi_list.items).map do |gapi_object|
|
157
|
+
HmacKey.from_gapi_metadata gapi_object, service,
|
158
|
+
user_project: user_project
|
159
|
+
end)
|
160
|
+
hmac_keys.instance_variable_set :@token, gapi_list.next_page_token
|
161
|
+
hmac_keys.instance_variable_set :@service, service
|
162
|
+
hmac_keys.instance_variable_set :@service_account_email,
|
163
|
+
service_account_email
|
164
|
+
hmac_keys.instance_variable_set :@show_deleted_keys,
|
165
|
+
show_deleted_keys
|
166
|
+
hmac_keys.instance_variable_set :@max, max
|
167
|
+
hmac_keys.instance_variable_set :@user_project, user_project
|
168
|
+
hmac_keys
|
169
|
+
end
|
170
|
+
|
171
|
+
protected
|
172
|
+
|
173
|
+
##
|
174
|
+
# Raise an error unless an active connection is available.
|
175
|
+
def ensure_service!
|
176
|
+
raise "Must have active connection" unless @service
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -21,6 +21,7 @@ require "google/cloud/storage/bucket"
|
|
21
21
|
require "google/cloud/storage/bucket/cors"
|
22
22
|
require "google/cloud/storage/bucket/lifecycle"
|
23
23
|
require "google/cloud/storage/file"
|
24
|
+
require "google/cloud/storage/hmac_key"
|
24
25
|
|
25
26
|
module Google
|
26
27
|
module Cloud
|
@@ -384,6 +385,91 @@ module Google
|
|
384
385
|
Bucket.from_gapi gapi, service, user_project: user_project
|
385
386
|
end
|
386
387
|
|
388
|
+
##
|
389
|
+
# Creates a new HMAC key.
|
390
|
+
#
|
391
|
+
# @param [String] service_account_email The email address of the service
|
392
|
+
# account. Used to create the HMAC key.
|
393
|
+
# @param [String] project_id The project ID associated with
|
394
|
+
# `service_account_email`, if `service_account_email` belongs to a
|
395
|
+
# project other than the currently authenticated project. Optional. If
|
396
|
+
# not provided, the project ID for the current project will be used.
|
397
|
+
# @param [String] user_project If this parameter is set to a project ID
|
398
|
+
# other than the current project, and that project is authorized for
|
399
|
+
# the currently authenticated service account, transit costs will be
|
400
|
+
# billed to the given project. The default is `nil`.
|
401
|
+
#
|
402
|
+
# @return [Google::Cloud::Storage::HmacKey]
|
403
|
+
#
|
404
|
+
def create_hmac_key service_account_email, project_id: nil,
|
405
|
+
user_project: nil
|
406
|
+
gapi = service.create_hmac_key service_account_email,
|
407
|
+
project_id: project_id,
|
408
|
+
user_project: user_project
|
409
|
+
HmacKey.from_gapi gapi, service, user_project: user_project
|
410
|
+
end
|
411
|
+
|
412
|
+
##
|
413
|
+
# Retrieves an HMAC key's metadata; the key's secret is not included in
|
414
|
+
# the representation.
|
415
|
+
#
|
416
|
+
# @param [String] project_id The project ID associated with the
|
417
|
+
# `service_account_email` used to create the HMAC key, if the
|
418
|
+
# service account email belongs to a project other than the
|
419
|
+
# currently authenticated project. Optional. If not provided, the
|
420
|
+
# project ID for current project will be used.
|
421
|
+
# @param [String] user_project If this parameter is set to a project ID
|
422
|
+
# other than the current project, and that project is authorized for
|
423
|
+
# the currently authenticated service account, transit costs will be
|
424
|
+
# billed to the given project. The default is `nil`.
|
425
|
+
#
|
426
|
+
# @return [Google::Cloud::Storage::HmacKey]
|
427
|
+
#
|
428
|
+
def hmac_key access_id, project_id: nil, user_project: nil
|
429
|
+
gapi = service.get_hmac_key \
|
430
|
+
access_id, project_id: project_id, user_project: user_project
|
431
|
+
HmacKey.from_gapi_metadata gapi, service, user_project: user_project
|
432
|
+
end
|
433
|
+
|
434
|
+
##
|
435
|
+
# Retrieves a list of HMAC key metadata matching the criteria; the keys'
|
436
|
+
# secrets are not included.
|
437
|
+
#
|
438
|
+
# @param [String] service_account_email
|
439
|
+
# If present, only keys for the given service account are returned.
|
440
|
+
# @param [String] project_id The project ID associated with the
|
441
|
+
# `service_account_email` used to create the HMAC keys, if the
|
442
|
+
# service account email belongs to a project other than the
|
443
|
+
# currently authenticated project. Optional. If not provided, the
|
444
|
+
# project ID for current project will be used.
|
445
|
+
# @param [Boolean] show_deleted_keys
|
446
|
+
# Whether to include keys in the `DELETED` state. The default value is
|
447
|
+
# false.
|
448
|
+
# @param [String] token A previously-returned page token representing
|
449
|
+
# part of the larger set of results to view.
|
450
|
+
# @param [Integer] max Maximum number of keys to return.
|
451
|
+
# @param [String] user_project If this parameter is set to a project ID
|
452
|
+
# other than the current project, and that project is authorized for
|
453
|
+
# the currently authenticated service account, transit costs will be
|
454
|
+
# billed to the given project. The default is `nil`.
|
455
|
+
#
|
456
|
+
# @return [Google::Cloud::Storage::HmacKey]
|
457
|
+
#
|
458
|
+
def hmac_keys service_account_email: nil, project_id: nil,
|
459
|
+
show_deleted_keys: nil, token: nil, max: nil,
|
460
|
+
user_project: nil
|
461
|
+
gapi = service.list_hmac_keys \
|
462
|
+
max: max, token: token,
|
463
|
+
service_account_email: service_account_email,
|
464
|
+
project_id: project_id, show_deleted_keys: show_deleted_keys,
|
465
|
+
user_project: user_project
|
466
|
+
|
467
|
+
HmacKey::List.from_gapi \
|
468
|
+
gapi, service,
|
469
|
+
service_account_email: nil, show_deleted_keys: nil,
|
470
|
+
max: max, user_project: user_project
|
471
|
+
end
|
472
|
+
|
387
473
|
##
|
388
474
|
# Generates a signed URL. See [Signed
|
389
475
|
# URLs](https://cloud.google.com/storage/docs/access-control/signed-urls)
|
@@ -16,7 +16,7 @@
|
|
16
16
|
require "google/cloud/storage/version"
|
17
17
|
require "google/apis/storage_v1"
|
18
18
|
require "digest"
|
19
|
-
require "
|
19
|
+
require "mini_mime"
|
20
20
|
require "pathname"
|
21
21
|
|
22
22
|
module Google
|
@@ -451,11 +451,75 @@ module Google
|
|
451
451
|
end
|
452
452
|
end
|
453
453
|
|
454
|
+
##
|
455
|
+
# Creates a new HMAC key for the specified service account.
|
456
|
+
# Returns Google::Apis::StorageV1::HmacKey.
|
457
|
+
def create_hmac_key service_account_email, project_id: nil,
|
458
|
+
user_project: nil
|
459
|
+
execute do
|
460
|
+
service.create_project_hmac_key \
|
461
|
+
(project_id || @project), service_account_email,
|
462
|
+
user_project: user_project(user_project)
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
##
|
467
|
+
# Deletes an HMAC key. Key must be in the INACTIVE state.
|
468
|
+
def delete_hmac_key access_id, project_id: nil, user_project: nil
|
469
|
+
execute do
|
470
|
+
service.delete_project_hmac_key \
|
471
|
+
(project_id || @project), access_id,
|
472
|
+
user_project: user_project(user_project)
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
##
|
477
|
+
# Retrieves an HMAC key's metadata.
|
478
|
+
# Returns Google::Apis::StorageV1::HmacKeyMetadata.
|
479
|
+
def get_hmac_key access_id, project_id: nil, user_project: nil
|
480
|
+
execute do
|
481
|
+
service.get_project_hmac_key \
|
482
|
+
(project_id || @project), access_id,
|
483
|
+
user_project: user_project(user_project)
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
##
|
488
|
+
# Retrieves a list of HMAC key metadata matching the criteria.
|
489
|
+
# Returns Google::Apis::StorageV1::HmacKeysMetadata.
|
490
|
+
def list_hmac_keys max: nil, token: nil, service_account_email: nil,
|
491
|
+
project_id: nil, show_deleted_keys: nil,
|
492
|
+
user_project: nil
|
493
|
+
execute do
|
494
|
+
service.list_project_hmac_keys \
|
495
|
+
(project_id || @project),
|
496
|
+
max_results: max, page_token: token,
|
497
|
+
service_account_email: service_account_email,
|
498
|
+
show_deleted_keys: show_deleted_keys,
|
499
|
+
user_project: user_project(user_project)
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
##
|
504
|
+
# Updates the state of an HMAC key. See the HMAC Key resource descriptor
|
505
|
+
# for valid states.
|
506
|
+
# Returns Google::Apis::StorageV1::HmacKeyMetadata.
|
507
|
+
def update_hmac_key access_id, hmac_key_metadata_object,
|
508
|
+
project_id: nil, user_project: nil
|
509
|
+
execute do
|
510
|
+
service.update_project_hmac_key \
|
511
|
+
(project_id || @project), access_id, hmac_key_metadata_object,
|
512
|
+
user_project: user_project(user_project)
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
454
516
|
##
|
455
517
|
# Retrieves the mime-type for a file path.
|
456
518
|
# An empty string is returned if no mime-type can be found.
|
457
519
|
def mime_type_for path
|
458
|
-
|
520
|
+
mime_type = MiniMime.lookup_by_filename path
|
521
|
+
return "" if mime_type.nil?
|
522
|
+
mime_type.content_type
|
459
523
|
end
|
460
524
|
|
461
525
|
# @private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|
@@ -88,19 +88,19 @@ dependencies:
|
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '2.5'
|
90
90
|
- !ruby/object:Gem::Dependency
|
91
|
-
name:
|
91
|
+
name: mini_mime
|
92
92
|
requirement: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '1.0'
|
97
97
|
type: :runtime
|
98
98
|
prerelease: false
|
99
99
|
version_requirements: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '1.0'
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
105
|
name: minitest
|
106
106
|
requirement: !ruby/object:Gem::Requirement
|
@@ -274,6 +274,8 @@ files:
|
|
274
274
|
- lib/google/cloud/storage/file/signer_v2.rb
|
275
275
|
- lib/google/cloud/storage/file/signer_v4.rb
|
276
276
|
- lib/google/cloud/storage/file/verifier.rb
|
277
|
+
- lib/google/cloud/storage/hmac_key.rb
|
278
|
+
- lib/google/cloud/storage/hmac_key/list.rb
|
277
279
|
- lib/google/cloud/storage/notification.rb
|
278
280
|
- lib/google/cloud/storage/policy.rb
|
279
281
|
- lib/google/cloud/storage/post_object.rb
|
@@ -299,7 +301,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
299
301
|
- !ruby/object:Gem::Version
|
300
302
|
version: '0'
|
301
303
|
requirements: []
|
302
|
-
rubygems_version: 3.0.
|
304
|
+
rubygems_version: 3.0.4
|
303
305
|
signing_key:
|
304
306
|
specification_version: 4
|
305
307
|
summary: API Client library for Google Cloud Storage
|