google-cloud-storage 0.25.0 → 1.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4450abcfeebceca2abde8444b448c4361cd66bba
4
- data.tar.gz: 9f9d2b7ec0dfcece945d361f3cc9828b8560d189
3
+ metadata.gz: e2f69d45d27d36cc09db5b968a09cbbecf4d8354
4
+ data.tar.gz: 62b776735c66856f21cfc352541c87c3452f1dc5
5
5
  SHA512:
6
- metadata.gz: 21241923c3f1b341eb21f495ae3e747ee2508df599c7ac1cf27ecccab85960eda2e7cdac878580d6def3343d551ff9de48cba5b2bda3fb73374be9eb77ada937
7
- data.tar.gz: a685308ed10e4cece3b05d15c48c9a4f1c04bdba60587332db912646b9fd998e1e4c479f158472ac07a0b4079dc8bbe6c843880fef959f3000d17ee9d078fc85
6
+ metadata.gz: 93933194f259974df44e8961ed44f72d03e666dd15ad65aa082c05546f50438417811619f74e17ba8dc0c2b30a48ec7fa6ec706cd9e93cae454a03aa19965b26
7
+ data.tar.gz: 825b6a69664ce2c0fab0910234b7b512f430369102db779b627b4083a8b14b9e2e1c50636a0bb74437e07f929f14bebe22539f34a84655325e239aa4bf83661c
@@ -171,7 +171,7 @@ module Google
171
171
  # directive for the file data.
172
172
  def cache_control= cache_control
173
173
  @gapi.cache_control = cache_control
174
- patch_gapi! :cache_control
174
+ update_gapi! :cache_control
175
175
  end
176
176
 
177
177
  ##
@@ -186,7 +186,7 @@ module Google
186
186
  # of the file data.
187
187
  def content_disposition= content_disposition
188
188
  @gapi.content_disposition = content_disposition
189
- patch_gapi! :content_disposition
189
+ update_gapi! :content_disposition
190
190
  end
191
191
 
192
192
  ##
@@ -203,7 +203,7 @@ module Google
203
203
  # data.
204
204
  def content_encoding= content_encoding
205
205
  @gapi.content_encoding = content_encoding
206
- patch_gapi! :content_encoding
206
+ update_gapi! :content_encoding
207
207
  end
208
208
 
209
209
  ##
@@ -218,7 +218,7 @@ module Google
218
218
  # the file data.
219
219
  def content_language= content_language
220
220
  @gapi.content_language = content_language
221
- patch_gapi! :content_language
221
+ update_gapi! :content_language
222
222
  end
223
223
 
224
224
  ##
@@ -234,7 +234,7 @@ module Google
234
234
  # the file data.
235
235
  def content_type= content_type
236
236
  @gapi.content_type = content_type
237
- patch_gapi! :content_type
237
+ update_gapi! :content_type
238
238
  end
239
239
 
240
240
  ##
@@ -253,7 +253,7 @@ module Google
253
253
  # "x-goog-meta-" response headers.
254
254
  def metadata= metadata
255
255
  @gapi.metadata = metadata
256
- patch_gapi! :metadata
256
+ update_gapi! :metadata
257
257
  end
258
258
 
259
259
  ##
@@ -292,9 +292,8 @@ module Google
292
292
  # {Bucket#storage_class}.
293
293
  # @param [Symbol, String] storage_class Storage class of the file.
294
294
  def storage_class= storage_class
295
- resp = service.update_file_storage_class \
296
- bucket, name, storage_class_for(storage_class)
297
- @gapi = resp.resource
295
+ @gapi.storage_class = storage_class_for(storage_class)
296
+ update_gapi! :storage_class
298
297
  end
299
298
 
300
299
  ##
@@ -329,7 +328,7 @@ module Google
329
328
  updater = Updater.new gapi
330
329
  yield updater
331
330
  updater.check_for_changed_metadata!
332
- patch_gapi! updater.updates unless updater.updates.empty?
331
+ update_gapi! updater.updates unless updater.updates.empty?
333
332
  end
334
333
 
335
334
  ##
@@ -469,6 +468,7 @@ module Google
469
468
  # @param [String] encryption_key Optional. The customer-supplied,
470
469
  # AES-256 encryption key used to encrypt the file, if one was provided
471
470
  # to {Bucket#create_file}.
471
+ # @yield [file] a block yielding a delegate object for updating
472
472
  #
473
473
  # @return [Google::Cloud::Storage::File]
474
474
  #
@@ -504,17 +504,43 @@ module Google
504
504
  # file.copy "copy/of/previous/generation/file.ext",
505
505
  # generation: 123456
506
506
  #
