blobby-gcs 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f09547aa636cb68c076fa0ad2f2253b1f357a1af97cee53993f5ad5f9ed8df37
4
+ data.tar.gz: b8941452f69592af379bcee4c87fc38f95f1d94600a5022044417c3a3fa8b322
5
+ SHA512:
6
+ metadata.gz: 11c590018bfa1ed10f1a6b452e2f88fc6915171e872210fd1e9dcfcb46aaa98c5aad7fd55edaea07e174d91805fc89e523a3f342c3665774468ee47c9725d4b5
7
+ data.tar.gz: 5ff02e4d413bffd69b0a06abbc5a81f4c9287407841869b89b18a0d2eacf878c372642c50bc608ba990b09dad78f75e8be596d3ade2c1e6bc6d5d692b32bee47
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in blobby-gcs.gemspec
8
+ gemspec
@@ -0,0 +1,121 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ blobby-gcs (0.1)
5
+ blobby (~> 1.1.0)
6
+ google-cloud-storage (~> 1.25)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ast (2.4.0)
14
+ blobby (1.1.1)
15
+ bundler-audit (0.6.1)
16
+ bundler (>= 1.2.0, < 3)
17
+ thor (~> 0.18)
18
+ byebug (11.0.1)
19
+ coderay (1.1.2)
20
+ declarative (0.0.10)
21
+ declarative-option (0.1.0)
22
+ diff-lcs (1.3)
23
+ digest-crc (0.4.1)
24
+ faraday (0.17.3)
25
+ multipart-post (>= 1.2, < 3)
26
+ google-api-client (0.36.3)
27
+ addressable (~> 2.5, >= 2.5.1)
28
+ googleauth (~> 0.9)
29
+ httpclient (>= 2.8.1, < 3.0)
30
+ mini_mime (~> 1.0)
31
+ representable (~> 3.0)
32
+ retriable (>= 2.0, < 4.0)
33
+ signet (~> 0.12)
34
+ google-cloud-core (1.4.1)
35
+ google-cloud-env (~> 1.0)
36
+ google-cloud-env (1.3.0)
37
+ faraday (~> 0.11)
38
+ google-cloud-storage (1.25.0)
39
+ addressable (~> 2.5)
40
+ digest-crc (~> 0.4)
41
+ google-api-client (~> 0.33)
42
+ google-cloud-core (~> 1.2)
43
+ googleauth (~> 0.9)
44
+ mini_mime (~> 1.0)
45
+ googleauth (0.10.0)
46
+ faraday (~> 0.12)
47
+ jwt (>= 1.4, < 3.0)
48
+ memoist (~> 0.16)
49
+ multi_json (~> 1.11)
50
+ os (>= 0.9, < 2.0)
51
+ signet (~> 0.12)
52
+ httpclient (2.8.3)
53
+ jaro_winkler (1.5.4)
54
+ jwt (2.2.1)
55
+ memoist (0.16.2)
56
+ method_source (0.9.2)
57
+ mini_mime (1.0.2)
58
+ multi_json (1.14.1)
59
+ multipart-post (2.1.1)
60
+ os (1.0.1)
61
+ parallel (1.19.1)
62
+ parser (2.7.0.1)
63
+ ast (~> 2.4.0)
64
+ pry (0.12.2)
65
+ coderay (~> 1.1.0)
66
+ method_source (~> 0.9.0)
67
+ pry-byebug (3.7.0)
68
+ byebug (~> 11.0)
69
+ pry (~> 0.10)
70
+ public_suffix (4.0.2)
71
+ rainbow (3.0.0)
72
+ rake (10.5.0)
73
+ representable (3.0.4)
74
+ declarative (< 0.1.0)
75
+ declarative-option (< 0.2.0)
76
+ uber (< 0.2.0)
77
+ retriable (3.1.2)
78
+ rspec (3.9.0)
79
+ rspec-core (~> 3.9.0)
80
+ rspec-expectations (~> 3.9.0)
81
+ rspec-mocks (~> 3.9.0)
82
+ rspec-core (3.9.1)
83
+ rspec-support (~> 3.9.1)
84
+ rspec-expectations (3.9.0)
85
+ diff-lcs (>= 1.2.0, < 2.0)
86
+ rspec-support (~> 3.9.0)
87
+ rspec-mocks (3.9.1)
88
+ diff-lcs (>= 1.2.0, < 2.0)
89
+ rspec-support (~> 3.9.0)
90
+ rspec-support (3.9.2)
91
+ rubocop (0.78.0)
92
+ jaro_winkler (~> 1.5.1)
93
+ parallel (~> 1.10)
94
+ parser (>= 2.6)
95
+ rainbow (>= 2.2.2, < 4.0)
96
+ ruby-progressbar (~> 1.7)
97
+ unicode-display_width (>= 1.4.0, < 1.7)
98
+ ruby-progressbar (1.10.1)
99
+ signet (0.12.0)
100
+ addressable (~> 2.3)
101
+ faraday (~> 0.9)
102
+ jwt (>= 1.5, < 3.0)
103
+ multi_json (~> 1.10)
104
+ thor (0.20.3)
105
+ uber (0.1.0)
106
+ unicode-display_width (1.6.0)
107
+
108
+ PLATFORMS
109
+ ruby
110
+
111
+ DEPENDENCIES
112
+ blobby-gcs!
113
+ bundler (~> 2.1)
114
+ bundler-audit (~> 0.6.1)
115
+ pry-byebug (~> 3.7)
116
+ rake (~> 10.0)
117
+ rspec (~> 3.0)
118
+ rubocop (~> 0.78.0)
119
+
120
+ BUNDLED WITH
121
+ 2.1.0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Jerome Paul
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ # Blobby::GCSStore [![Build status](https://badge.buildkite.com/3a10d87beff89aab18d733ccd5fb3080e76020079c00ebdaab.svg)](https://buildkite.com/gs/blobby-gcs)
2
+
3
+ This gem provides a Google Cloud Storage (GCS) implementation of the "store" interface defined by the [`blobby`](https://github.com/realestate-com-au/blobby) gem. It's been packaged separately to avoid adding dependencies to the core gem.
4
+
5
+ The simplest use-case is writing to a single bucket:
6
+
7
+ ```ruby
8
+ gcs_store = Blobby.store("gs://<bucket_name>/<directory_path_inside_bucket>")
9
+ gcs_store["key"].write("IO or string file content")
10
+ ```
11
+
12
+ Configuration is provided using the [same environment variables](https://googleapis.dev/ruby/google-cloud-storage/latest/file.AUTHENTICATION.html) as the `google-cloud-storage` gem (which this one is wrapping).
13
+
14
+ ```ruby
15
+ require 'blobby-gcs'
16
+
17
+ ENV["GOOGLE_CLOUD_PROJECT"] = "my-project-id"
18
+ ENV["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/keyfile.json"
19
+
20
+ gcs_store = Blobby.store("gs://<bucket_name>/<directory_path_inside_bucket>")
21
+ ```
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem 'blobby-gcs'
29
+ ```
30
+
31
+ And then execute:
32
+
33
+ ```bash
34
+ $ bundle
35
+ ```
36
+
37
+ Or install it yourself as:
38
+
39
+ ```bash
40
+ $ gem install blobby-gcs
41
+ ```
42
+
43
+ ## Development
44
+
45
+ You can run the tests within Docker via `auto/test` or directly within your shell using `scripts/test`.
46
+
47
+ There are integration tests within this gem which point to a real **Google Cloud Storage** bucket, so credentials are required. If you do not already have `~/.config/gcloud/application_default_credentials.json` from authenticating with [`gcloud`](https://cloud.google.com/sdk/gcloud/), run:
48
+
49
+ ```bash
50
+ $ gcloud auth application-default login
51
+ ```
52
+
53
+ You will also need to provide the name of a GCS bucket you have `storage.objectAdmin` access to (and unfortunately, also `storage.legacyBucketReader`):
54
+
55
+ ```bash
56
+ export GOOGLE_CLOUD_PROJECT=unused
57
+ export BLOBBY_GCS_TEST_BUCKET=...name of bucket...
58
+ ```
59
+
60
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and publish the `.gem` file to [rubygems.org](https://rubygems.org).
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/greensync/blobby-gcs.
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'blobby-gcs'
8
+ spec.version = 0.1
9
+ spec.authors = ['Jerome Paul']
10
+ spec.email = ['jerome.paul@greensync.com.au']
11
+
12
+ spec.summary = 'Store BLOBs in Google Cloud Storage'
13
+ spec.homepage = 'https://github.com/greensync/blobby-gcs'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files += Dir['lib/**/*']
17
+ spec.files += Dir['LICENSE.txt']
18
+ spec.files += Dir['blobby-gcs.gemspec']
19
+ spec.files += Dir['Gemfile']
20
+ spec.files += Dir['Gemfile.lock']
21
+ spec.files += Dir['README.md']
22
+
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 2.1'
26
+ spec.add_development_dependency 'bundler-audit', '~> 0.6.1'
27
+ spec.add_development_dependency 'pry-byebug', '~> 3.7'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'rubocop', '~> 0.78.0'
31
+
32
+ spec.add_runtime_dependency('blobby', '~> 1.1.0')
33
+ spec.add_runtime_dependency('google-cloud-storage', '~> 1.25')
34
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'blobby'
4
+ require 'blobby/gcs_store'
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'blobby'
4
+ require 'blobby/key_transforming_store'
5
+ require 'google/cloud/storage'
6
+ require 'uri'
7
+
8
+ module Blobby
9
+ # A BLOB store backed by Google Cloud Storage.
10
+ #
11
+ class GCSStore
12
+
13
+ def self.from_uri(uri)
14
+ uri = URI(uri)
15
+ raise ArgumentError, "invalid GCS address: #{uri}" unless uri.scheme == 'gs'
16
+
17
+ bucket_name = uri.host
18
+ prefix = uri.path.sub(%r{\A/}, '').sub(%r{/\Z}, '')
19
+ raise ArgumentError, 'no bucket specified' if bucket_name.nil?
20
+
21
+ store = new(bucket_name)
22
+ store = KeyTransformingStore.new(store) { |key| prefix + '/' + key } unless prefix.empty?
23
+ store
24
+ end
25
+
26
+ def initialize(bucket_name, gcs_options: {})
27
+ @bucket_name = bucket_name
28
+ @gcs_options = gcs_options
29
+ end
30
+
31
+ def available?
32
+ !!bucket&.exists?
33
+ end
34
+
35
+ def [](key)
36
+ KeyConstraint.must_allow!(key)
37
+ StoredObject.new(bucket, key)
38
+ end
39
+
40
+ class StoredObject
41
+
42
+ def initialize(bucket, key)
43
+ @bucket = bucket
44
+ @key = key
45
+ end
46
+
47
+ # https://googleapis.dev/ruby/google-cloud-storage/latest/Google/Cloud/Storage/File.html#exists%3F-instance_method
48
+ # bucket.file(key) returns nil, if the file does not exist!
49
+ def exists?
50
+ !!gcs_file&.exists?
51
+ end
52
+
53
+ # https://googleapis.dev/ruby/google-cloud-storage/latest/Google/Cloud/Storage/File.html#download-instance_method
54
+ def read
55
+ return nil unless exists?
56
+
57
+ io = gcs_file.download
58
+ if block_given?
59
+ while (chunk = io.read(512))
60
+ yield chunk
61
+ end
62
+ nil
63
+ else
64
+ io.read
65
+ end
66
+ end
67
+
68
+ # https://googleapis.dev/ruby/google-cloud-storage/latest/Google/Cloud/Storage/Bucket.html#create_file-instance_method
69
+ def write(content)
70
+ content = StringIO.new(content) unless content.respond_to?(:read)
71
+ bucket.create_file(content, key)
72
+ nil
73
+ end
74
+
75
+ # https://googleapis.dev/ruby/google-cloud-storage/latest/Google/Cloud/Storage/File.html#delete-instance_method
76
+ def delete
77
+ return false unless exists?
78
+
79
+ gcs_file.delete
80
+ end
81
+
82
+ private
83
+
84
+ attr_reader :bucket, :key
85
+
86
+ def gcs_file
87
+ bucket.file(key)
88
+ end
89
+
90
+ end
91
+
92
+ private
93
+
94
+ attr_reader :bucket_name, :gcs_options
95
+
96
+ def bucket
97
+ @bucket ||= gcs_client.bucket(bucket_name, skip_lookup: true)
98
+ end
99
+
100
+ def gcs_client
101
+ @gcs_client ||= Google::Cloud::Storage.new(gcs_options)
102
+ end
103
+
104
+ end
105
+
106
+ register_store_factory 'gs', GCSStore
107
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blobby-gcs
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Jerome Paul
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler-audit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.78.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.78.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: blobby
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.1.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.1.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: google-cloud-storage
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.25'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.25'
125
+ description:
126
+ email:
127
+ - jerome.paul@greensync.com.au
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - Gemfile
133
+ - Gemfile.lock
134
+ - LICENSE.txt
135
+ - README.md
136
+ - blobby-gcs.gemspec
137
+ - lib/blobby-gcs.rb
138
+ - lib/blobby/gcs_store.rb
139
+ homepage: https://github.com/greensync/blobby-gcs
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubygems_version: 3.0.3
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Store BLOBs in Google Cloud Storage
162
+ test_files: []