Skip to content

Commit 548e740

Browse files
committed
Support ElasticBeanstalk optional session token
It's used in some authentication scenarios like Amazon AWS-Educate
1 parent 598b6f5 commit 548e740

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

lib/dpl/providers/elasticbeanstalk.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Elasticbeanstalk < Provider
2828

2929
opt '--access_key_id ID', 'AWS Access Key ID', required: true, secret: true
3030
opt '--secret_access_key KEY', 'AWS Secret Key', required: true, secret: true
31+
opt '--session_token TOKEN', 'AWS Session Token', required: false, secret: true
3132
opt '--region REGION', 'AWS Region the Elastic Beanstalk app is running in', default: 'us-east-1'
3233
opt '--app NAME', 'Elastic Beanstalk application name', default: :repo_name
3334
opt '--env NAME', 'Elastic Beanstalk environment name to be updated.'
@@ -41,14 +42,15 @@ class Elasticbeanstalk < Provider
4142
opt '--debug', internal: true
4243

4344
msgs login: 'Using Access Key: %{access_key_id}',
45+
login_token: 'Using Access Key: %{access_key_id}, Session Token: %{session_token}',
4446
zip_add: 'Adding %s'
4547

4648
msgs clean_description: 'Removed non-printable characters from the version description'
4749

4850
attr_reader :started, :object, :version
4951

5052
def login
51-
info :login
53+
info(session_token ? :login_token : :login)
5254
end
5355

5456
def setup
@@ -171,7 +173,7 @@ def environment
171173
end
172174

173175
def credentials
174-
Aws::Credentials.new(access_key_id, secret_access_key)
176+
Aws::Credentials.new(access_key_id, secret_access_key, session_token)
175177
end
176178

177179
def s3

spec/dpl/providers/elasticbeanstalk_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@
118118
it { should have_run '[info] Using Access Key: ac******************' }
119119
end
120120

121+
describe 'with ~/.aws/credentials', run: false do
122+
let(:args) { |e| %w(--env env --bucket_name bucket) }
123+
124+
file '~/.aws/credentials', <<-str.sub(/^\s*/, '')
125+
[default]
126+
aws_access_key_id=access_key_id
127+
aws_secret_access_key=secret_access_key
128+
aws_session_token=token
129+
str
130+
131+
before { subject.run }
132+
it { should have_run '[info] Using Access Key: ac******************, Session Token: t*******************' }
133+
end
134+
121135
describe 'with ~/.aws/config', run: false do
122136
let(:args) { |e| %w(--access_key_id id --secret_access_key secret) }
123137

0 commit comments

Comments
 (0)