onlyoffice_s3_wrapper 0.1.2 → 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
  SHA256:
3
- metadata.gz: 4af2be8cb335b101363b5cef8e5cc0887399dd737283d5c28229f1468b37c5df
4
- data.tar.gz: 6bdd4346707a555268285f21ee1b0a75d821998d94b5df73fc92f518a6cf1d20
3
+ metadata.gz: a6147e29e1e324812b01f9748f18a4aa66f1e391d8888acd2c2a8e49a28076db
4
+ data.tar.gz: f343cc5ca7cbc42e9412f2f127a05fc39ed9cdcbd31f9a1dd1eeb9820350c8f3
5
5
  SHA512:
6
- metadata.gz: e974d934b9c74d0d50e43ac55e1e20f6c8e81a939074c558e3cc574b26ac58f388e446765bb640212de4b8bca0f121b8fc56ca3ac04c0a32fa13ff755c415e8a
7
- data.tar.gz: 7fe4920dfd38dd251b4c6f6161e194d2a6b118f3c685275f8f8e75fc7d139c98fa26fa52aa521bbbab2ff6ae71369d7e0407fbfb16c66373699c608365a0a0bf
6
+ metadata.gz: 627aa9ab9034ba2253555da52a7409edc0d521cbca545c8e11a7d0406dafe56e272d82da004712690b33856c95668280fbb2738e4f81c48dd2b5e4e4d83b9a8e
7
+ data.tar.gz: a297f145abe4a37aeb26bd7d48973793015e24e175979961ccb0313372ccf602e8d0085d3ccebca35fd983644cc86bdc274cce32fddbba582db6d422d5b0f94c
@@ -7,6 +7,7 @@ require 'onlyoffice_file_helper'
7
7
  require 'onlyoffice_s3_wrapper/path_helper'
8
8
  require 'onlyoffice_s3_wrapper/version'
9
9
 
10
+ # Namespace for Gem
10
11
  module OnlyofficeS3Wrapper
11
12
  # Class for working with amazon s3
12
13
  class AmazonS3Wrapper
@@ -27,6 +28,10 @@ module OnlyofficeS3Wrapper
27
28
  @download_folder = Dir.mktmpdir('amazon-s3-downloads')
28
29
  end
29
30
 
31
+ # Get files by prefix
32
+ # @param prefix [String] prefix to filter
33
+ # @param field [Symbol] field to get
34
+ # @return [Array<Object>] result set
30
35
  def get_files_by_prefix(prefix = nil, field: :key)
31
36
  @bucket.objects(prefix: prefix)
32
37
  .collect(&field)
@@ -40,50 +45,81 @@ module OnlyofficeS3Wrapper
40
45
  @bucket.objects(prefix: prefix).collect(&:key)
41
46
  end
42
47
 
48
+ # Is string path to folder
49
+ # @param str [String] path
50
+ # @return [True, False]
43
51
  def folder?(str)
44
52
  str.end_with? '/'
45
53
  end
46
54
 
55
+ # Get object by name
56
+ # @param obj_name [String] name of object
57
+ # @return [Object]
47
58
  def get_object(obj_name)
48
59
  @bucket.object(obj_name)
49
60
  end
50
61
 
51
- def download_file_by_name(file_name, download_folder = @download_folder)
62
+ # @param file_name [String] path to file in S3 bucket
63
+ # @param download_location [String] path to save file.
64
+ # Can be full path to file, or just the directory to save
65
+ # @return [String] full path to file
66
+ def download_file_by_name(file_name, download_location = nil)
52
67
  object = get_object(file_name)
53
- download_object(object, download_folder)
54
- OnlyofficeLoggerHelper.log("Downloaded file with name #{file_name} to "\
55
- "folder #{download_folder}")
68
+ temp_location = download_object(object, @download_folder)
69
+ OnlyofficeLoggerHelper.log("Temp downloaded file: #{temp_location}")
70
+
71
+ return temp_location unless download_location
72
+
73
+ download_location = "#{download_location}/#{File.basename(file_name)}" if File.directory?(download_location)
74
+ FileUtils.mv(temp_location, download_location)
75
+ download_location
56
76
  end
57
77
 
78
+ # Download object
79
+ # @param object [Object] to download
80
+ # @param download_folder [String] path to save
81
+ # @return [String] path to downloaded file
58
82
  def download_object(object, download_folder = @download_folder)
83
+ file_name = "#{download_folder}/#{File.basename(object.key)}"
59
84
  link = object.presigned_url(:get, expires_in: 3600)
