Skip to content

Commit

Permalink
PR feedback #2
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Apr 29, 2024
1 parent be36879 commit 8437358
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module {{module_name}}
expiration: Time.now + 60 * 5
})
expect_auth({"name"=>"sigv4", "signingName"=>"s3express"})
EXPRESS_CREDENTIALS_CACHE.clear
Aws::S3.express_credentials_cache.clear
{{/s3_express_auth?}}
expect_auth({{{expected_auth}}})
{{/expect_auth?}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
module Aws
module S3
# @api private
ACCESS_GRANTS_CREDENTIALS_CACHE = LRUCache.new(max_entries: 100)
def self.access_grants_credentials_cache
@access_grants_credentials_cache ||= LRUCache.new(max_entries: 100)
end

# @api private
ACCESS_GRANTS_ACCOUNT_ID_CACHE = LRUCache.new(
max_entries: 100,
expiration: 60 * 10
)
def self.access_grants_account_id_cache
@access_grants_account_id_cache ||= LRUCache.new(
max_entries: 100,
expiration: 60 * 10
)
end

# Returns Credentials class for S3 Access Grants. Accepts GetDataAccess
# params and other configuration as options. See
Expand Down Expand Up @@ -44,8 +49,8 @@ def initialize(options = {})
@bucket_region_cache = BUCKET_REGIONS # shared cache with s3_signer
return unless @caching

@credentials_cache = ACCESS_GRANTS_CREDENTIALS_CACHE
@account_id_cache = ACCESS_GRANTS_ACCOUNT_ID_CACHE
@credentials_cache = Aws::S3.access_grants_credentials_cache
@account_id_cache = Aws::S3.access_grants_account_id_cache
end

def access_grants_credentials_for(options = {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
module Aws
module S3
# @api private
EXPRESS_CREDENTIALS_CACHE = LRUCache.new(max_entries: 100)
def self.express_credentials_cache
@express_credentials_cache ||= LRUCache.new(max_entries: 100)
end

# Returns Credentials class for S3 Express. Accepts CreateSession
# params as options. See {Client#create_session} for details.
Expand All @@ -20,7 +22,9 @@ def initialize(options = {})
@client = options.delete(:client)
@caching = options.delete(:caching) != false
@options = options
@cache = EXPRESS_CREDENTIALS_CACHE
return unless @caching

@cache = Aws::S3.express_credentials_cache
end

def express_credentials_for(bucket)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

$:.unshift(File.expand_path('../../../aws-sdk-s3control/lib', __FILE__))
require_relative 'spec_helper'

module Aws
Expand Down Expand Up @@ -43,8 +44,8 @@ module S3
end

after do
ACCESS_GRANTS_CREDENTIALS_CACHE.clear
ACCESS_GRANTS_ACCOUNT_ID_CACHE.clear
Aws::S3.access_grants_credentials_cache.clear
Aws::S3.access_grants_account_id_cache.clear
BUCKET_REGIONS.clear
end

Expand Down
1 change: 1 addition & 0 deletions gems/aws-sdk-s3/spec/access_grants_credentials_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

$:.unshift(File.expand_path('../../../aws-sdk-s3control/lib', __FILE__))
require_relative 'spec_helper'

module Aws
Expand Down
12 changes: 6 additions & 6 deletions gems/aws-sdk-s3/spec/endpoint_provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6528,7 +6528,7 @@ module Aws::S3
expiration: Time.now + 60 * 5
})
expect_auth({"name"=>"sigv4", "signingName"=>"s3express"})
EXPRESS_CREDENTIALS_CACHE.clear
Aws::S3.express_credentials_cache.clear
expect_auth({"name"=>"sigv4-s3express", "signingName"=>"s3express", "signingRegion"=>"us-east-1", "disableDoubleEncoding"=>true})
resp = client.get_object(
bucket: 'mybucket--use1-az1--x-s3',
Expand Down Expand Up @@ -6568,7 +6568,7 @@ module Aws::S3
expiration: Time.now + 60 * 5
})
expect_auth({"name"=>"sigv4", "signingName"=>"s3express"})
EXPRESS_CREDENTIALS_CACHE.clear
Aws::S3.express_credentials_cache.clear
expect_auth({"name"=>"sigv4-s3express", "signingName"=>"s3express", "signingRegion"=>"us-east-1", "disableDoubleEncoding"=>true})
resp = client.get_object(
bucket: 'mybucket--use1-az1--x-s3',
Expand Down Expand Up @@ -6607,7 +6607,7 @@ module Aws::S3
expiration: Time.now + 60 * 5
})
expect_auth({"name"=>"sigv4", "signingName"=>"s3express"})
EXPRESS_CREDENTIALS_CACHE.clear
Aws::S3.express_credentials_cache.clear
expect_auth({"name"=>"sigv4-s3express", "signingName"=>"s3express", "signingRegion"=>"ap-northeast-1", "disableDoubleEncoding"=>true})
resp = client.get_object(
bucket: 'mybucket--apne1-az1--x-s3',
Expand Down Expand Up @@ -6647,7 +6647,7 @@ module Aws::S3
expiration: Time.now + 60 * 5
})
expect_auth({"name"=>"sigv4", "signingName"=>"s3express"})
EXPRESS_CREDENTIALS_CACHE.clear
Aws::S3.express_credentials_cache.clear
expect_auth({"name"=>"sigv4-s3express", "signingName"=>"s3express", "signingRegion"=>"ap-northeast-1", "disableDoubleEncoding"=>true})
resp = client.get_object(
bucket: 'mybucket--apne1-az1--x-s3',
Expand Down Expand Up @@ -6891,7 +6891,7 @@ module Aws::S3
expiration: Time.now + 60 * 5
})
expect_auth({"name"=>"sigv4", "signingName"=>"s3express"})
EXPRESS_CREDENTIALS_CACHE.clear
Aws::S3.express_credentials_cache.clear
expect_auth({"name"=>"sigv4-s3express", "signingName"=>"s3express", "signingRegion"=>"us-west-2", "disableDoubleEncoding"=>true})
resp = client.get_object(
bucket: 'mybucket--usw2-az1--x-s3',
Expand Down Expand Up @@ -6945,7 +6945,7 @@ module Aws::S3
expiration: Time.now + 60 * 5
})
expect_auth({"name"=>"sigv4", "signingName"=>"s3express"})
EXPRESS_CREDENTIALS_CACHE.clear
Aws::S3.express_credentials_cache.clear
expect_auth({"name"=>"sigv4-s3express", "signingName"=>"s3express", "signingRegion"=>"us-west-2", "disableDoubleEncoding"=>true})
resp = client.get_object(
bucket: 'mybucket--usw2-az1--x-s3',
Expand Down
2 changes: 1 addition & 1 deletion gems/aws-sdk-s3/spec/express_credentials_provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module S3

describe '#express_credentials_for' do
after do
EXPRESS_CREDENTIALS_CACHE.clear
Aws::S3.express_credentials_cache.clear
end

it 'returns a new set of credentials for the bucket' do
Expand Down
5 changes: 4 additions & 1 deletion gems/aws-sdk-s3/spec/plugins/express_session_auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ module S3
session_token: 's3-session',
expiration: Time.now + 60 * 5
})
EXPRESS_CREDENTIALS_CACHE.clear
end

after do
Aws::S3.express_credentials_cache.clear
end

describe 's3 express auth' do
Expand Down

0 comments on commit 8437358

Please sign in to comment.