wt_s3_signer 0.3.0 → 1.0.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: 4d9af4f1dd28d4da07932e0515d3afef4283e170ecd04a4346671bc5bed0a3bb
4
- data.tar.gz: ee1534d3b34ae69f947ac936298f0b20b22e3ce356a85b8bfd16329d023bae47
3
+ metadata.gz: f0f72f6633de6786061caf9225caea94b6d5eeb40083895962c10ac06d711730
4
+ data.tar.gz: 87d6086cc05d0372442bf3ca05623fa47865a45acd758e4a0450e5329cc4aa76
5
5
  SHA512:
6
- metadata.gz: 2b8b4b29b4943746bbddb007d81a6b398d8bbe60b58ea0751cb21c3e264cca66393d5d2baf94c55230795f75f85bc56fd65eb5b946082830f1ea2fde459d6d8e
7
- data.tar.gz: 259d5038c1becca0b990c99f236f1bc9e76fc179401f06e366f5482481a8bd3b442e3cfc6e25d3636e725019b8c4ae0a329dc5a298253ddb28c8846a6decd21e
6
+ metadata.gz: 876a30ce3e8074072fb2380a3083ead9980948774cc41d0c28ac7ce8815b09271b5b764bb1e897eeba6de5b762b81206c50e28b69bb9df7df7df611329819416
7
+ data.tar.gz: aae3c570d6db90e7274c47bdd99b9d1bd5c53ca2a2715d137577dda6c6120c5a3db9eb858acebc8259efb8308143d4b9a8a4d8da6830a98999c5bc2913a8b01a
data/CHANGELOG.md CHANGED
@@ -1,2 +1,6 @@
1
+ ## 1.0.0
2
+ * Remove option `client:` `from WT::S3Signer.for_s3_bucket`
3
+ * Uses a singleton s3_client by default to take advantage of AWS credentials cache
4
+
1
5
  ## 0.3.0
2
6
  * Add option `client:` to `WT::S3Signer.for_s3_bucket`, so it's possible to inject a cached `Aws::S3::Client` instance and prevent too many requests to the AWS metadata endpoint
data/lib/wt_s3_signer.rb CHANGED
@@ -31,7 +31,7 @@ module WT
31
31
  # the AWS instance metadata endpoint
32
32
  # @param extra_attributes[Hash] any extra keyword arguments to pass to `S3Signer.new`
33
33
  # @return [WT::S3Signer]
34
- def self.for_s3_bucket(bucket, client: Aws::S3::Client.new, **extra_attributes)
34
+ def self.for_s3_bucket(bucket, **extra_attributes)
35
35
  kwargs = {}
36
36
 
37
37
  kwargs[:bucket_endpoint_url] = bucket.url
@@ -170,6 +170,13 @@ module WT
170
170
  Aws::S3::Bucket.new(bucket_name)
171
171
  end
172
172
 
173
+ # AWS gems have a mechanism to cache credentials internally. So take
174
+ # advantage of this, it's necessary to use the same client instance.
175
+ def self.client
176
+ @client ||= Aws::S3::Client.new
177
+ end
178
+ private_class_method :client
179
+
173
180
  def derive_signing_key(key, datestamp, region, service)
174
181
  prefixed_key = "AWS4" + key
175
182
  k_date = hmac_bytes(prefixed_key, datestamp)
@@ -1,5 +1,5 @@
1
1
  module WT
2
2
  class S3Signer
3
- VERSION = '0.3.0'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -45,21 +45,22 @@ describe WT::S3Signer do
45
45
  end
46
46
 
47
47
  describe '.for_s3_bucket' do
48
- it 'accepts an s3_client instance via dependency injection' do
48
+ it 'uses a singleton instance of s3 client' do
49
49
  allow(WT::S3Signer).to receive(:create_bucket).and_return(bucket)
50
50
  bucket.object('dir/testobject').put(body: 'is here')
51
51
 
52
- s3_client = Aws::S3::Client.new
52
+ # If other tests run before, they might instantiate the singleton client,
53
+ # so it's acceptable for Aws::S3::Client to not receive :new
54
+ expect(Aws::S3::Client).to receive(:new).at_most(:once).and_call_original
53
55
 
54
- expect(Aws::S3::Client).not_to receive(:new)
56
+ signer1 = described_class.for_s3_bucket(bucket, expires_in: 174)
57
+ signer2 = described_class.for_s3_bucket(bucket, expires_in: 175)
55
58
 
56
- signer = described_class.for_s3_bucket(
57
- bucket, client: s3_client, expires_in: 174
58
- )
59
+ presigned_url1 = signer1.presigned_get_url(object_key: 'dir/testobject')
60
+ presigned_url2 = signer2.presigned_get_url(object_key: 'dir/testobject')
59
61
 
60
- presigned_url = signer.presigned_get_url(object_key: 'dir/testobject')
61
-
62
- expect(presigned_url).to include("X-Amz-Expires=174")
62
+ expect(presigned_url1).to include("X-Amz-Expires=174")
63
+ expect(presigned_url2).to include("X-Amz-Expires=175")
63
64
  end
64
65
  end
65
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wt_s3_signer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Suriano
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  requirements: []
142
- rubygems_version: 3.1.2
142
+ rubygems_version: 3.1.6
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: A library for signing S3 key faster