tumugi-plugin-google_cloud_storage 0.1.0 → 0.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
  SHA1:
3
- metadata.gz: a54e93d2ae132b0372b36c6f3d1974c1fbb7ef92
4
- data.tar.gz: 6c1c6aa1fe96b655ab3f8f9b49176ef34dc9858f
3
+ metadata.gz: d867db4d8e41e26c1aeccc2ae435882def2eaedf
4
+ data.tar.gz: 1e1a67c26142bf89ffb1c2c2f3b8c571031f835e
5
5
  SHA512:
6
- metadata.gz: 83efe8fafc377ac90a8fc103bcee1195fb80296330a50b8a28d6c029037e19b1b29f0e15337a8443313f6fa643311ccc42a9b9747bf4308bc183bb454bacd4ed
7
- data.tar.gz: f2ce008443eaf65118d94650698ec6ccf4b2ebf07d6079ae11a2ac7d28da8992cb683dae22cb20f6558dcc7603a41e0d2b1843a804f7bb2545e8e164aac13a71
6
+ metadata.gz: 5f167627c6079a672936b132ef4980b2d0d0db217d47c67e956a7a2b0b3f5714b6f8f10978ec848539bfc60205ad6f4d37870a7752573482c2d1d6125af939c1
7
+ data.tar.gz: 8e9f630ce8bfbd0c12ca2061e0593122e251bbed638b04ff2a1e0559f691c7b1dce2ec8021681062a4bc4b953422c1e81a0d29d1ca319c907a09763b3ace2501
@@ -1,13 +1,8 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.1.10
5
- - 2.2.5
4
+ - 2.1
6
5
  - 2.3.1
7
- - ruby-head
8
- - jruby-9.0.5.0
6
+ - jruby-9.1.2.0
9
7
  before_install:
10
8
  - gem install bundler
