shrine-google_cloud_storage 2.0.1 → 3.2.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
  SHA256:
3
- metadata.gz: fa8300b784f31a4d398fc656917be9717fb7c05668de36ab15584bad9f85ff25
4
- data.tar.gz: 967a2776f9f7246be332f21835478863b254ae9d55247ab14dafb61f715a378b
3
+ metadata.gz: cb917fe9e6635501eee44ec51a1d22260c4644db9e45693f2eb67fec80e5783c
4
+ data.tar.gz: bc5e261763d6e6f8bf2260e8d29f131709fa1fe6c88315f3eced62993270b807
5
5
  SHA512:
6
- metadata.gz: f53205e5d15a03e3508ff5bf235017050b0281af87095f4643e7ab072cc909195391cd97144d577814274e78d4c547ff6d9e6f9afe8818d55087f71736105dd5
7
- data.tar.gz: 81df0875f5f7ce14df49ebfb717aceecaa09c79134fe50c37b6b5fd7b1810c91c03a53221bb0484336bed9b4027d1bc9071c50ed104b007cf6dadceceffffa78
6
+ metadata.gz: fce36757f6eae8539ead0310cef964369d533d3b17a1ba26f04fb05af063a23aa65a1abb7db8074a6d16a1a7cda46579c72aadb53283da3e1e83087b294378e9
7
+ data.tar.gz: 80d104beac4587fcc85d2ece8e26b8c1332e57e4a78f3de5e4d4adf8cd3a0784cd35892c20da878495fcc8544f034dcedcc09a75573db96e39d7968bd81b73f2
data/README.md CHANGED
@@ -12,8 +12,7 @@ gem "shrine-google_cloud_storage"
12
12
 
13
13
  ## Authentication
14
14
 