60
- OnlyofficeLoggerHelper.log('Try to download object with name '\
61
- "#{object.key} to #{download_folder}")
62
- File.open("#{download_folder}/#{File.basename(object.key)}", 'w') do |f|
85
+ File.open(file_name, 'w') do |f|
63
86
  IO.copy_stream(URI.parse(link).open, f)
64
87
  end
65
- OnlyofficeLoggerHelper.log("File with name #{object.key} successfully "\
66
- "downloaded to folder #{download_folder}")
67
- rescue StandardError
68
- raise("File #{object.key} is not found un bucket #{@bucket.name}")
88
+ file_name
89
+ rescue StandardError => e
90
+ raise("File #{file_name} download failed with: #{e}")
69
91
  end
70
92
 
93
+ # Upload file
94
+ # @param file_path [String] file to upload
95
+ # @param upload_folder [String] path to upload
96
+ # @return [nil]
71
97
  def upload_file(file_path, upload_folder)
72
98
  path = bucket_file_path(File.basename(file_path),
73
99
  upload_folder)
74
100
  @bucket.object(path).upload_file(file_path)
75
101
  end
76
102
 
103
+ # Make file public
104
+ # @param file_path [String] file to make public
105
+ # @return [Array<String, String>] public url and permissions
77
106
  def make_public(file_path)
78
107
  @bucket.object(file_path).acl.put(acl: 'public-read')
79
108
  permission = @bucket.object(file_path).acl.grants.last.permission
80
109
  [@bucket.object(file_path).public_url.to_s, permission]
81
110
  end
82
111
 
112
+ # Get permissions for file
113
+ # @param file_path [String] path to file
114
+ # @return [Aws::S3::ObjectAcl] permissions
83
115
  def get_permission_by_link(file_path)
84
116
  @bucket.object(file_path).acl
85
117
  end
86
118
 
119
+ # Upload file/folder and make public
120
+ # @param file_path [String] file to upload
121
+ # @param upload_folder [True, False] is this a folder
122
+ # @return [String] public url
87
123
  def upload_file_and_make_public(file_path, upload_folder = nil)
88
124
  upload_file(file_path, upload_folder)
89
125
  make_public(bucket_file_path(File.basename(file_path), upload_folder))
@@ -91,26 +127,30 @@ module OnlyofficeS3Wrapper
91
127
  upload_folder)).public_url
92
128
  end
93
129
 
130
+ # Delete file by name
131
+ # @param file_path [String] name of file
132
+ # @return [nil]
94
133
  def delete_file(file_path)
95
134
  file_path = file_path.sub('/', '') if file_path[0] == '/'
96
135
  get_object(file_path).delete
97
136
  end
98
137
 
99
- private
100
-
101
138
  # Get S3 key and S3 private key
139
+ # @param force_file_read [True, False] force key read from file
102
140
  # @return [Array <String>] list of keys
103
- def read_keys
104
- return if read_env_keys
141
+ def read_keys(force_file_read: false)
142
+ return if read_env_keys && !force_file_read
105
143
 
106
- @access_key_id = File.read(Dir.home + '/.s3/key').strip
107
- @secret_access_key = File.read(Dir.home + '/.s3/private_key').strip
144
+ @access_key_id = File.read("#{Dir.home}/.s3/key").strip &&
145
+ @secret_access_key = File.read("#{Dir.home}/.s3/private_key").strip
108
146
  rescue Errno::ENOENT
109
147
  raise Errno::ENOENT, "No key or private key found in #{Dir.home}/.s3/ "\
110
148
  "Please create files #{Dir.home}/.s3/key "\
111
149
  "and #{Dir.home}/.s3/private_key"
112
150
  end
113
151
 
152
+ private
153
+
114
154
  # Read keys from env variables
115
155
  def read_env_keys
116
156
  return false unless ENV['S3_KEY'] && ENV['S3_PRIVATE_KEY']
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeS3Wrapper
4
+ # [String] Name of gem
5
+ NAME = 'onlyoffice_s3_wrapper'
6
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OnlyofficeS3Wrapper
4
- VERSION = '0.1.2'
4
+ # [String] Version of gem
5
+ VERSION = '0.2.0'
5
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onlyoffice_s3_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ONLYOFFICE
@@ -10,36 +10,162 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-01-24 00:00:00.000000000 Z
13
+ date: 2020-09-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk-s3
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: '1'
21
+ version: 1.79.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: '1'
28
+ version: 1.79.1
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: onlyoffice_file_helper
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
33
+ - - '='
34
34
  - !ruby/object:Gem::Version
35
- version: '0.1'
35
+ version: 0.3.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - "~>"
40
+ - - '='
41
41
  - !ruby/object:Gem::Version
