onlyoffice_s3_wrapper 0.1.2 → 0.5.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: 25f38aa09f4a824ded25d7ce67f2d755b6198bc3d3ef0da38ce34f7f764ee073
4
+ data.tar.gz: 867c8fbe23ef0652ac46d67616603bc3f1114cbcbd42e9bb4be1f0328640d94f
5
5
  SHA512:
6
- metadata.gz: e974d934b9c74d0d50e43ac55e1e20f6c8e81a939074c558e3cc574b26ac58f388e446765bb640212de4b8bca0f121b8fc56ca3ac04c0a32fa13ff755c415e8a
7
- data.tar.gz: 7fe4920dfd38dd251b4c6f6161e194d2a6b118f3c685275f8f8e75fc7d139c98fa26fa52aa521bbbab2ff6ae71369d7e0407fbfb16c66373699c608365a0a0bf
6
+ metadata.gz: cd20669e80e5d8864681f3bc027d669e2ca87b90b011d4cae92807221d1ff958c746e500599a260a9848b44b4d9394dd590139624bdee54451f7acef7e4809ec
7
+ data.tar.gz: 1215716abf6d09264ba2af95ce961b70d1fcb8369b68addfb854579ff839d02c4d1e16b39b46084b5ed89857f8eb3e4ebe4be1d45752b7e4f30833db7c32b3f4
@@ -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.5.0'
5
6
  end
@@ -7,9 +7,13 @@ 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
14
+ # @return [String] default content type for uploaded files
15
+ DEFAULT_CONTENT_TYPE = 'binary/octet-stream'
16
+
13
17
  include PathHelper
14
18
  attr_accessor :s3, :bucket, :download_folder
15
19
  # [String] Amazon key
@@ -27,6 +31,10 @@ module OnlyofficeS3Wrapper
27
31
  @download_folder = Dir.mktmpdir('amazon-s3-downloads')
28
32
  end
29
33
 
34
+ # Get files by prefix
35
+ # @param prefix [String] prefix to filter
36
+ # @param field [Symbol] field to get
37
+ # @return [Array<Object>] result set
30
38
  def get_files_by_prefix(prefix = nil, field: :key)
31
39
  @bucket.objects(prefix: prefix)
32
40
  .collect(&field)
@@ -40,83 +48,110 @@ module OnlyofficeS3Wrapper
40
48
  @bucket.objects(prefix: prefix).collect(&:key)
41
49
  end
42
50
 
51
+ # Is string path to folder
52
+ # @param str [String] path
53
+ # @return [True, False]
43
54
  def folder?(str)
44
55
  str.end_with? '/'
45
56
  end
46
57
 
58
+ # Get object by name
59
+ # @param obj_name [String] name of object
60
+ # @return [Object]
47
61
  def get_object(obj_name)
48
62
  @bucket.object(obj_name)
49
63
  end
50
64
 
51
- def download_file_by_name(file_name, download_folder = @download_folder)
65
+ # @param file_name [String] path to file in S3 bucket
66
+ # @param download_location [String] path to save file.
67
+ # Can be full path to file, or just the directory to save
68
+ # @return [String] full path to file
69
+ def download_file_by_name(file_name, download_location = nil)
52
70
  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}")
71
+ temp_location = download_object(object, @download_folder)
72
+ OnlyofficeLoggerHelper.log("Temp downloaded file: #{temp_location}")
73
+
74
+ return temp_location unless download_location
75
+
76
+ download_location = "#{download_location}/#{File.basename(file_name)}" if File.directory?(download_location)
77
+ FileUtils.mv(temp_location, download_location)
78
+ download_location
56
79
  end
57
80
 
81
+ # Download object
82
+ # @param object [Object] to download
83
+ # @param download_folder [String] path to save
84
+ # @return [String] path to downloaded file
58
85
  def download_object(object, download_folder = @download_folder)
86
+ file_name = "#{download_folder}/#{File.basename(object.key)}"
59
87
  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|
88
+ File.open(file_name, 'w') do |f|
63
89
  IO.copy_stream(URI.parse(link).open, f)
64
90
  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}")
91
+ file_name
92
+ rescue StandardError => e
93
+ raise("File #{file_name} download failed with: #{e}")
69
94
  end
70
95
 
71
- def upload_file(file_path, upload_folder)
96
+ # Upload file
97
+ # @param file_path [String] file to upload
98
+ # @param upload_folder [String] path to upload
99
+ # @param content_type [String] content type of file to upload
100
+ # @return [nil]
101
+ def upload_file(file_path, upload_folder, content_type = DEFAULT_CONTENT_TYPE)
72
102
  path = bucket_file_path(File.basename(file_path),
73
103
  upload_folder)
74
- @bucket.object(path).upload_file(file_path)
104
+ @bucket.object(path).upload_file(file_path, content_type: content_type)
75
105
  end
76
106
 
107
+ # Make file public
108
+ # @param file_path [String] file to make public
109
+ # @return [Array<String, String>] public url and permissions
77
110
  def make_public(file_path)
78
111
  @bucket.object(file_path).acl.put(acl: 'public-read')
79
112
  permission = @bucket.object(file_path).acl.grants.last.permission
80
113
  [@bucket.object(file_path).public_url.to_s, permission]
81
114
  end
82
115
 
