Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AWS temporary credentials #403

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ AssetSync.configure do |config|
config.fog_directory = ENV['FOG_DIRECTORY']
config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
config.aws_session_token = ENV['AWS_SESSION_TOKEN'] if ENV.key?['AWS_SESSION_TOKEN']

# Don't delete files from the store
# config.existing_remote_files = 'keep'
Expand Down
4 changes: 3 additions & 1 deletion lib/asset_sync/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Invalid < StandardError; end
attr_reader :fog_public # e.g. true, false, "default"

# Amazon AWS
attr_accessor :aws_access_key_id, :aws_secret_access_key, :aws_reduced_redundancy, :aws_iam_roles, :aws_signature_version
attr_accessor :aws_access_key_id, :aws_secret_access_key, :aws_session_token, :aws_reduced_redundancy, :aws_iam_roles, :aws_signature_version
attr_accessor :fog_host # e.g. 's3.amazonaws.com'
attr_accessor :fog_port # e.g. '9000'
attr_accessor :fog_path_style # e.g. true
Expand Down Expand Up @@ -203,6 +203,7 @@ def load_yml!
self.fog_scheme = yml["fog_scheme"]
self.aws_access_key_id = yml["aws_access_key_id"]
self.aws_secret_access_key = yml["aws_secret_access_key"]
self.aws_session_token = yml["aws_session_token"] if yml.has_key?("aws_session_token")
self.aws_reduced_redundancy = yml["aws_reduced_redundancy"]
self.aws_iam_roles = yml["aws_iam_roles"]
self.aws_signature_version = yml["aws_signature_version"]
Expand Down Expand Up @@ -260,6 +261,7 @@ def fog_options
:aws_access_key_id => aws_access_key_id,
:aws_secret_access_key => aws_secret_access_key
})
options.merge!({:aws_session_token => aws_session_token}) if aws_session_token
end
options.merge!({:host => fog_host}) if fog_host
options.merge!({:port => fog_port}) if fog_port
Expand Down
1 change: 1 addition & 0 deletions lib/asset_sync/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Engine < Rails::Engine

config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID'] if ENV.has_key?('AWS_ACCESS_KEY_ID')
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY'] if ENV.has_key?('AWS_SECRET_ACCESS_KEY')
config.aws_session_token = ENV['AWS_SESSION_TOKEN'] if ENV.has_key?('AWS_SESSION_TOKEN')
config.aws_signature_version = ENV['AWS_SIGNATURE_VERSION'] if ENV.has_key?('AWS_SIGNATURE_VERSION')
config.aws_reduced_redundancy = ENV['AWS_REDUCED_REDUNDANCY'] == true if ENV.has_key?('AWS_REDUCED_REDUNDANCY')

Expand Down
4 changes: 4 additions & 0 deletions lib/generators/asset_sync/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def aws_secret_access_key
"<%= ENV['AWS_SECRET_ACCESS_KEY'] %>"
end

def aws_session_token
"<%= ENV['AWS_SESSION_TOKEN'] %>"
end

def google_storage_access_key_id
"<%= ENV['GOOGLE_STORAGE_ACCESS_KEY_ID'] %>"
end
Expand Down
1 change: 1 addition & 0 deletions lib/generators/asset_sync/templates/asset_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
config.fog_provider = 'AWS'
config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
config.aws_session_token = ENV['AWS_SESSION_TOKEN'] if ENV.key?['AWS_SESSION_TOKEN']
# To use AWS reduced redundancy storage.
# config.aws_reduced_redundancy = true
#
Expand Down