wt_s3_signer 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/wt_s3_signer.rb +8 -1
- data/lib/wt_s3_signer/version.rb +1 -1
- data/spec/url_signing_spec.rb +10 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0f72f6633de6786061caf9225caea94b6d5eeb40083895962c10ac06d711730
|
4
|
+
data.tar.gz: 87d6086cc05d0372442bf3ca05623fa47865a45acd758e4a0450e5329cc4aa76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
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)
|
data/lib/wt_s3_signer/version.rb
CHANGED
data/spec/url_signing_spec.rb
CHANGED
@@ -45,21 +45,22 @@ describe WT::S3Signer do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
describe '.for_s3_bucket' do
|
48
|
-
it '
|
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
|
-
|
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
|
-
|
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
|
-
|
57
|
-
|
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
|
-
|
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.
|
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.
|
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
|