116
+ # Get permissions for file
117
+ # @param file_path [String] path to file
118
+ # @return [Aws::S3::ObjectAcl] permissions
83
119
  def get_permission_by_link(file_path)
84
120
  @bucket.object(file_path).acl
85
121
  end
86
122
 
87
- def upload_file_and_make_public(file_path, upload_folder = nil)
88
- upload_file(file_path, upload_folder)
123
+ # Upload file/folder and make public
124
+ # @param file_path [String] file to upload
125
+ # @param upload_folder [True, False] is this a folder
126
+ # @param content_type [String] content type of file to upload
127
+ # @return [String] public url
128
+ def upload_file_and_make_public(file_path,
129
+ upload_folder = nil,
130
+ content_type = DEFAULT_CONTENT_TYPE)
131
+ upload_file(file_path, upload_folder, content_type)
89
132
  make_public(bucket_file_path(File.basename(file_path), upload_folder))
90
133
  @bucket.object(bucket_file_path(File.basename(file_path),
91
134
  upload_folder)).public_url
92
135
  end
93
136
 
137
+ # Delete file by name
138
+ # @param file_path [String] name of file
139
+ # @return [nil]
94
140
  def delete_file(file_path)
95
141
  file_path = file_path.sub('/', '') if file_path[0] == '/'
96
142
  get_object(file_path).delete
97
143
  end
98
144
 
99
- private
100
-
101
145
  # Get S3 key and S3 private key
102
- # @return [Array <String>] list of keys
103
- def read_keys
104
- return if read_env_keys
105
-
106
- @access_key_id = File.read(Dir.home + '/.s3/key').strip
107
- @secret_access_key = File.read(Dir.home + '/.s3/private_key').strip
146
+ # @param key_location [String] Path to search for key files
147
+ # @return [nil]
148
+ def read_keys(key_location = "#{Dir.home}/.s3")
149
+ @access_key_id = File.read("#{key_location}/key").strip
150
+ @secret_access_key = File.read("#{key_location}/private_key").strip
108
151
  rescue Errno::ENOENT
109
- raise Errno::ENOENT, "No key or private key found in #{Dir.home}/.s3/ "\
110
- "Please create files #{Dir.home}/.s3/key "\
111
- "and #{Dir.home}/.s3/private_key"
112
- end
113
-
114
- # Read keys from env variables
115
- def read_env_keys
116
- return false unless ENV['S3_KEY'] && ENV['S3_PRIVATE_KEY']
117
-
118
- @access_key_id = ENV['S3_KEY']
119
- @secret_access_key = ENV['S3_PRIVATE_KEY']
152
+ raise Errno::ENOENT, "No key or private key found in #{key_location} "\
153
+ "Please create files #{key_location}/key "\
154
+ "and #{key_location}/private_key"
120
155
  end
121
156
  end
122
157
  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.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ONLYOFFICE
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-01-24 00:00:00.000000000 Z
13
+ date: 2021-12-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk-s3
@@ -32,14 +32,146 @@ dependencies:
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '0.1'
35
+ version: '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'
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'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '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'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '13'
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'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '3'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rubocop
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '1'
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'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '1'
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'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
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: '2'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - "~>"
139
+ - !ruby/object:Gem::Version
140
+ version: '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'
148
+ type: :development
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - "~>"
153
+ - !ruby/object:Gem::Version
154
+ version: '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'
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: 0.9.20
165
+ type: :development
166
+ prerelease: false
167
+ version_requirements: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: 0.9.20
43
175
  description: ONLYOFFICE Helper Gem for S3. Used in QA
44
176
  email:
45
177
  - shockwavenn@gmail.com
@@ -48,14 +180,20 @@ executables: []
48
180
  extensions: []
49
181
  extra_rdoc_files: []
50
182
  files:
51
- - README.md
52
183
  - lib/onlyoffice_s3_wrapper.rb
184
+ - lib/onlyoffice_s3_wrapper/name.rb
53
185
  - lib/onlyoffice_s3_wrapper/path_helper.rb
54
186
  - lib/onlyoffice_s3_wrapper/version.rb
55
- homepage: https://github.com/onlyoffice-testing-robot/onlyoffice_s3_wrapper
187
+ homepage: https://github.com/ONLYOFFICE-QA/onlyoffice_s3_wrapper
56
188
  licenses:
57
189
  - AGPL-3.0
58
- metadata: {}
190
+ metadata:
191
+ bug_tracker_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_s3_wrapper/issues
192
+ changelog_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_s3_wrapper/blob/master/CHANGELOG.md
193
+ documentation_uri: https://www.rubydoc.info/gems/onlyoffice_s3_wrapper
194
+ homepage_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_s3_wrapper
195
+ source_code_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_s3_wrapper
196
+ rubygems_mfa_required: 'true'
59
197
  post_install_message:
60
198
  rdoc_options: []
61
199
  require_paths:
@@ -64,14 +202,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
202
  requirements:
65
203
  - - ">="
66
204
  - !ruby/object:Gem::Version
67
- version: '0'
205
+ version: '2.5'
68
206
  required_rubygems_version: !ruby/object:Gem::Requirement
69
207
  requirements:
70
208
  - - ">="
71
209
  - !ruby/object:Gem::Version
72
210
  version: '0'
73
211
  requirements: []
74
- rubygems_version: 3.0.6
212
+ rubygems_version: 3.2.32
75
213
  signing_key:
76
214
  specification_version: 4
77
215
  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).