42
- version: '0.1'
42
+ version: 0.3.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: overcommit
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '='
48
+ - !ruby/object:Gem::Version
49
+ version: 0.55.0
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '='
55
+ - !ruby/object:Gem::Version
56
+ version: 0.55.0
57
+ - !ruby/object:Gem::Dependency
58
+ name: rake
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '='
62
+ - !ruby/object:Gem::Version
63
+ version: 13.0.1
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '='
69
+ - !ruby/object:Gem::Version
70
+ version: 13.0.1
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 3.9.0
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '='
83
+ - !ruby/object:Gem::Version
84
+ version: 3.9.0
85
+ - !ruby/object:Gem::Dependency
86
+ name: rubocop
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '='
90
+ - !ruby/object:Gem::Version
91
+ version: 0.90.0
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '='
97
+ - !ruby/object:Gem::Version
98
+ version: 0.90.0
99
+ - !ruby/object:Gem::Dependency
100
+ name: rubocop-performance
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '='
104
+ - !ruby/object:Gem::Version
105
+ version: 1.8.0
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '='
111
+ - !ruby/object:Gem::Version
112
+ version: 1.8.0
113
+ - !ruby/object:Gem::Dependency
114
+ name: rubocop-rake
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '='
118
+ - !ruby/object:Gem::Version
119
+ version: 0.5.1
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '='
125
+ - !ruby/object:Gem::Version
126
+ version: 0.5.1
127
+ - !ruby/object:Gem::Dependency
128
+ name: rubocop-rspec
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '='
132
+ - !ruby/object:Gem::Version
133
+ version: 1.43.2
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '='
139
+ - !ruby/object:Gem::Version
140
+ version: 1.43.2
141
+ - !ruby/object:Gem::Dependency
142
+ name: simplecov
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '='
146
+ - !ruby/object:Gem::Version
147
+ version: 0.19.0
148
+ type: :development
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '='
153
+ - !ruby/object:Gem::Version
154
+ version: 0.19.0
155
+ - !ruby/object:Gem::Dependency
156
+ name: yard
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - '='
160
+ - !ruby/object:Gem::Version
161
+ version: 0.9.25
162
+ type: :development
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - '='
167
+ - !ruby/object:Gem::Version
168
+ version: 0.9.25
43
169
  description: ONLYOFFICE Helper Gem for S3. Used in QA
44
170
  email:
45
171
  - shockwavenn@gmail.com
@@ -48,14 +174,19 @@ executables: []
48
174
  extensions: []
49
175
  extra_rdoc_files: []
50
176
  files:
51
- - README.md
52
177
  - lib/onlyoffice_s3_wrapper.rb
178
+ - lib/onlyoffice_s3_wrapper/name.rb
53
179
  - lib/onlyoffice_s3_wrapper/path_helper.rb
54
180
  - lib/onlyoffice_s3_wrapper/version.rb
55
- homepage: https://github.com/onlyoffice-testing-robot/onlyoffice_s3_wrapper
181
+ homepage: https://github.com/ONLYOFFICE-QA/onlyoffice_s3_wrapper
56
182
  licenses:
57
183
  - AGPL-3.0
58
- metadata: {}
184
+ metadata:
185
+ bug_tracker_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_s3_wrapper/issues
186
+ changelog_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_s3_wrapper/blob/master/CHANGELOG.md
187
+ documentation_uri: https://www.rubydoc.info/gems/onlyoffice_s3_wrapper
188
+ homepage_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_s3_wrapper
189
+ source_code_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_s3_wrapper
59
190
  post_install_message:
60
191
  rdoc_options: []
61
192
  require_paths:
@@ -64,14 +195,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
195
  requirements:
65
196
  - - ">="
66
197
  - !ruby/object:Gem::Version
67
- version: '0'
198
+ version: '2.5'
68
199
  required_rubygems_version: !ruby/object:Gem::Requirement
69
200
  requirements:
70
201
  - - ">="
71
202
  - !ruby/object:Gem::Version
72
203
  version: '0'
73
204
  requirements: []
74
- rubygems_version: 3.0.6
205
+ rubygems_version: 3.1.4
75
206
  signing_key:
76
207
  specification_version: 4
77
208
  summary: ONLYOFFICE Helper Gem for S3
data/README.md DELETED
@@ -1,39 +0,0 @@
1
- # OnlyofficeS3Wrapper
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/onlyoffice_s3_wrapper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'onlyoffice_s3_wrapper'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install onlyoffice_s3_wrapper
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- 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 push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/onlyoffice_s3_wrapper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
-
37
- ## Code of Conduct
38
-
39
- Everyone interacting in the OnlyofficeS3Wrapper project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/onlyoffice_s3_wrapper/blob/master/CODE_OF_CONDUCT.md).