gcs-signer 0.2.1 → 0.2.2
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 +4 -4
- data/lib/gcs_signer.rb +27 -11
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcc753e1262301f1f25d2bc0637ad2c03fbe0da7
|
4
|
+
data.tar.gz: f8bf159daf4ac001b8999e563cb87f09c6e44b74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dce4c13fe146f462926ab4c8b124f756a5a5b9fa525b7e38ee4c2502990d80bd030e49f42d6b9838199b054cf7deb4acb48cb465bc6342ef045d9995c3a0579
|
7
|
+
data.tar.gz: 8b563b219fdd62a91775b6c4ed2f85b138c433dcffad7f6db3ade618622fe967e06abbf6e1be3646cf1acb9e53e190e166a319dae22242c543dc6505a718958d
|
data/lib/gcs_signer.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "uri"
|
3
4
|
require "openssl"
|
4
5
|
require "base64"
|
@@ -10,7 +11,7 @@ require "json"
|
|
10
11
|
# signer.sign "your-bucket", "object/name"
|
11
12
|
# # => "https://storage.googleapis.com/your-bucket/object/name?..."
|
12
13
|
class GcsSigner
|
13
|
-
VERSION = "0.2.
|
14
|
+
VERSION = "0.2.2"
|
14
15
|
|
15
16
|
# gcs-signer requires credential that can access to GCS.
|
16
17
|
# [path] the path of the service_account json file.
|
@@ -37,7 +38,12 @@ class GcsSigner
|
|
37
38
|
# Variable options are available:
|
38
39
|
# [expires] Time(stamp in UTC) when the signed url expires.
|
39
40
|
# [valid_for] ...or how much seconds is the signed url available.
|
40
|
-
#
|
41
|
+
# [google_access_id] Just in case if you want to change \+GoogleAccessId+
|
42
|
+
# [response_content_disposition] Content-Disposition of the signed URL.
|
43
|
+
# [response_content_type] Content-Type of the signed URL.
|
44
|
+
#
|
45
|
+
# If you set neither \+expires+ nor \+valid_for+,
|
46
|
+
# it will set to 300 seconds by default.
|
41
47
|
#
|
42
48
|
# # default is 5 minutes
|
43
49
|
# signer.sign_url("bucket-name", "path/to/file")
|
@@ -56,15 +62,19 @@ class GcsSigner
|
|
56
62
|
# like \+method+, \+md5+, and \+content_type+. See:
|
57
63
|
# https://cloud.google.com/storage/docs/access-control/signed-urls
|
58
64
|
#
|
59
|
-
# Just in case if you want to change \+GoogleAccessId+ in the signed url,
|
60
|
-
# You can set \+google_access_id+ as an option.
|
61
65
|
def sign_url(bucket, object_name, options = {})
|
62
66
|
options = apply_default_options(options)
|
63
67
|
|
64
|
-
url = URI.join
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
+
url = URI.join(
|
69
|
+
@gcs_host,
|
70
|
+
URI.escape("/#{bucket}/"), URI.escape(object_name)
|
71
|
+
)
|
72
|
+
|
73
|
+
url.query = query_for_signed_url(
|
74
|
+
sign(string_that_will_be_signed(url, options)),
|
75
|
+
options
|
76
|
+
)
|
77
|
+
|
68
78
|
url.to_s
|
69
79
|
end
|
70
80
|
|
@@ -114,9 +124,15 @@ class GcsSigner
|
|
114
124
|
|
115
125
|
# Escapes and generates query string for actual result.
|
116
126
|
def query_for_signed_url(signature, options)
|
117
|
-
|
118
|
-
|
119
|
-
|
127
|
+
query = {
|
128
|
+
"GoogleAccessId" => options[:google_access_id],
|
129
|
+
"Expires" => options[:expires].to_i,
|
130
|
+
"Signature" => Base64.strict_encode64(signature),
|
131
|
+
"response-content-disposition" => options[:response_content_disposition],
|
132
|
+
"response-content-type" => options[:response_content_type]
|
133
|
+
}.reject { |_, v| v.nil? }
|
134
|
+
|
135
|
+
URI.encode_www_form(query)
|
120
136
|
end
|
121
137
|
|
122
138
|
# raised When GcsSigner could not find service_account JSON file.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gcs-signer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sangwon Yi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.
|
48
|
+
version: 0.49.1
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
55
|
+
version: 0.49.1
|
56
56
|
description: |2
|
57
57
|
Simple signed URL generator for Google Cloud Storage.
|
58
58
|
No additional gems and API requests required to generate signed URL.
|
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
87
|
rubyforge_project:
|
88
|
-
rubygems_version: 2.6.
|
88
|
+
rubygems_version: 2.6.13
|
89
89
|
signing_key:
|
90
90
|
specification_version: 4
|
91
91
|
summary: Simple signed URL generator for Google Cloud Storage.
|