webpacker_uploader 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b7937b7a57c7be6ea442c7d321feb36005dab87386227ad7f9bdbd262dbe838
4
- data.tar.gz: abd3a34e04a85979607905611e354bbddaa6aa1c8059ed945e28bd5ed5bb7b13
3
+ metadata.gz: b1f1e410b9ed124323d818d4b436581aecd735717f47176bf9754091209e608d
4
+ data.tar.gz: e8732c0cab079cf51864b1addd8a3e8d94c1487fa371872213f5343f2473de03
5
5
  SHA512:
6
- metadata.gz: b61d0ab52871ad4700df2ce3a79ad89d7aed913073aaba4370c580878d3dfc556c6f4a52332fde1b63430e7d9aea253e6bb07ac8fff14be2c295d835f560a40e
7
- data.tar.gz: d41c5bb9716983ca88c6d3f8be8e93961b8cff4c57ffe635f2a9ef299fc0577856734d5da015e8a5e7232f2eb3ea98922989f535e202be283522ab2ec0494a64
6
+ metadata.gz: 0c52c1f98939ca6338579e23fbe186fadfa1b22204bf62ceaffdb3ec4e2387c2f0763330a0db7cfcbc898e7a77035719749458b5828a0d5b7ba3b3b78ecde8e0
7
+ data.tar.gz: 2dde591f7f50548ad64a14f401b325aa3a4e83566c78463602406a458d6d6bc331843ab188fd7142c8be616722671574bf43ec36d0d0dcc9155f9253bdc61c84
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  .ruby-version
10
10
  *.gem
11
11
  /test/test_app/log/
