google-cloud-storage 0.23.0 → 0.23.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ea4be7f9752b1d98381c5f9eb8109a5a3bee1f5
4
- data.tar.gz: b7f3164a319ac37f66badeca1c789b59042ad741
3
+ metadata.gz: d25ea51c3061bfb14179befa5250f8665e7f9691
4
+ data.tar.gz: b431f5182d343bb654b7d57cc75db83d6d5470f7
5
5
  SHA512:
6
- metadata.gz: 26edfa57afbf8251e3463677b3b9c524a789d61a426b5e43459a221717cb1c7a838052e5e6f454944c247ef78c0a24f79b1339805c1ae7bee0ad6be35b532536
7
- data.tar.gz: bcedbb48b9d1cef2fccf80c45f28a1f4b384e7805ba50027808d21931c27204a5647d785bdb1d595dda58c073caf77f3bae71bb36402c7221f14d3b4f0189e74
6
+ metadata.gz: f257e340fb77698aaa60a23ac31d86d42352ad6c70450e59a0a30166f96b3c9b111244033131041c1c567d5a34a0c981d1a74b662af844e1c6276a69b2ad35be
7
+ data.tar.gz: 419052576260453c9595b6c1a6236e8f325d0104fdd0ffc81f71bde1d17e00d28871eff0f8951ef9e56bba825289c7e00cbabff7bec861459fc32a6c23988a56
@@ -613,6 +613,9 @@ module Google
613
613
  # @param [String] content_md5 The MD5 digest value in base64. If you
614
614
  # provide this in the string, the client (usually a browser) must
615
615
  # provide this HTTP header with this same value in its request.
616
+ # @param [Hash] headers Google extension headers (custom HTTP headers
617
+ # that begin with `x-goog-`) that must be included in requests that
618
+ # use the signed URL.
616
619
  # @param [String] issuer Service Account's Client Email.
617
620
  # @param [String] client_email Service Account's Client Email.
618
621
  # @param [OpenSSL::PKey::RSA, String] signing_key Service Account's
@@ -649,11 +652,23 @@ module Google
649
652
  # issuer: "service-account@gcloud.com",
650
653
  # signing_key: key
651
654
  #
655
+ # @example Using the headers option:
656
+ # require "google/cloud/storage"
657
+ #
658
+ # storage = Google::Cloud.storage
659
+ #
660
+ # bucket = storage.bucket "my-todo-app"
661
+ # shared_url = bucket.signed_url "avatars/heidi/400x400.png",
662
+ # headers: {
663
+ # "x-goog-acl" => "private",
664
+ # "x-goog-meta-foo" => "bar,baz"
665
+ # }
666
+ #
652
667
  def signed_url path, method: nil, expires: nil, content_type: nil,
653
- content_md5: nil, issuer: nil, client_email: nil,
654
- signing_key: nil, private_key: nil
668
+ content_md5: nil, headers: nil, issuer: nil,
669
+ client_email: nil, signing_key: nil, private_key: nil
655
670
  ensure_service!
656
- options = { method: method, expires: expires,
671
+ options = { method: method, expires: expires, headers: headers,
657
672
  content_type: content_type, content_md5: content_md5,
658
673
  issuer: issuer, client_email: client_email,
659
674
  signing_key: signing_key, private_key: private_key }
@@ -547,6 +547,9 @@ module Google
547
547
  # @param [String] content_md5 The MD5 digest value in base64. If you
548
548
  # provide this in the string, the client (usually a browser) must
549
549
  # provide this HTTP header with this same value in its request.
550
+ # @param [Hash] headers Google extension headers (custom HTTP headers
551
+ # that begin with `x-goog-`) that must be included in requests that
552
+ # use the signed URL.
550
553
  # @param [String] issuer Service Account's Client Email.
551
554
  # @param [String] client_email Service Account's Client Email.
552
555
  # @param [OpenSSL::PKey::RSA, String] signing_key Service Account's
@@ -584,11 +587,24 @@ module Google
584
587
  # shared_url = file.signed_url issuer: "service-account@gcloud.com",
585
588
  # signing_key: key
586
589
  #
590
+ # @example Using the `headers` option:
591
+ # require "google/cloud/storage"
592
+ #
593
+ # storage = Google::Cloud::Storage.new
594
+ #
595
+ # bucket = storage.bucket "my-todo-app"
596
+ # file = bucket.file "avatars/heidi/400x400.png"
597
+ # shared_url = file.signed_url method: "GET",
598
+ # headers: {
599
+ # "x-goog-acl" => "public-read",
600
+ # "x-goog-meta-foo" => bar,baz"
601
+ # }
602
+ #
587
603
  def signed_url method: nil, expires: nil, content_type: nil,
588
- content_md5: nil, issuer: nil, client_email: nil,
589
- signing_key: nil, private_key: nil
604
+ content_md5: nil, headers: nil, issuer: nil,
605
+ client_email: nil, signing_key: nil, private_key: nil
590
606
  ensure_service!
591
- options = { method: method, expires: expires,
607
+ options = { method: method, expires: expires, headers: headers,
592
608
  content_type: content_type, content_md5: content_md5,
593
609
  issuer: issuer, client_email: client_email,
594
610
  signing_key: signing_key, private_key: private_key }
@@ -746,7 +762,7 @@ module Google
746
762
  def signature_str options
747
763
  [options[:method], options[:content_md5],
748
764
  options[:content_type], options[:expires],
749
- ext_path].join "\n"
765
+ format_extension_headers(options[:headers]) + ext_path].join "\n"
750
766
  end
751
767
 
752
768
  def determine_signing_key options = {}
@@ -781,8 +797,18 @@ module Google
781
797
  def generate_signed_url issuer, signed_string, expires
782
798
  signature = Base64.strict_encode64(signed_string).delete("\n")
783
799
  "#{ext_url}?GoogleAccessId=#{CGI.escape issuer}" \
784
- "&Expires=#{expires}" \
785
- "&Signature=#{CGI.escape signature}"
800
+ "&Expires=#{expires}" \
801
+ "&Signature=#{CGI.escape signature}"
802
+ end
803
+
804
+ def format_extension_headers headers
805
+ return "" if headers.nil?
806
+ fail "Headers must be given in a Hash" unless headers.is_a? Hash
807
+ flatten = headers.map do |key, value|
808
+ "#{key.to_s.downcase}:#{value.gsub(/\s+/, ' ')}\n"
809
+ end
810
+ flatten.reject! { |h| h.start_with? "x-goog-encryption-key" }
811
+ flatten.sort.join
786
812
  end
787
813
  end
788
814
 
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Storage
19
- VERSION = "0.23.0"
19
+ VERSION = "0.23.1"
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.23.0
4
+ version: 0.23.1
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: 2016-12-09 00:00:00.000000000 Z
12
+ date: 2016-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core