gcloud 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +8 -0
- data/lib/gcloud.rb +48 -30
- data/lib/gcloud/bigquery.rb +4 -6
- data/lib/gcloud/bigquery/connection.rb +2 -14
- data/lib/gcloud/bigquery/dataset.rb +41 -42
- data/lib/gcloud/bigquery/project.rb +50 -46
- data/lib/gcloud/bigquery/query_job.rb +7 -8
- data/lib/gcloud/bigquery/table.rb +54 -55
- data/lib/gcloud/bigquery/table/schema.rb +30 -40
- data/lib/gcloud/bigquery/view.rb +10 -11
- data/lib/gcloud/credentials.rb +19 -25
- data/lib/gcloud/datastore.rb +4 -6
- data/lib/gcloud/datastore/dataset.rb +3 -5
- data/lib/gcloud/dns.rb +4 -6
- data/lib/gcloud/dns/connection.rb +17 -16
- data/lib/gcloud/dns/importer.rb +5 -11
- data/lib/gcloud/dns/project.rb +11 -12
- data/lib/gcloud/dns/zone.rb +52 -92
- data/lib/gcloud/dns/zone/transaction.rb +2 -2
- data/lib/gcloud/pubsub.rb +4 -6
- data/lib/gcloud/pubsub/connection.rb +1 -12
- data/lib/gcloud/pubsub/project.rb +30 -36
- data/lib/gcloud/pubsub/subscription.rb +18 -26
- data/lib/gcloud/pubsub/topic.rb +16 -26
- data/lib/gcloud/resource_manager.rb +5 -6
- data/lib/gcloud/resource_manager/connection.rb +4 -4
- data/lib/gcloud/resource_manager/manager.rb +10 -14
- data/lib/gcloud/resource_manager/project.rb +3 -5
- data/lib/gcloud/search.rb +295 -0
- data/lib/gcloud/search/api_client.rb +144 -0
- data/lib/gcloud/search/connection.rb +146 -0
- data/lib/gcloud/search/credentials.rb +30 -0
- data/lib/gcloud/search/document.rb +301 -0
- data/lib/gcloud/search/document/list.rb +85 -0
- data/lib/gcloud/search/errors.rb +67 -0
- data/lib/gcloud/search/field_value.rb +164 -0
- data/lib/gcloud/search/field_values.rb +263 -0
- data/lib/gcloud/search/fields.rb +267 -0
- data/lib/gcloud/search/index.rb +613 -0
- data/lib/gcloud/search/index/list.rb +90 -0
- data/lib/gcloud/search/project.rb +197 -0
- data/lib/gcloud/search/result.rb +169 -0
- data/lib/gcloud/search/result/list.rb +95 -0
- data/lib/gcloud/storage.rb +4 -6
- data/lib/gcloud/storage/bucket.rb +55 -43
- data/lib/gcloud/storage/bucket/cors.rb +5 -7
- data/lib/gcloud/storage/file.rb +35 -30
- data/lib/gcloud/storage/file/acl.rb +12 -16
- data/lib/gcloud/storage/project.rb +56 -22
- data/lib/gcloud/version.rb +1 -1
- metadata +20 -3
@@ -0,0 +1,95 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2015 Google Inc. All rights reserved.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
module Gcloud
|
17
|
+
module Search
|
18
|
+
class Result
|
19
|
+
##
|
20
|
+
# Result::List is a special case Array with additional values.
|
21
|
+
class List < DelegateClass(::Array)
|
22
|
+
##
|
23
|
+
# If not empty, indicates that there are more records that match
|
24
|
+
# the request and this value should be passed to continue.
|
25
|
+
attr_reader :token
|
26
|
+
|
27
|
+
##
|
28
|
+
# The number of documents that match the query. It is greater than or
|
29
|
+
# equal to the number of documents actually returned. This is an
|
30
|
+
# approximation and not an exact count unless it is less than or equal
|
31
|
+
# to the Index#search +matched_count_accuracy+ option.
|
32
|
+
attr_reader :matched_count
|
33
|
+
|
34
|
+
##
|
35
|
+
# Create a new Result::List with an array of Result instances.
|
36
|
+
def initialize arr = []
|
37
|
+
super arr
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Whether there a next page of results.
|
42
|
+
def next?
|
43
|
+
!token.nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# Retrieve the next page of results.
|
48
|
+
def next
|
49
|
+
return nil unless next?
|
50
|
+
ensure_index!
|
51
|
+
@index.search @query, @search_options.merge(token: token)
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Retrieves all results by repeatedly loading pages until #next?
|
56
|
+
# returns false. Returns the list instance for method chaining.
|
57
|
+
def all
|
58
|
+
while next?
|
59
|
+
next_results = self.next
|
60
|
+
push(*next_results)
|
61
|
+
self.token = next_results.token
|
62
|
+
end
|
63
|
+
self
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# New Result::List from a response object.
|
68
|
+
def self.from_response resp, index, query, search_options #:nodoc:
|
69
|
+
data = JSON.parse resp.body
|
70
|
+
results = new(Array(data["results"]).map do |raw|
|
71
|
+
Result.from_hash raw
|
72
|
+
end)
|
73
|
+
results.instance_eval do
|
74
|
+
@token = data["results"].last["nextPageToken"]
|
75
|
+
@matched_count = data["matchedCount"]
|
76
|
+
@index = index
|
77
|
+
@query = query
|
78
|
+
@search_options = search_options
|
79
|
+
end
|
80
|
+
results
|
81
|
+
rescue JSON::ParserError
|
82
|
+
ApiError.from_response_status resp
|
83
|
+
end
|
84
|
+
|
85
|
+
protected
|
86
|
+
|
87
|
+
##
|
88
|
+
# Raise an error unless an active connection is available.
|
89
|
+
def ensure_index!
|
90
|
+
fail "Must have active connection" unless @index
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/lib/gcloud/storage.rb
CHANGED
@@ -31,9 +31,7 @@ module Gcloud
|
|
31
31
|
# +keyfile+::
|
32
32
|
# Keyfile downloaded from Google Cloud. If file path the file must be
|
33
33
|
# readable. (+String+ or +Hash+)
|
34
|
-
# +
|
35
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
36
|
-
# <code>options[:scope]</code>::
|
34
|
+
# +scope+::
|
37
35
|
# The OAuth 2.0 scopes controlling the set of resources and operations that
|
38
36
|
# the connection can access. See {Using OAuth 2.0 to Access Google
|
39
37
|
# APIs}[https://developers.google.com/identity/protocols/OAuth2]. (+String+
|
@@ -57,12 +55,12 @@ module Gcloud
|
|
57
55
|
# bucket = storage.bucket "my-bucket"
|
58
56
|
# file = bucket.file "path/to/my-file.ext"
|
59
57
|
#
|
60
|
-
def self.storage project = nil, keyfile = nil,
|
58
|
+
def self.storage project = nil, keyfile = nil, scope: nil
|
61
59
|
project ||= Gcloud::Storage::Project.default_project
|
62
60
|
if keyfile.nil?
|
63
|
-
credentials = Gcloud::Storage::Credentials.default
|
61
|
+
credentials = Gcloud::Storage::Credentials.default scope: scope
|
64
62
|
else
|
65
|
-
credentials = Gcloud::Storage::Credentials.new keyfile,
|
63
|
+
credentials = Gcloud::Storage::Credentials.new keyfile, scope: scope
|
66
64
|
end
|
67
65
|
Gcloud::Storage::Project.new project, credentials
|
68
66
|
end
|
@@ -304,9 +304,7 @@ module Gcloud
|
|
304
304
|
#
|
305
305
|
# === Parameters
|
306
306
|
#
|
307
|
-
# +
|
308
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
309
|
-
# <code>options[:retries]</code>::
|
307
|
+
# +retries+::
|
310
308
|
# The number of times the API call should be retried.
|
311
309
|
# Default is Gcloud::Backoff.retries. (+Integer+)
|
312
310
|
#
|
@@ -336,8 +334,9 @@ module Gcloud
|
|
336
334
|
# bucket = storage.bucket "my-bucket"
|
337
335
|
# bucket.delete retries: 5
|
338
336
|
#
|
339
|
-
def delete
|
337
|
+
def delete retries: nil
|
340
338
|
ensure_connection!
|
339
|
+
options = { retries: retries }
|
341
340
|
resp = connection.delete_bucket name, options
|
342
341
|
if resp.success?
|
343
342
|
true
|
@@ -351,26 +350,22 @@ module Gcloud
|
|
351
350
|
#
|
352
351
|
# === Parameters
|
353
352
|
#
|
354
|
-
# +
|
355
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
356
|
-
# <code>options[:prefix]</code>::
|
353
|
+
# +prefix+::
|
357
354
|
# Filter results to files whose names begin with this prefix.
|
358
355
|
# (+String+)
|
359
|
-
#
|
356
|
+
# +token+::
|
360
357
|
# A previously-returned page token representing part of the larger set
|
361
358
|
# of results to view. (+String+)
|
362
|
-
#
|
359
|
+
# +max+::
|
363
360
|
# Maximum number of items plus prefixes to return. As duplicate prefixes
|
364
361
|
# are omitted, fewer total results may be returned than requested.
|
365
362
|
# The default value of this parameter is 1,000 items. (+Integer+)
|
366
|
-
#
|
363
|
+
# +versions+::
|
367
364
|
# If +true+, lists all versions of an object as distinct results.
|
368
365
|
# The default is +false+. For more information, see
|
369
366
|
# {Object Versioning
|
370
367
|
# }[https://cloud.google.com/storage/docs/object-versioning].
|
371
368
|
# (+Boolean+)
|
372
|
-
# <code>options[:max]</code>::
|
373
|
-
# Maximum number of buckets to return. (+Integer+)
|
374
369
|
#
|
375
370
|
# === Returns
|
376
371
|
#
|
@@ -411,8 +406,9 @@ module Gcloud
|
|
411
406
|
# tmp_files = bucket.files token: tmp_files.token
|
412
407
|
# end
|
413
408
|
#
|
414
|
-
def files
|
409
|
+
def files prefix: nil, token: nil, max: nil, versions: nil
|
415
410
|
ensure_connection!
|
411
|
+
options = { prefix: prefix, token: token, max: max, versions: versions }
|
416
412
|
resp = connection.list_files name, options
|
417
413
|
if resp.success?
|
418
414
|
File::List.from_response resp, connection
|
@@ -429,6 +425,9 @@ module Gcloud
|
|
429
425
|
#
|
430
426
|
# +path+::
|
431
427
|
# Name (path) of the file. (+String+)
|
428
|
+
# +generation+::
|
429
|
+
# When present, selects a specific revision of this object.
|
430
|
+
# Default is the latest version. (+Integer+)
|
432
431
|
#
|
433
432
|
# === Returns
|
434
433
|
#
|
@@ -446,8 +445,9 @@ module Gcloud
|
|
446
445
|
# file = bucket.file "path/to/my-file.ext"
|
447
446
|
# puts file.name
|
448
447
|
#
|
449
|
-
def file path,
|
448
|
+
def file path, generation: nil
|
450
449
|
ensure_connection!
|
450
|
+
options = { generation: generation }
|
451
451
|
resp = connection.get_file name, path, options
|
452
452
|
if resp.success?
|
453
453
|
File.from_gapi resp.data, connection
|
@@ -467,9 +467,7 @@ module Gcloud
|
|
467
467
|
# Path of the file on the filesystem to upload. (+String+)
|
468
468
|
# +path+::
|
469
469
|
# Path to store the file in Google Cloud Storage. (+String+)
|
470
|
-
# +
|
471
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
472
|
-
# <code>options[:acl]</code>::
|
470
|
+
# +acl+::
|
473
471
|
# A predefined set of access controls to apply to this file.
|
474
472
|
# (+String+)
|
475
473
|
#
|
@@ -486,40 +484,40 @@ module Gcloud
|
|
486
484
|
# and project team members get access according to their roles.
|
487
485
|
# * +public+, +public_read+, +publicRead+ - File owner gets OWNER
|
488
486
|
# access, and allUsers get READER access.
|
489
|
-
#
|
487
|
+
# +cache_control+::
|
490
488
|
# The {Cache-Control}[https://tools.ietf.org/html/rfc7234#section-5.2]
|
491
489
|
# response header to be returned when the file is downloaded. (+String+)
|
492
|
-
#
|
490
|
+
# +content_disposition+::
|
493
491
|
# The {Content-Disposition}[https://tools.ietf.org/html/rfc6266]
|
494
492
|
# response header to be returned when the file is downloaded. (+String+)
|
495
|
-
#
|
493
|
+
# +content_encoding+::
|
496
494
|
# The {Content-Encoding
|
497
495
|
# }[https://tools.ietf.org/html/rfc7231#section-3.1.2.2] response header
|
498
496
|
# to be returned when the file is downloaded. (+String+)
|
499
|
-
#
|
497
|
+
# +content_language+::
|
500
498
|
# The {Content-Language}[http://tools.ietf.org/html/bcp47] response
|
501
499
|
# header to be returned when the file is downloaded. (+String+)
|
502
|
-
#
|
500
|
+
# +content_type+::
|
503
501
|
# The {Content-Type}[https://tools.ietf.org/html/rfc2616#section-14.17]
|
504
502
|
# response header to be returned when the file is downloaded. (+String+)
|
505
|
-
#
|
503
|
+
# +chunk_size+::
|
506
504
|
# The number of bytes per chunk in a resumable upload. Must be divisible
|
507
505
|
# by 256KB. If it is not divisible by 265KB then it will be lowered to
|
508
506
|
# the nearest acceptable value. (+Integer+)
|
509
|
-
#
|
507
|
+
# +crc32c+::
|
510
508
|
# The CRC32c checksum of the file data, as described in
|
511
509
|
# {RFC 4960, Appendix B}[http://tools.ietf.org/html/rfc4960#appendix-B].
|
512
510
|
# If provided, Cloud Storage will only create the file if the value
|
513
511
|
# matches the value calculated by the service. See
|
514
512
|
# {Validation}[https://cloud.google.com/storage/docs/hashes-etags]
|
515
513
|
# for more information. (+String+)
|
516
|
-
#
|
514
|
+
# +md5+::
|
517
515
|
# The MD5 hash of the file data. If provided, Cloud Storage will only
|
518
516
|
# create the file if the value matches the value calculated by the
|
519
517
|
# service. See
|
520
518
|
# {Validation}[https://cloud.google.com/storage/docs/hashes-etags]
|
521
519
|
# for more information. (+String+)
|
522
|
-
#
|
520
|
+
# +metadata+::
|
523
521
|
# A hash of custom, user-provided web-safe keys and arbitrary string
|
524
522
|
# values that will returned with requests for the file as "x-goog-meta-"
|
525
523
|
# response headers. (+Hash+)
|
@@ -551,7 +549,7 @@ module Gcloud
|
|
551
549
|
# bucket.create_file "path/to/local.file.ext",
|
552
550
|
# "destination/path/file.ext"
|
553
551
|
#
|
554
|
-
# A chunk_size value can be provided in the options to be used
|
552
|
+
# A +chunk_size+ value can be provided in the options to be used
|
555
553
|
# in resumable uploads. This value is the number of bytes per
|
556
554
|
# chunk and must be divisible by 256KB. If it is not divisible
|
557
555
|
# by 265KB then it will be lowered to the nearest acceptable
|
@@ -568,17 +566,27 @@ module Gcloud
|
|
568
566
|
# "destination/path/file.ext",
|
569
567
|
# chunk_size: 1024*1024 # 1 MB chunk
|
570
568
|
#
|
571
|
-
# ====
|
569
|
+
# ==== Troubleshooting large uploads
|
572
570
|
#
|
573
|
-
# You may encounter
|
574
|
-
#
|
571
|
+
# You may encounter errors while attempting to upload large files. Below
|
572
|
+
# are a couple of common cases and their solutions.
|
573
|
+
#
|
574
|
+
# ===== Handling memory errors
|
575
|
+
#
|
576
|
+
# If you encounter a memory error such as +NoMemoryError+, try performing
|
577
|
+
# a resumable upload and setting the +chunk_size+ option to a value that
|
578
|
+
# works for your environment, as explained in the final example above.
|
579
|
+
#
|
580
|
+
# ===== Handling broken pipe errors
|
581
|
+
#
|
582
|
+
# To avoid broken pipe (+Errno::EPIPE+) errors when uploading, add the
|
575
583
|
# {httpclient}[https://rubygems.org/gems/httpclient] gem to your project,
|
576
|
-
# and the
|
577
|
-
#
|
578
|
-
#
|
579
|
-
#
|
580
|
-
#
|
581
|
-
#
|
584
|
+
# and the configuration shown below. These lines must execute after you
|
585
|
+
# require gcloud but before you make your first gcloud connection. The
|
586
|
+
# first statement configures {Faraday}[https://rubygems.org/gems/faraday]
|
587
|
+
# to use httpclient. The second statement, which should only be added if
|
588
|
+
# you are using a version of Faraday at or above 0.9.2, is a workaround
|
589
|
+
# for {this gzip
|
582
590
|
# issue}[https://github.com/GoogleCloudPlatform/gcloud-ruby/issues/367].
|
583
591
|
#
|
584
592
|
# require "gcloud"
|
@@ -594,18 +602,22 @@ module Gcloud
|
|
594
602
|
# gcloud = Gcloud.new
|
595
603
|
# storage = gcloud.storage
|
596
604
|
#
|
597
|
-
def create_file file, path = nil,
|
605
|
+
def create_file file, path = nil, acl: nil, cache_control: nil,
|
606
|
+
content_disposition: nil, content_encoding: nil,
|
607
|
+
content_language: nil, content_type: nil, chunk_size: nil,
|
608
|
+
crc32c: nil, md5: nil, metadata: nil
|
598
609
|
ensure_connection!
|
610
|
+
options = { acl: File::Acl.predefined_rule_for(acl), md5: md5,
|
611
|
+
cache_control: cache_control, content_type: content_type,
|
612
|
+
content_disposition: content_disposition, crc32c: crc32c,
|
613
|
+
content_encoding: content_encoding, chunk_size: chunk_size,
|
614
|
+
content_language: content_language, metadata: metadata }
|
599
615
|
ensure_file_exists! file
|
600
|
-
options[:acl] = File::Acl.predefined_rule_for options[:acl]
|
601
616
|
resumable = resumable_upload?(file)
|
602
617
|
resp = @connection.upload_file resumable, name, file, path, options
|
603
618
|
|
604
|
-
if resp.success?
|
605
|
-
|
606
|
-
else
|
607
|
-
fail ApiError.from_response(resp)
|
608
|
-
end
|
619
|
+
return File.from_gapi(resp.data, connection) if resp.success?
|
620
|
+
fail ApiError.from_response(resp)
|
609
621
|
end
|
610
622
|
alias_method :upload_file, :create_file
|
611
623
|
alias_method :new_file, :create_file
|
@@ -75,14 +75,12 @@ module Gcloud
|
|
75
75
|
# The list of HTTP methods permitted in cross origin resource sharing
|
76
76
|
# with the bucket. (GET, OPTIONS, POST, etc) Note: "*" is permitted in
|
77
77
|
# the list of methods, and means "any method". (+String+ or +Array+)
|
78
|
-
# +
|
79
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
80
|
-
# <code>options[:headers]</code>::
|
78
|
+
# +headers+::
|
81
79
|
# The list of header field names to send in the
|
82
80
|
# Access-Control-Allow-Headers header in the preflight response.
|
83
81
|
# Indicates the custom request headers that may be used in the actual
|
84
82
|
# request. (+String+ or +Array+)
|
85
|
-
#
|
83
|
+
# +max_age+::
|
86
84
|
# The value to send in the Access-Control-Max-Age header in the
|
87
85
|
# preflight response. Indicates how many seconds the results of a
|
88
86
|
# preflight request can be cached in a preflight result cache. The
|
@@ -102,10 +100,10 @@ module Gcloud
|
|
102
100
|
# max_age: 300
|
103
101
|
# end
|
104
102
|
#
|
105
|
-
def add_rule origin, methods,
|
103
|
+
def add_rule origin, methods, headers: nil, max_age: nil
|
106
104
|
rule = { "origin" => Array(origin), "method" => Array(methods) }
|
107
|
-
rule["responseHeader"] = Array(
|
108
|
-
rule["maxAgeSeconds"]
|
105
|
+
rule["responseHeader"] = Array(headers) || []
|
106
|
+
rule["maxAgeSeconds"] = max_age || 1800
|
109
107
|
push rule
|
110
108
|
end
|
111
109
|
end
|
data/lib/gcloud/storage/file.rb
CHANGED
@@ -284,9 +284,7 @@ module Gcloud
|
|
284
284
|
# +path+::
|
285
285
|
# The path on the local file system to write the data to.
|
286
286
|
# The path provided must be writable. (+String+)
|
287
|
-
# +
|
288
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
289
|
-
# <code>options[:verify]</code>::
|
287
|
+
# +verify+::
|
290
288
|
# The verification algoruthm used to ensure the downloaded file contents
|
291
289
|
# are correct. Default is +:md5+. (+Symbol+)
|
292
290
|
#
|
@@ -349,14 +347,14 @@ module Gcloud
|
|
349
347
|
# file = bucket.file "path/to/my-file.ext"
|
350
348
|
# file.download "path/to/downloaded/file.ext", verify: :none
|
351
349
|
#
|
352
|
-
def download path,
|
350
|
+
def download path, verify: :md5
|
353
351
|
ensure_connection!
|
354
352
|
resp = connection.download_file bucket, name
|
355
353
|
if resp.success?
|
356
354
|
::File.open path, "wb+" do |f|
|
357
355
|
f.write resp.body
|
358
356
|
end
|
359
|
-
verify_file! ::File.new(path),
|
357
|
+
verify_file! ::File.new(path), verify
|
360
358
|
else
|
361
359
|
fail ApiError.from_response(resp)
|
362
360
|
end
|
@@ -373,12 +371,7 @@ module Gcloud
|
|
373
371
|
# +dest_path+::
|
374
372
|
# If a bucket was provided in the first parameter, this contains the
|
375
373
|
# path to copy the file to in the given bucket. (+String+)
|
376
|
-
# +
|
377
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
378
|
-
# <code>options[:generation]</code>::
|
379
|
-
# Select a specific revision of the file to copy. The default is the
|
380
|
-
# latest version. (+Integer+)
|
381
|
-
# <code>options[:acl]</code>::
|
374
|
+
# +acl+::
|
382
375
|
# A predefined set of access controls to apply to new file.
|
383
376
|
# (+String+)
|
384
377
|
#
|
@@ -395,6 +388,9 @@ module Gcloud
|
|
395
388
|
# and project team members get access according to their roles.
|
396
389
|
# * +public+, +public_read+, +publicRead+ - File owner gets OWNER
|
397
390
|
# access, and allUsers get READER access.
|
391
|
+
# +generation+::
|
392
|
+
# Select a specific revision of the file to copy. The default is the
|
393
|
+
# latest version. (+Integer+)
|
398
394
|
#
|
399
395
|
# === Returns
|
400
396
|
#
|
@@ -432,8 +428,9 @@ module Gcloud
|
|
432
428
|
# file.copy "copy/of/previous/generation/file.ext",
|
433
429
|
# generation: 123456
|
434
430
|
#
|
435
|
-
def copy dest_bucket_or_path, dest_path = nil,
|
431
|
+
def copy dest_bucket_or_path, dest_path = nil, acl: nil, generation: nil
|
436
432
|
ensure_connection!
|
433
|
+
options = { acl: acl, generation: generation }
|
437
434
|
dest_bucket, dest_path, options = fix_copy_args dest_bucket_or_path,
|
438
435
|
dest_path, options
|
439
436
|
|
@@ -485,9 +482,7 @@ module Gcloud
|
|
485
482
|
#
|
486
483
|
# === Parameters
|
487
484
|
#
|
488
|
-
# +
|
489
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
490
|
-
# <code>options[:protocol]</code>::
|
485
|
+
# +protocol+::
|
491
486
|
# The protocol to use for the URL. Default is +HTTPS+. (+String+)
|
492
487
|
#
|
493
488
|
# === Examples
|
@@ -513,8 +508,7 @@ module Gcloud
|
|
513
508
|
# file = bucket.file "avatars/heidi/400x400.png"
|
514
509
|
# public_url = file.public_url protocol: "http"
|
515
510
|
#
|
516
|
-
def public_url
|
517
|
-
protocol = options[:protocol] || :https
|
511
|
+
def public_url protocol: :https
|
518
512
|
"#{protocol}://storage.googleapis.com/#{bucket}/#{name}"
|
519
513
|
end
|
520
514
|
alias_method :url, :public_url
|
@@ -537,25 +531,27 @@ module Gcloud
|
|
537
531
|
#
|
538
532
|
# === Parameters
|
539
533
|
#
|
540
|
-
# +
|
541
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
542
|
-
# <code>options[:method]</code>::
|
534
|
+
# +method+::
|
543
535
|
# The HTTP verb to be used with the signed URL. Signed URLs can be used
|
544
536
|
# with +GET+, +HEAD+, +PUT+, and +DELETE+ requests. Default is +GET+.
|
545
537
|
# (+String+)
|
546
|
-
#
|
538
|
+
# +expires+::
|
547
539
|
# The number of seconds until the URL expires. Default is 300/5 minutes.
|
548
540
|
# (+Integer+)
|
549
|
-
#
|
541
|
+
# +content_type+::
|
550
542
|
# When provided, the client (browser) must send this value in the
|
551
543
|
# HTTP header. e.g. +text/plain+ (+String+)
|
552
|
-
#
|
544
|
+
# +content_md5+::
|
553
545
|
# The MD5 digest value in base64. If you provide this in the string, the
|
554
546
|
# client (usually a browser) must provide this HTTP header with this
|
555
547
|
# same value in its request. (+String+)
|
556
|
-
#
|
548
|
+
# +issuer+::
|
557
549
|
# Service Account's Client Email. (+String+)
|
558
|
-
#
|
550
|
+
# +client_email+::
|
551
|
+
# Service Account's Client Email. (+String+)
|
552
|
+
# +signing_key+::
|
553
|
+
# Service Account's Private Key. (+OpenSSL::PKey::RSA+ or +String+)
|
554
|
+
# +private_key+::
|
559
555
|
# Service Account's Private Key. (+OpenSSL::PKey::RSA+ or +String+)
|
560
556
|
#
|
561
557
|
# === Examples
|
@@ -598,8 +594,14 @@ module Gcloud
|
|
598
594
|
# shared_url = file.signed_url issuer: "service-account@gcloud.com",
|
599
595
|
# signing_key: key
|
600
596
|
#
|
601
|
-
def signed_url
|
597
|
+
def signed_url method: nil, expires: nil, content_type: nil,
|
598
|
+
content_md5: nil, issuer: nil, client_email: nil,
|
599
|
+
signing_key: nil, private_key: nil
|
602
600
|
ensure_connection!
|
601
|
+
options = { method: method, expires: expires,
|
602
|
+
content_type: content_type, content_md5: content_md5,
|
603
|
+
issuer: issuer, client_email: client_email,
|
604
|
+
signing_key: signing_key, private_key: private_key }
|
603
605
|
signer = File::Signer.new self
|
604
606
|
signer.signed_url options
|
605
607
|
end
|
@@ -710,16 +712,19 @@ module Gcloud
|
|
710
712
|
|
711
713
|
def fix_copy_args dest_bucket, dest_path, options = {}
|
712
714
|
if dest_path.respond_to?(:to_hash) && options.empty?
|
713
|
-
options
|
715
|
+
options = dest_path
|
716
|
+
dest_path = nil
|
717
|
+
end
|
718
|
+
if dest_path.nil?
|
719
|
+
dest_path = dest_bucket
|
720
|
+
dest_bucket = bucket
|
714
721
|
end
|
715
|
-
dest_path, dest_bucket = dest_bucket, bucket if dest_path.nil?
|
716
722
|
dest_bucket = dest_bucket.name if dest_bucket.respond_to? :name
|
717
723
|
options[:acl] = File::Acl.predefined_rule_for options[:acl]
|
718
724
|
[dest_bucket, dest_path, options]
|
719
725
|
end
|
720
726
|
|
721
|
-
def verify_file! file,
|
722
|
-
verify = options[:verify] || :md5
|
727
|
+
def verify_file! file, verify = :md5
|
723
728
|
verify_md5 = verify == :md5 || verify == :all
|
724
729
|
verify_crc32c = verify == :crc32c || verify == :all
|
725
730
|
Verifier.verify_md5! self, file if verify_md5
|