12
+ /integration/dummy/log/
data/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file. The format
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [[0.6.0]](https://github.com/tlatsas/webpacker_uploader/releases/tag/v0.6.0) - 2021-07-20
8
+
9
+ ### Added
10
+
11
+ - Allow passing arbitrary options to the AWS S3 Client through the AWS provider. ([#11](https://github.com/tlatsas/webpacker_uploader/pull/11), [@tlatsas](https://github.com/tlatsas))
12
+
13
+ ### Fixed
14
+
15
+ - Fix undefined method delegate for WebpackerUploader:Module when using the console script. ([#13](https://github.com/tlatsas/webpacker_uploader/pull/13), [@tlatsas](https://github.com/tlatsas))
16
+
7
17
  ## [[0.5.0]](https://github.com/tlatsas/webpacker_uploader/releases/tag/v0.5.0) - 2021-07-12
8
18
 
9
19
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- webpacker_uploader (0.5.0)
4
+ webpacker_uploader (0.6.0)
5
5
  mime-types
6
6
  rack (~> 2.0)
7
7
  webpacker (>= 5.1)
@@ -29,21 +29,21 @@ GEM
29
29
  tzinfo (~> 2.0)
30
30
  zeitwerk (~> 2.3)
31
31
  ast (2.4.2)
32
- aws-eventstream (1.1.0)
33
- aws-partitions (1.376.0)
34
- aws-sdk-core (3.108.0)
32
+ aws-eventstream (1.1.1)
33
+ aws-partitions (1.477.0)
34
+ aws-sdk-core (3.117.0)
35
35
  aws-eventstream (~> 1, >= 1.0.2)
36
36
  aws-partitions (~> 1, >= 1.239.0)
37
37
  aws-sigv4 (~> 1.1)
38
38
  jmespath (~> 1.0)
39
- aws-sdk-kms (1.38.0)
40
- aws-sdk-core (~> 3, >= 3.99.0)
39
+ aws-sdk-kms (1.44.0)
40
+ aws-sdk-core (~> 3, >= 3.112.0)
41
41
  aws-sigv4 (~> 1.1)
42
- aws-sdk-s3 (1.81.1)
43
- aws-sdk-core (~> 3, >= 3.104.3)
42
+ aws-sdk-s3 (1.96.1)
43
+ aws-sdk-core (~> 3, >= 3.112.0)
44
44
  aws-sdk-kms (~> 1)
45
45
  aws-sigv4 (~> 1.1)
46
- aws-sigv4 (1.2.2)
46
+ aws-sigv4 (1.2.4)
47
47
  aws-eventstream (~> 1, >= 1.0.2)
48
48
  builder (3.2.4)
49
49
  concurrent-ruby (1.1.9)
@@ -58,9 +58,11 @@ GEM
58
58
  method_source (1.0.0)
59
59
  mime-types (3.3.1)
60
60
  mime-types-data (~> 3.2015)
61
- mime-types-data (3.2021.0225)
61
+ mime-types-data (3.2021.0704)
62
+ mini_portile2 (2.5.3)
62
63
  minitest (5.14.2)
63
- nokogiri (1.11.7-x86_64-darwin)
64
+ nokogiri (1.11.7)
65
+ mini_portile2 (~> 2.5.0)
64
66
  racc (~> 1.4)
65
67
  parallel (1.20.1)
66
68
  parser (3.0.0.0)
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Ruby tests](https://img.shields.io/github/workflow/status/tlatsas/webpacker_uploader/Ruby%20tests?style=flat-square)](https://github.com/tlatsas/webpacker_uploader/actions)
4
4
  [![RuboCop](https://img.shields.io/github/workflow/status/tlatsas/webpacker_uploader/RuboCop?label=rubocop&style=flat-square)](https://github.com/tlatsas/webpacker_uploader/actions)
5
5
  [![Gem](https://img.shields.io/gem/v/webpacker_uploader?style=flat-square)](https://rubygems.org/gems/webpacker_uploader)
6
+ [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg?style=flat-square)](https://www.rubydoc.info/gems/webpacker_uploader)
6
7
 
7
8
  Webpacker uploader provides an easy way to upload your assets to AWS S3.
8
9
  It knows which files to upload by reading the `manifest.json` file.
@@ -147,6 +148,19 @@ interactive prompt that will allow you to experiment.
147
148
 
148
149
  To install this gem onto your local machine, run `bundle exec rake install`.
149
150
 
151
+ ## Integration tests
152
+
153
+ This gem also provides an integration test suite. It runs using [localstack](https://github.com/localstack/localstack/).
154
+ To run the integration tests, install docker on your system and spin up a localstack container running the s3 service.
155
+
156
+ ```shell
157
+ docker compose -f "integration/docker-compose.yml" up --detach
158
+ ```
159
+
160
+ To run the tests, use `rake test:integration`.
161
+
162
+ To stop the container once done run: `docker-compose -f "integration/docker-compose.yml" down`
163
+
150
164
  ## Contributing
151
165
 
152
166
  Bug reports and pull requests are welcome on GitHub at https://github.com/tlatsas/webpacker_uploader.
data/Rakefile CHANGED
@@ -12,4 +12,12 @@ Rake::TestTask.new(:test) do |t|
12
12
  t.test_files = FileList["test/**/*_test.rb"]
13
13
  end
14
14
 
15
+ namespace :test do
16
+ desc "Run integration tests using localstack"
17
+ Rake::TestTask.new(:integration) do |t|
18
+ t.libs << "integration"
19
+ t.test_files = FileList["integration/**/*_test.rb"]
20
+ end
21
+ end
22
+
15
23
  task default: :test
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/core_ext/module"
3
4
  require "active_support/core_ext/object/blank"
4
5
 
5
6
  module WebpackerUploader
@@ -7,7 +7,8 @@ module WebpackerUploader
7
7
  module Providers
8
8
  # AWS provider uploads files to AWS S3. It uses the +aws-sdk-s3+ gem.
9
9
  class Aws
10
- attr_reader :client, :resource, :bucket # @private
10
+ # AWS provider error class. Raised when the provided AWS client credentials options are wrong.
11
+ class CredentialsError < StandardError; end
11
12
 
12
13
  # @param [Hash] options
13
14
  # * :region (String) The S3 region name.
@@ -18,7 +19,12 @@ module WebpackerUploader
18
19
  # * :access_key_id (String) the AWS credentials access id.
19
20
  # * :secret_access_key (String) the AWS credentials secret access key.
20
21
  #
21
- # @example Initialize the using a named profile:
22
+ # @note Any unknown options will be passed directly to the +Aws::S3::Client+ class
23
+ # during initialization.
24
+ #
25
+ # @raise [CredentialsError] if the credential options Hash is not correct.
26
+ #
27
+ # @example Initialize using a named profile:
22
28
  #
23
29
  # provider_options = {
24
30
  # credentials: { profile_name: "staging" },
@@ -45,9 +51,11 @@ module WebpackerUploader
45
51
  # }
46
52
  # provider = WebpackerUploader::Providers::Aws.new(provider_options)
47
53
  def initialize(options)
48
- @client = ::Aws::S3::Client.new(client_options(options))
49
- @resource = ::Aws::S3::Resource.new(client: @client)
50
- @bucket = @resource.bucket(options[:bucket])
54
+ @region = options.delete(:region)
55
+ @bucket_name = options.delete(:bucket)
56
+ @credentials = credentials(options.delete(:credentials))
57
+ @aws_options = options
58
+ @resource = ::Aws::S3::Resource.new(client: client)
51
59
  end
52
60
 
53
61
  # Uploads a file to AWS S3.
@@ -57,25 +65,43 @@ module WebpackerUploader
57
65
  # @param content_type [String] The content type that will be set to the S3 object.
58
66
  # @return [void]
59
67
  def upload!(object_key, file, content_type = "")
60
- object = @bucket.object(object_key)
68
+ object = @resource.bucket(@bucket_name).object(object_key)
61
69
  object.upload_file(file, content_type: content_type)
62
70
  end
63
71
 
64
72
  private
65
- def client_options(options)
66
- opts = { region: options[:region] }
67
- opts[:profile] = options[:profile_name] if options.key? :profile_name
68
- opts[:credentials] = credentials(options) if credentials(options)
69
- opts
70
- end
71
-
72
73
  def credentials(options)
73
- if options.key?(:instance_profile) && options[:instance_profile]
74
+ if options.key?(:profile_name)
75
+ { profile: options[:profile_name] }
76
+ elsif options.key?(:instance_profile) && options[:instance_profile]
74
77
  ::Aws::InstanceProfileCredentials.new
75
- elsif options.key?(:access_key_id)
78
+ elsif options.key?(:access_key_id) && options.key?(:secret_access_key)
76
79
  ::Aws::Credentials.new(options[:access_key_id], options[:secret_access_key])
80
+ else
81
+ raise CredentialsError, "Wrong AWS provider credentials options."
77
82
  end
78
83
  end
84
+
85
+ def profile?
86
+ @credentials.is_a?(Hash) && @credentials.key?(:profile)
87
+ end
88
+
89
+ def credentials_object?
90
+ !profile?
91
+ end
92
+
93
+ def client
94
+ ::Aws::S3::Client.new(client_options)
95
+ end
96
+
97
+ def client_options
98
+ opts = {}
99
+ opts.merge!(@aws_options)
100
+ opts[:region] = @region
101
+ opts.merge!(@credentials) if profile?
102
+ opts[:credentials] = @credentials if credentials_object?
103
+ opts
104
+ end
79
105
  end
80
106
  end
81
107
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebpackerUploader
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+ require "webpacker_uploader/providers/aws"
5
+
6
+ class AwsTest < Minitest::Test
7
+ def test_credentials_initialization
8
+ assert_raises(WebpackerUploader::Providers::Aws::CredentialsError) do
9
+ WebpackerUploader::Providers::Aws.new(credentials: {})
10
+ end
11
+
12
+ assert_raises(WebpackerUploader::Providers::Aws::CredentialsError) do
13
+ WebpackerUploader::Providers::Aws.new(credentials: { access_key_id: "test" })
14
+ end
15
+ end
16
+ end
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  "source_code_uri" => "https://github.com/tlatsas/webpacker_uploader/tree/v#{s.version}"
21
21
  }
22
22
 
23
- s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(bin|test|.github)/}) }
23
+ s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(bin|test|integration|.github)/}) }
24
24
  s.test_files = `git ls-files -- test/*`.split("\n")
25
25
  s.require_paths = ["lib"]
26
26
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpacker_uploader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Latsas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-12 00:00:00.000000000 Z
11
+ date: 2021-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webpacker
@@ -135,6 +135,7 @@ files:
135
135
  - test/configuration_test.rb
136
136
  - test/manifest_test.rb
137
137
  - test/mime_test.rb
138
+ - test/providers/aws_test.rb
138
139
  - test/test_app/config/webpacker.yml
139
140
  - test/test_app/public/packs/manifest.json
140
141
  - test/test_helper.rb
@@ -147,7 +148,7 @@ metadata:
147
148
  homepage_uri: https://github.com/tlatsas/webpacker_uploader
148
149
  bug_tracker_uri: https://github.com/tlatsas/webpacker_uploader/issues
149
150
  changelog_uri: https://github.com/tlatsas/webpacker_uploader/blob/main/CHANGELOG.md
150
- source_code_uri: https://github.com/tlatsas/webpacker_uploader/tree/v0.5.0
151
+ source_code_uri: https://github.com/tlatsas/webpacker_uploader/tree/v0.6.0
151
152
  post_install_message:
152
153
  rdoc_options: []
153
154
  require_paths:
@@ -171,6 +172,7 @@ test_files:
171
172
  - test/configuration_test.rb
172
173
  - test/manifest_test.rb
173
174
  - test/mime_test.rb
175
+ - test/providers/aws_test.rb
174
176
  - test/test_app/config/webpacker.yml
175
177
  - test/test_app/public/packs/manifest.json
176
178
  - test/test_helper.rb