Skip to content

Commit

Permalink
Handle aws session token
Browse files Browse the repository at this point in the history
  • Loading branch information
umihico committed Nov 5, 2024
1 parent f225361 commit 4c0534e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/sitemap_generator/adapters/aws_sdk_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ class AwsSdkAdapter
# All other options you provide are passed directly to the AWS client.
# See https://docs.aws.amazon.com/sdk-for-ruby/v2/api/Aws/S3/Client.html#initialize-instance_method
# for a full list of supported options.
def initialize(bucket, aws_access_key_id: nil, aws_secret_access_key: nil, aws_region: nil, aws_endpoint: nil, acl: 'public-read', cache_control: 'private, max-age=0, no-cache', **options)
def initialize(bucket, aws_access_key_id: nil, aws_secret_access_key: nil, aws_session_token: nil, aws_region: nil, aws_endpoint: nil, acl: 'public-read', cache_control: 'private, max-age=0, no-cache', **options)
@bucket = bucket
@acl = acl
@cache_control = cache_control
@options = options
set_option_unless_set(:access_key_id, aws_access_key_id)
set_option_unless_set(:secret_access_key, aws_secret_access_key)
set_option_unless_set(:session_token, aws_session_token)
set_option_unless_set(:region, aws_region)
set_option_unless_set(:endpoint, aws_endpoint)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/adapters/s3_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class S3Adapter
def initialize(opts = {})
@aws_access_key_id = opts[:aws_access_key_id] || ENV['AWS_ACCESS_KEY_ID']
@aws_secret_access_key = opts[:aws_secret_access_key] || ENV['AWS_SECRET_ACCESS_KEY']
@aws_session_token = opts[:aws_session_token] || ENV['AWS_SESSION_TOKEN']
@fog_provider = opts[:fog_provider] || ENV['FOG_PROVIDER']
@fog_directory = opts[:fog_directory] || ENV['FOG_DIRECTORY']
@fog_region = opts[:fog_region] || ENV['FOG_REGION']
Expand All @@ -43,6 +44,7 @@ def write(location, raw_data)
if @aws_access_key_id && @aws_secret_access_key
credentials[:aws_access_key_id] = @aws_access_key_id
credentials[:aws_secret_access_key] = @aws_secret_access_key
credentials[:aws_session_token] = @aws_session_token if @aws_session_token
else
credentials[:use_iam_profile] = true
end
Expand Down
2 changes: 2 additions & 0 deletions spec/sitemap_generator/adapters/s3_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{
aws_access_key_id: 'aws_access_key_id',
aws_secret_access_key: 'aws_secret_access_key',
aws_session_token: 'aws_session_token',
fog_provider: 'fog_provider',
fog_directory: 'fog_directory',
fog_region: 'fog_region',
Expand All @@ -51,6 +52,7 @@
it 'sets options on the instance' do
expect(adapter.instance_variable_get(:@aws_access_key_id)).to eq('aws_access_key_id')
expect(adapter.instance_variable_get(:@aws_secret_access_key)).to eq('aws_secret_access_key')
expect(adapter.instance_variable_get(:@aws_session_token)).to eq('aws_session_token')
expect(adapter.instance_variable_get(:@fog_provider)).to eq('fog_provider')
expect(adapter.instance_variable_get(:@fog_directory)).to eq('fog_directory')
expect(adapter.instance_variable_get(:@fog_region)).to eq('fog_region')
Expand Down

0 comments on commit 4c0534e

Please sign in to comment.