15
- The GCS plugin uses Google's [Project and Credential Lookup]. Please check
16
- documentation for the various ways to provide credentials.
15
+ The GCS plugin uses the `google-cloud-storage` gem. Please refer to [its documentation for setting up authentication](https://googleapis.dev/ruby/google-cloud-storage/latest/file.AUTHENTICATION.html).
17
16
 
18
17
  ## Usage
19
18
 
@@ -66,7 +65,7 @@ cp .env.sample .env
66
65
 
67
66
  #### Option 2 - manual setup
68
67
 
69
- Create your own bucket and provide variables that allow for [project and credential lookup](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-storage/v1.6.0/guides/authentication#projectandcredentiallookup).
68
+ Create your own bucket and provide variables that allow for [project and credential lookup](https://googleapis.dev/ruby/google-cloud-storage/latest/file.AUTHENTICATION.html#project-and-credential-lookup).
70
69
  For example:
71
70
 
72
71
  ```sh
@@ -97,4 +96,3 @@ GCS_DEBUG=true
97
96
 
98
97
  [Google Cloud Storage]: https://cloud.google.com/storage/
99
98
  [Shrine]: https://github.com/shrinerb/shrine
100
- [Project and Credential Lookup]: http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-storage/master/guides/authentication#projectandcredentiallookup
@@ -10,7 +10,7 @@ class Shrine
10
10
  # Initialize a Shrine::Storage for GCS allowing for auto-discovery of the Google::Cloud::Storage client.
11
11
  # @param [String] project Provide if not using auto discovery
12
12
  # @see http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-storage/v1.6.0/guides/authentication#environmentvariables for information on discovery
13
- def initialize(project: nil, bucket:, prefix: nil, host: nil, default_acl: nil, object_options: {})
13
+ def initialize(project: nil, bucket:, prefix: nil, host: nil, default_acl: nil, object_options: {}, credentials: nil)
14
14
  @project = project
15
15
  @bucket = bucket
16
16
  @prefix = prefix
@@ -18,6 +18,7 @@ class Shrine
18
18
  @default_acl = default_acl
19
19
  @object_options = object_options
20
20
  @storage = nil
21
+ @credentials = credentials
21
22
  end
22
23
 
23
24
  # If the file is an UploadFile from GCS, issues a copy command, otherwise it uploads a file.
@@ -29,7 +30,7 @@ class Shrine
29
30
  file = existing_file.copy(
30
31
  @bucket, # dest_bucket_or_path - the bucket to copy the file to
31
32
  object_name(id), # dest_path - the path to copy the file to in the given bucket
32
- acl: @default_acl
33
+ acl: options.fetch(:acl) { @default_acl }
33
34
  ) do |f|
34
35
  # Workaround a bug in File#copy where the content-type is not copied if you provide a block
35
36
  # See https://github.com/renchap/shrine-google_cloud_storage/issues/36
@@ -44,55 +45,53 @@ class Shrine
44
45
  file
45
46
  else
46
47
  with_file(io) do |file|
47
- get_bucket.create_file(
48
- file,
49
- object_name(id), # path
50
- @object_options.merge(
51
- content_type: shrine_metadata["mime_type"],
52
- acl: @default_acl
53
- ).merge(options)
54
- )
48
+ file_options = @object_options.merge(
49
+ content_type: shrine_metadata["mime_type"],
50
+ acl: options.fetch(:acl) { @default_acl }
51
+ ).merge(options)
52
+
53
+ get_bucket.create_file(
54
+ file,
55
+ object_name(id), # path
56
+ **file_options
57
+ )
55
58
  end
56
59
  end
57
60
  end
58
61
 
59
62
  # URL to the remote file, accepts options for customizing the URL
60
63
  def url(id, **options)
61
- if options.key? :expires
62
- signed_url = storage.signed_url(@bucket, object_name(id), options)
64
+ if @default_acl == 'publicRead'
65
+ host = @host || "storage.googleapis.com/#{@bucket}"
66
+ "https://#{host}/#{URI.encode_www_form_component(object_name(id))}"
67
+ else
68
+ signed_url = storage.signed_url(@bucket, object_name(id), **options)
63
69
  signed_url.gsub!(/storage.googleapis.com\/#{@bucket}/, @host) if @host
64
70
  signed_url
65
- else
66
- host = @host || "storage.googleapis.com/#{@bucket}"
67
- "https://#{host}/#{object_name(id)}"
68
71
  end
69
72
  end
70
73
 
71
- # Downloads the file from GCS, and returns a `Tempfile`.
72
- def download(id)
73
- tempfile = Tempfile.new(["googlestorage", File.extname(id)], binmode: true)
74
- get_file(id).download tempfile.path
75
- tempfile.tap(&:open)
76
- end
77
-
78
74
  # Opens the remote file and returns it as `Down::ChunkedIO` object.
79
75
  # @return [Down::ChunkedIO] object
80
76
  # @see https://github.com/janko-m/down#downchunkedio
81
- def open(id)
77
+ def open(id, rewindable: true, **options)
82
78
  file = get_file(id)
83
79
 
80
+ raise Shrine::FileNotFound, "file #{id.inspect} not found on storage" unless file
81
+
84
82
  # create enumerator which lazily yields chunks of downloaded content
85
83
  chunks = Enumerator.new do |yielder|
86
84
  # trick to get google client to stream the download
87
85
  proc_io = ProcIO.new { |data| yielder << data }
88
- file.download(proc_io, verify: :none)
86
+ file.download(proc_io, verify: :none, **options)
89
87
  end
90
88
 
91
89
  # wrap chunks in an IO-like object which downloads when needed
92
90
  Down::ChunkedIO.new(
93
- chunks: chunks,
94
- size: file.size,
95
- data: { file: file }
91
+ chunks: chunks,
92
+ size: file.size,
93
+ rewindable: rewindable,
94
+ data: { file: file },
96
95
  )
97
96
  end
98
97
 
@@ -154,11 +153,13 @@ class Shrine
154
153
 
155
154
  # @see http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-storage/v1.6.0/guides/authentication
156
155
  def storage
157
- @storage ||= if @project.nil?
158
- Google::Cloud::Storage.new
159
- else
160
- Google::Cloud::Storage.new(project: @project)
161
- end
156
+ return @storage if @storage
157
+
158
+ opts = {}
159
+ opts[:project] = @project if @project
160
+ opts[:credentials] = @credentials if @credentials
161
+
162
+ @storage = Google::Cloud::Storage.new(**opts)
162
163
  end
163
164
 
164
165
  def copyable?(io)
@@ -1,23 +1,30 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "shrine-google_cloud_storage"
3
- gem.version = "2.0.1"
3
+ gem.version = "3.2.0"
4
4
 
5
- gem.required_ruby_version = ">= 2.1"
5
+ gem.required_ruby_version = ">= 2.6"
6
6
 
7
7
  gem.summary = "Provides Google Cloud Storage storage for Shrine."
8
8
  gem.homepage = "https://github.com/renchap/shrine-google_cloud_storage"
9
9
  gem.authors = ["Renaud Chaput"]
10
10
  gem.email = ["renchap@gmail.com"]
11
11
  gem.license = "MIT"
12
+ gem.metadata = {
13
+ "bug_tracker_uri" => "https://github.com/renchap/shrine-google_cloud_storage/issues",
14
+ "changelog_uri" => "https://github.com/renchap/shrine-google_cloud_storage/blob/main/CHANGELOG.md",
15
+ "homepage_uri" => "https://github.com/renchap/shrine-google_cloud_storage/",
16
+ "source_code_uri" => "https://github.com/renchap/shrine-google_cloud_storage/",
17
+ "rubygems_mfa_required" => "true",
18
+ }
12
19
 
13
20
  gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "shrine-google_cloud_storage.gemspec"]
14
21
  gem.require_path = "lib"
15
22
 
16
- gem.add_dependency "shrine", "~> 2.11"
23
+ gem.add_dependency "shrine", "~> 3.0"
17
24
  gem.add_dependency "google-cloud-storage", "~> 1.6"
18
25
 
19
26
  gem.add_development_dependency "rake"
20
27
  gem.add_development_dependency "minitest"
21
28
  gem.add_development_dependency "dotenv"
22
- gem.add_development_dependency "http", "~> 4.0"
29
+ gem.add_development_dependency "http", "~> 5.0"
23
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-google_cloud_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renaud Chaput
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-21 00:00:00.000000000 Z
11
+ date: 2022-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shrine
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.11'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.11'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: google-cloud-storage
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,15 +86,15 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '4.0'
89
+ version: '5.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '4.0'
97
- description:
96
+ version: '5.0'
97
+ description:
98
98
  email:
99
99
  - renchap@gmail.com
100
100
  executables: []
@@ -107,8 +107,13 @@ files:
107
107
  homepage: https://github.com/renchap/shrine-google_cloud_storage
108
108
  licenses:
109
109
  - MIT
110
- metadata: {}
111
- post_install_message:
110
+ metadata:
111
+ bug_tracker_uri: https://github.com/renchap/shrine-google_cloud_storage/issues
112
+ changelog_uri: https://github.com/renchap/shrine-google_cloud_storage/blob/main/CHANGELOG.md
113
+ homepage_uri: https://github.com/renchap/shrine-google_cloud_storage/
114
+ source_code_uri: https://github.com/renchap/shrine-google_cloud_storage/
115
+ rubygems_mfa_required: 'true'
116
+ post_install_message:
112
117
  rdoc_options: []
113
118
  require_paths:
114
119
  - lib
@@ -116,15 +121,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
121
  requirements:
117
122
  - - ">="
118
123
  - !ruby/object:Gem::Version
119
- version: '2.1'
124
+ version: '2.6'
120
125
  required_rubygems_version: !ruby/object:Gem::Requirement
121
126
  requirements:
122
127
  - - ">="
123
128
  - !ruby/object:Gem::Version
124
129
  version: '0'
125
130
  requirements: []
126
- rubygems_version: 3.0.3
127
- signing_key:
131
+ rubygems_version: 3.2.32
132
+ signing_key:
128
133
  specification_version: 4
129
134
  summary: Provides Google Cloud Storage storage for Shrine.
130
135
  test_files: []