507
+ # @example The file can be modified during copying:
508
+ # require "google/cloud/storage"
509
+ #
510
+ # storage = Google::Cloud::Storage.new
511
+ #
512
+ # bucket = storage.bucket "my-bucket"
513
+ #
514
+ # file = bucket.file "path/to/my-file.ext"
515
+ # file.copy "new-destination-bucket",
516
+ # "path/to/destination/file.ext" do |f|
517
+ # f.metadata["copied_from"] = "#{file.bucket}/#{file.name}"
518
+ # end
519
+ #
507
520
  def copy dest_bucket_or_path, dest_path = nil, acl: nil,
508
521
  generation: nil, encryption_key: nil
509
522
  ensure_service!
510
- options = { acl: acl, generation: generation,
511
- key: encryption_key }
523
+ options = { acl: acl, generation: generation, key: encryption_key }
512
524
  dest_bucket, dest_path, options = fix_copy_args dest_bucket_or_path,
513
525
  dest_path, options
514
526
 
515
- gapi = service.copy_file bucket, name,
516
- dest_bucket, dest_path, options
517
- File.from_gapi gapi, service
527
+ copy_gapi = nil
528
+ if block_given?
529
+ updater = Updater.new gapi
530
+ yield updater
531
+ updater.check_for_changed_metadata!
532
+ copy_gapi = gapi_from_attrs(updater.updates) if updater.updates.any?
533
+ end
534
+
535
+ resp = service.copy_file bucket, name, dest_bucket, dest_path,
536
+ copy_gapi, options
537
+ until resp.done
538
+ sleep 1
539
+ resp = service.copy_file bucket, name, dest_bucket, dest_path,
540
+ copy_gapi,
541
+ options.merge(token: resp.rewrite_token)
542
+ end
543
+ File.from_gapi resp.resource, service
518
544
  end
519
545
 
520
546
  ##
@@ -566,10 +592,11 @@ module Google
566
592
  ensure_service!
567
593
  options = { source_key: encryption_key,
568
594
  destination_key: new_encryption_key }
569
- gapi = service.rewrite_file bucket, name, bucket, name, options
595
+ gapi = service.rewrite_file bucket, name, bucket, name, nil, options
570
596
  until gapi.done
597
+ sleep 1
571
598
  options[:token] = gapi.rewrite_token
572
- gapi = service.rewrite_file bucket, name, bucket, name, options
599
+ gapi = service.rewrite_file bucket, name, bucket, name, nil, options
573
600
  end
574
601
  File.from_gapi gapi.resource, service
575
602
  end
@@ -805,15 +832,39 @@ module Google
805
832
  fail "Must have active connection" unless service
806
833
  end
807
834
 
808
- def patch_gapi! *attributes
835
+ def update_gapi! *attributes
809
836
  attributes.flatten!
810
837
  return if attributes.empty?
838
+ update_gapi = gapi_from_attrs attributes
839
+ return if update_gapi.nil?
840
+
811
841
  ensure_service!