11
- matrix:
12
- allow_failures:
13
- - rvm: ruby-head
@@ -0,0 +1,37 @@
1
+ # Change Log
2
+
3
+ ## [0.2.0](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/tree/0.2.0) (2016-06-06)
4
+ [Full Changelog](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/compare/v0.1.0...0.2.0)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - Change tumugi dependency version [\#14](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/14) ([hakobera](https://github.com/hakobera))
9
+ - Support custom filesystem for GoogleCloudStorageFileTarget [\#11](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/11) ([hakobera](https://github.com/hakobera))
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Remove unneeded log [\#16](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/16) ([hakobera](https://github.com/hakobera))
14
+ - Prepare release for 0.2.0 [\#15](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/15) ([hakobera](https://github.com/hakobera))
15
+ - Change test directory [\#13](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/13) ([hakobera](https://github.com/hakobera))
16
+ - Change ruby version on travis [\#12](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/12) ([hakobera](https://github.com/hakobera))
17
+
18
+ ## [v0.1.0](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/tree/v0.1.0) (2016-05-30)
19
+ **Closed issues:**
20
+
21
+ - Release v0.1.0 [\#8](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/issues/8)
22
+
23
+ **Merged pull requests:**
24
+
25
+ - Preapre release for v0.1.0 [\#10](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/10) ([hakobera](https://github.com/hakobera))
26
+ - Support JSON private key file for authentication [\#9](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/9) ([hakobera](https://github.com/hakobera))
27
+ - Update README [\#7](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/7) ([hakobera](https://github.com/hakobera))
28
+ - Standardize Google API Call error handling [\#6](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/6) ([hakobera](https://github.com/hakobera))
29
+ - Fix railse\_if\_exist option not working when copy and move [\#5](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/5) ([hakobera](https://github.com/hakobera))
30
+ - Rename gem and namespace [\#4](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/4) ([hakobera](https://github.com/hakobera))
31
+ - Add tests [\#3](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/3) ([hakobera](https://github.com/hakobera))
32
+ - Update tumugi to v0.5.1 [\#2](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/2) ([hakobera](https://github.com/hakobera))
33
+ - Fix test failed on travis [\#1](https://github.com/tumugi/tumugi-plugin-google_cloud_storage/pull/1) ([hakobera](https://github.com/hakobera))
34
+
35
+
36
+
37
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
@@ -4,13 +4,13 @@ module Tumugi
4
4
  module Plugin
5
5
  module GoogleCloudStorage
6
6
  class AtomicFile < Tumugi::AtomicFile
7
- def initialize(path, client)
7
+ def initialize(path, fs)
8
8
  super(path)
9
- @client = client
9
+ @fs = fs
10
10
  end
11
11
 
12
12
  def move_to_final_destination(temp_file)
13
- @client.upload(temp_file, path)
13
+ @fs.upload(temp_file, path)
14
14
  end
15
15
  end
16
16
  end
@@ -1,6 +1,8 @@
1
1
  require 'uri'
2
2
  require 'json'
3
+ require 'googleauth/service_account'
3
4
  require 'google/apis/storage_v1'
5
+ require 'google/apis/drive_v3'
4
6
  require 'tumugi/file_system'
5
7
 
6
8
  module Tumugi
@@ -10,7 +12,7 @@ module Tumugi
10
12
  attr_reader :client
11
13
 
12
14
  def initialize(config)
13
- @client = create_client(config)
15
+ save_config(config)
14
16
  end
15
17
 
16
18
  #######################################################################
@@ -33,16 +35,16 @@ module Tumugi
33
35
  raise Tumugi::FileSystemError.new("Cannot delete root of bucket at path '#{path}'") if root?(key)
34
36
 
35
37
  if obj_exist?(bucket, key)
36
- @client.delete_object(bucket, key)
38
+ client.delete_object(bucket, key, options: request_options)
37
39
  wait_until { !obj_exist?(bucket, key) }
38
40
  true
39
41
  elsif directory?(path)
40
42
  raise Tumugi::FileSystemError.new("Path '#{path}' is a directory. Must use recursive delete") if !recursive
41
43
 
42
44
  objs = entries(path).map(&:name)
43
- @client.batch do |client|
45
+ client.batch do |client|
44
46
  objs.each do |obj|
45
- client.delete_object(bucket, obj)
47
+ client.delete_object(bucket, obj, options: request_options)
46
48
  end
47
49
  end
48
50
  wait_until { !directory?(path) }
@@ -80,7 +82,7 @@ module Tumugi
80
82
  true
81
83
  else
82
84
  # Any objects with this prefix
83
- objects = @client.list_objects(bucket, prefix: obj, max_results: 20)
85
+ objects = client.list_objects(bucket, prefix: obj, max_results: 20, options: request_options)
84
86
  !!(objects.items && objects.items.size > 0)
85
87
  end
86
88
  end
@@ -95,7 +97,7 @@ module Tumugi
95
97
  next_page_token = ''
96
98
 
97
99
  until next_page_token.nil?
98
- objects = @client.list_objects(bucket, prefix: obj, page_token: next_page_token)
100
+ objects = client.list_objects(bucket, prefix: obj, page_token: next_page_token, options: request_options)
99
101
  if objects && objects.items
100
102
  results.concat(objects.items)
101
103
  next_page_token = objects.next_page_token
@@ -120,7 +122,7 @@ module Tumugi
120
122
  def upload(media, path, content_type: nil)
121
123
  bucket, key = path_to_bucket_and_key(path)
122
124
  obj = Google::Apis::StorageV1::Object.new(bucket: bucket, name: key)
123
- @client.insert_object(bucket, obj, upload_source: media, content_type: content_type)
125
+ client.insert_object(bucket, obj, upload_source: media, content_type: content_type, options: request_options)
124
126
  wait_until { obj_exist?(bucket, key) }
125
127
  rescue
126
128
  process_error($!)
@@ -131,7 +133,7 @@ module Tumugi
131
133
  if download_path.nil?
132
134
  download_path = Tempfile.new('tumugi_gcs_file_system').path
133
135
  end
134
- @client.get_object(bucket, key, download_dest: download_path)
136
+ client.get_object(bucket, key, download_dest: download_path, options: request_options)
135
137
  wait_until { File.exist?(download_path) }
136
138
 
137
139
  if block_given?
@@ -164,13 +166,13 @@ module Tumugi
164
166
  copied_objs = []
165
167
  entries(src_path).each do |entry|
166
168
  suffix = entry.name[src_prefix.length..-1]
167
- @client.copy_object(src_bucket, src_prefix + suffix,
168
- dest_bucket, dest_prefix + suffix)
169
+ client.copy_object(src_bucket, src_prefix + suffix,
170
+ dest_bucket, dest_prefix + suffix, options: request_options)
169
171
  copied_objs << (dest_prefix + suffix)
170
172
  end
171
173
  wait_until { copied_objs.all? {|obj| obj_exist?(dest_bucket, obj)} }
172
174
  else
173
- @client.copy_object(src_bucket, src_key, dest_bucket, dest_key)
175
+ client.copy_object(src_bucket, src_key, dest_bucket, dest_key, options: request_options)
174
176
  wait_until { obj_exist?(dest_bucket, dest_key) }
175
177
  end
176
178
  rescue
@@ -186,7 +188,7 @@ module Tumugi
186
188
  def create_bucket(bucket)
187
189
  unless bucket_exist?(bucket)
188
190
  b = Google::Apis::StorageV1::Bucket.new(name: bucket)
189
- @client.insert_bucket(@project_id, b)
191
+ client.insert_bucket(@project_id, b, options: request_options)
190
192
  true
191
193
  else
192
194
  false
@@ -197,7 +199,7 @@ module Tumugi
197
199
 
198
200
  def remove_bucket(bucket)
199
201
  if bucket_exist?(bucket)
200
- @client.delete_bucket(bucket)
202
+ client.delete_bucket(bucket, options: request_options)
201
203
  true
202
204
  else
203
205
  false
@@ -207,7 +209,7 @@ module Tumugi
207
209
  end
208
210
 
209
211
  def bucket_exist?(bucket)
210
- @client.get_bucket(bucket)
212
+ client.get_bucket(bucket, options: request_options)
211
213
  true
212
214
  rescue => e
213
215
  return false if e.status_code == 404
@@ -217,7 +219,7 @@ module Tumugi
217
219
  private
218
220
 
219
221
  def obj_exist?(bucket, key)
220
- @client.get_object(bucket, key)
222
+ client.get_object(bucket, key, options: request_options)
221
223
  true
222
224
  rescue => e
223
225
  return false if e.status_code == 404
@@ -236,7 +238,7 @@ module Tumugi
236
238
  end
237
239
  end
238
240
 
239
- def create_client(config)
241
+ def save_config(config)
240
242
  if config.private_key_file.nil?
241
243
  @project_id = config.project_id
242
244
  client_email = config.client_email
@@ -247,28 +249,39 @@ module Tumugi
247
249
  client_email = json['client_email']
248
250
  private_key = json['private_key']
249
251
  end
252
+ @key = {
253
+ client_email: client_email,
254
+ private_key: private_key
255
+ }
256
+ end
257
+
258
+ def client
259
+ return @cached_client if @cached_client && @cached_client_expiration > Time.now
250
260
 
251
- # https://cloud.google.com/storage/docs/authentication
252
- scope = "https://www.googleapis.com/auth/devstorage.read_write"
253
-
254
- if client_email and private_key
255
- auth = Signet::OAuth2::Client.new(
256
- token_credential_uri: "https://accounts.google.com/o/oauth2/token",
257
- audience: "https://accounts.google.com/o/oauth2/token",
258
- scope: scope,
259
- issuer: client_email,
260
- signing_key: OpenSSL::PKey.read(private_key))
261
- # MEMO: signet-0.6.1 depend on Farady.default_connection
262
- Faraday.default_connection.options.timeout = 60
263
- auth.fetch_access_token!
261
+ client = Google::Apis::StorageV1::StorageService.new
262
+ scope = Google::Apis::StorageV1::AUTH_DEVSTORAGE_READ_WRITE
263
+
264
+ if @key[:client_email] and @key[:private_key]
265
+ options = {
266
+ json_key_io: StringIO.new(JSON.generate(@key)),
267
+ scope: scope
268
+ }
269
+ auth = Google::Auth::ServiceAccountCredentials.make_creds(options)
264
270
  else
265
271
  auth = Google::Auth.get_application_default([scope])
266
- auth.fetch_access_token!
267
272
  end
268
-
269
- client = Google::Apis::StorageV1::StorageService.new
273
+ auth.fetch_access_token!
270
274
  client.authorization = auth
271
- client
275
+
276
+ @cached_client_expiration = Time.now + (auth.expires_in / 2)
277
+ @cached_client = client
278
+ end
279
+
280
+ def request_options
281
+ {
282
+ retries: 5,
283
+ timeout_sec: 60
284
+ }
272
285
  end
273
286
 
274
287
  def wait_until(&block)
@@ -12,11 +12,11 @@ module Tumugi
12
12
 
13
13
  attr_reader :bucket, :key, :path
14
14
 
15
- def initialize(bucket:, key:)
15
+ def initialize(bucket:, key:, fs: nil)
16
16
  @bucket = bucket
17
17
  @key = key
18
18
  @path = "gs://#{File.join(bucket, key)}"
19
- log "bucket='#{bucket}, key='#{key}'"
19
+ @fs = fs unless fs.nil?
20
20
  end
21
21
 
22
22
  def fs
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "tumugi-plugin-google_cloud_storage"
7
- spec.version = "0.1.0"
7
+ spec.version = "0.2.0"
8
8
  spec.authors = ["Kazuyuki Honda"]
9
9
  spec.email = ["hakobera@gmail.com"]
10
10
 
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.required_ruby_version = '>= 2.1'
21
21
 
22
- spec.add_runtime_dependency "tumugi", "~> 0.5.1"
22
+ spec.add_runtime_dependency "tumugi", ">= 0.5.1"
23
23
  spec.add_runtime_dependency "google-api-client", "~> 0.9.3"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.11"
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tumugi-plugin-google_cloud_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuyuki Honda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-30 00:00:00.000000000 Z
11
+ date: 2016-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tumugi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.5.1
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
26
  version: 0.5.1
27
27
  - !ruby/object:Gem::Dependency
@@ -131,6 +131,7 @@ extra_rdoc_files: []
131
131
  files:
132
132
  - ".gitignore"
133
133
  - ".travis.yml"
134
+ - CHANGELOG.md
134
135
  - Gemfile
135
136
  - README.md
136
137
  - Rakefile