activestorage-storj-s3 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9d4db330ebc9a658831d5260f645be98bd62c2ed93c19c9350741617a666192d
4
+ data.tar.gz: f63a6df7af0c284069c563396df3e05eb92071ffcd4a3d7467181d608885555d
5
+ SHA512:
6
+ metadata.gz: 8fd9ab82eef8973ea2f93dabe3b9c3088ceb2f5ce30c2f99e0b587fcbca5d69896b59d3c2f3e62b4309b8edd0f9e09392418b32bdbfaa60a1f0f12e87aa21998
7
+ data.tar.gz: 15a2512ba851bb81d048adc88187e2a98fdbd23ab0f40175c97f8976fc1c900453273c2fbc789ff644097f55bf3c5f89d6fde1aaf6c581b44425b41c1d34b05f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Your Data
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # ActiveStorage-Storj-S3
2
+ ActiveStorage-Storj-S3 is a ruby gem extension for [activestorage-storj](https://github.com/Your-Data/activestorage-storj) gem to provide [Storj S3 Compatible Gateway](https://docs.storj.io/dcs/api-reference/s3-compatible-gateway) support for some ActiveStorage features, e.g. [direct upload](https://guides.rubyonrails.org/active_storage_overview.html#direct-uploads) which requires [S3 presigned URL](https://docs.storj.io/dcs/api-reference/s3-compatible-gateway/using-presigned-urls).
3
+
4
+ ## Requirements
5
+ * [activestorage-storj](https://github.com/Your-Data/activestorage-storj) gem installed in a Rails project.
6
+
7
+ ## Installation
8
+ * Add this line to your Rails application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'activestorage-storj-s3', '~> 1.0'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ * Modify Storj configuration in `config/storage.yml`:
20
+
21
+ ```yaml
22
+ storj:
23
+ service: storj_s3 # change from "storj" to "storj_s3"
24
+ ...
25
+ # provide the Storj S3 gateway credentials
26
+ s3_gateway:
27
+ access_key_id: ""
28
+ secret_access_key: ""
29
+ endpoint: ""
30
+ region: global
31
+ ```
32
+
33
+ The rest configurations are same as in `activestorage-storj` gem.
34
+
35
+ ## Running the Tests
36
+
37
+ * Create `configurations.yml` file in `test/dummy/config/environments/service` folder, or copy the existing `configurations.example.yml` as `configurations.yml`.
38
+
39
+ * Provide Storj configurations for both `storj` and `storj_public` services in `configurations.yml`:
40
+
41
+ ```yaml
42
+ storj:
43
+ service: storj_s3
44
+ access_grant: ""
45
+ bucket: ""
46
+ auth_service_address: auth.storjshare.io:7777
47
+ link_sharing_address: https://link.storjshare.io
48
+ s3_gateway:
49
+ access_key_id: ""
50
+ secret_access_key: ""
51
+ endpoint: ""
52
+ region: global
53
+
54
+ storj_public:
55
+ service: storj_s3
56
+ access_grant: ""
57
+ bucket: ""
58
+ auth_service_address: auth.storjshare.io:7777
59
+ link_sharing_address: https://link.storjshare.io
60
+ s3_gateway:
61
+ access_key_id: ""
62
+ secret_access_key: ""
63
+ endpoint: ""
64
+ region: global
65
+ public: true
66
+ ```
67
+
68
+ * Run the tests:
69
+
70
+ ```bash
71
+ $ bin/test
72
+ ```
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_storage/service/storj_service"
4
+ require "aws-sdk-s3"
5
+
6
+ module ActiveStorage
7
+ class Service::StorjS3Service < Service::StorjService
8
+ class S3GatewayConfigRequiredError < ActiveStorage::Error; end
9
+
10
+ attr_reader :s3_bucket
11
+
12
+ def initialize(access_grant:, bucket:, upload_chunk_size: nil, download_chunk_size: nil, multipart_upload_threshold: nil,
13
+ auth_service_address: nil, link_sharing_address: nil, public: false, **config)
14
+ super(access_grant: access_grant, bucket: bucket, upload_chunk_size: upload_chunk_size, download_chunk_size: download_chunk_size,
15
+ multipart_upload_threshold: multipart_upload_threshold, auth_service_address: auth_service_address, link_sharing_address: link_sharing_address,
16
+ public: public, **config)
17
+
18
+ s3_config = config[:s3_gateway]
19
+ raise S3GatewayConfigRequiredError.new, "S3 Gateway configuration is required" if s3_config.blank?
20
+
21
+ @s3_client = Aws::S3::Resource.new(
22
+ access_key_id: s3_config[:access_key_id],
23
+ secret_access_key: s3_config[:secret_access_key],
24
+ region: s3_config[:region],
25
+ endpoint: s3_config[:endpoint]
26
+ )
27
+ @s3_bucket = @s3_client.bucket(bucket)
28
+
29
+ upload = s3_config[:upload] || {}
30
+ @s3_upload_options = upload
31
+ @s3_upload_options[:acl] = "public-read" if public?
32
+ end
33
+
34
+ def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:, custom_metadata: {})
35
+ instrument :url, key: key do |payload|
36
+ generated_url = @s3_bucket.object(key).presigned_url :put, expires_in: expires_in.to_i,
37
+ content_type: content_type, content_length: content_length, content_md5: checksum,
38
+ metadata: custom_metadata, whitelist_headers: ["content-length"], **@s3_upload_options
39
+
40
+ payload[:url] = generated_url
41
+
42
+ generated_url
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ module ActiveStorage
2
+ module Storj
3
+ module S3
4
+ class Railtie < ::Rails::Railtie
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module ActiveStorage
2
+ module Storj
3
+ module S3
4
+ VERSION = "1.0.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :activestorage_storj do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activestorage-storj-s3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Your Data
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 7.0.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '7.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 7.0.4
33
+ - !ruby/object:Gem::Dependency
34
+ name: aws-sdk-s3
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.48'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.48'
47
+ description: Providing Storj S3 gateway support for activestorage-storj gem
48
+ email:
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - lib/active_storage/service/storj_s3_service.rb
57
+ - lib/active_storage/storj/s3/railtie.rb
58
+ - lib/active_storage/storj/s3/version.rb
59
+ - lib/tasks/activestorage/storj_tasks.rake
60
+ homepage: https://github.com/Your-Data/activestorage-storj-s3
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 3.3.26
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: activestorage-storj gem extension to provide Storj S3 gateway support
83
+ test_files: []