812
- patch_args = Hash[attributes.map do |attr|
842
+
843
+ if attributes.include? :storage_class
844
+ @gapi = rewrite_gapi bucket, name, update_gapi
845
+ else
846
+ @gapi = service.patch_file bucket, name, update_gapi
847
+ end
848
+ end
849
+
850
+ def gapi_from_attrs *attributes
851
+ attributes.flatten!
852
+ return nil if attributes.empty?
853
+ attr_params = Hash[attributes.map do |attr|
813
854
  [attr, @gapi.send(attr)]
814
855
  end]
815
- patch_gapi = Google::Apis::StorageV1::Object.new patch_args
816
- @gapi = service.patch_file bucket, name, patch_gapi
856
+ Google::Apis::StorageV1::Object.new attr_params
857
+ end
858
+
859
+ def rewrite_gapi bucket, name, update_gapi
860
+ resp = service.rewrite_file bucket, name, bucket, name, update_gapi
861
+ until resp.done
862
+ sleep 1
863
+ rewrite_options = { token: resp.rewrite_token }
864
+ resp = service.rewrite_file bucket, name, bucket, name,
865
+ update_gapi, rewrite_options
866
+ end
867
+ resp.resource
817
868
  end
818
869
 
819
870
  def fix_copy_args dest_bucket, dest_path, options = {}
@@ -853,10 +904,6 @@ module Google
853
904
  ##
854
905
  # Yielded to a block to accumulate changes for a patch request.
855
906
  class Updater < File
856
- # @private Do not allow storage_class to be set in an update call.
857
- # It cannot be set with PATCH.
858
- undef :storage_class=
859
-
860
907
  # @private
861
908
  attr_reader :updates
862
909
 
@@ -865,6 +912,7 @@ module Google
865
912
  def initialize gapi
866
913
  @updates = []
867
914
  @gapi = gapi
915
+ @metadata ||= @gapi.metadata.to_h.dup
868
916
  end
869
917
 
870
918
  ##
@@ -872,8 +920,7 @@ module Google
872
920
  # values that will returned with requests for the file as
873
921
  # "x-goog-meta-" response headers.
874
922
  def metadata
875
- # do not freeze metadata
876
- @metadata ||= @gapi.metadata.to_h.dup
923
+ @metadata
877
924
  end
878
925
 
879
926
  ##
@@ -883,22 +930,22 @@ module Google
883
930
  def metadata= metadata
884
931
  @metadata = metadata
885
932
  @gapi.metadata = @metadata
886
- patch_gapi! :metadata
933
+ update_gapi! :metadata
887
934
  end
888
935
 
889
936
  ##
890
937
  # @private Make sure any metadata changes are saved
891
938
  def check_for_changed_metadata!
892
- return if @metadata == @gapi.metadata
939
+ return if @metadata == @gapi.metadata.to_h
893
940
  @gapi.metadata = @metadata
894
- patch_gapi! :metadata
941
+ update_gapi! :metadata
895
942
  end
896
943
 
897
944
  protected
898
945
 
899
946
  ##
900
947
  # Queue up all the updates instead of making them.
901
- def patch_gapi! attribute
948
+ def update_gapi! attribute
902
949
  @updates << attribute
903
950
  @updates.uniq!
904
951
  end
@@ -46,9 +46,10 @@ module Google
46
46
  @service.client_options.application_name = "gcloud-ruby"
47
47
  @service.client_options.application_version = \
48
48
  Google::Cloud::Storage::VERSION
49
+ @service.client_options.open_timeout_sec = timeout
50
+ @service.client_options.read_timeout_sec = timeout
51
+ @service.client_options.send_timeout_sec = timeout
49
52
  @service.request_options.retries = retries || 3
50
- @service.request_options.timeout_sec = timeout
51
- @service.request_options.open_timeout_sec = timeout
52
53
  @service.request_options.header ||= {}
53
54
  @service.request_options.header["x-goog-api-client"] = \
54
55
  "gl-ruby/#{RUBY_VERSION} gccl/#{Google::Cloud::Storage::VERSION}"
@@ -207,14 +208,18 @@ module Google
207
208
  # destination bucket/object.
208
209
  def copy_file source_bucket_name, source_file_path,
209
210
  destination_bucket_name, destination_file_path,
210
- options = {}
211
+ file_gapi = nil, options = {}
212
+ key_options = rewrite_key_options options[:key],
213
+ options[:key]
211
214
  execute do
212
- service.copy_object \
215
+ service.rewrite_object \
213
216
  source_bucket_name, source_file_path,
214
217
  destination_bucket_name, destination_file_path,
218
+ file_gapi,
215
219
  destination_predefined_acl: options[:acl],
216
220
  source_generation: options[:generation],
217
- options: key_options(options[:key])
221
+ rewrite_token: options[:token],
222
+ options: key_options
218
223
  end
219
224
  end
220
225
 
@@ -222,28 +227,18 @@ module Google
222
227
  # destination bucket/object.
223
228
  def rewrite_file source_bucket_name, source_file_path,
224
229
  destination_bucket_name, destination_file_path,
225
- options = {}
226
- options = rewrite_key_options options[:source_key],
227
- options[:destination_key]
230
+ file_gapi = nil, options = {}
231
+ key_options = rewrite_key_options options[:source_key],
232
+ options[:destination_key]
228
233
  execute do
229
234
  service.rewrite_object \
230
235
  source_bucket_name, source_file_path,
231
236
  destination_bucket_name, destination_file_path,
237
+ file_gapi,
232
238
  destination_predefined_acl: options[:acl],
233
239
  source_generation: options[:generation],
234
240
  rewrite_token: options[:token],
235
- options: options
236
- end
237
- end
238
-
239
- ## Rewrite a file from source bucket/object to a
240
- # destination bucket/object.
241
- def update_file_storage_class bucket_name, file_path, storage_class
242
- execute do
243
- service.rewrite_object \
244
- bucket_name, file_path,
245
- bucket_name, file_path,
246
- Google::Apis::StorageV1::Object.new(storage_class: storage_class)
241
+ options: key_options
247
242
  end
248
243
  end
249
244
 
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Storage
19
- VERSION = "0.25.0"
19
+ VERSION = "1.0.0"
20
20
  end
21
21
  end
22
22
  end
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: 0.25.0
4
+ version: 1.0.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: 2017-04-01 00:00:00.000000000 Z
12
+ date: 2017-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 0.10.0
34
+ version: 0.11.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: 0.10.0
41
+ version: 0.11.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: digest-crc
44
44
  requirement: !ruby/object:Gem::Requirement