Skip to content
This repository has been archived by the owner on Oct 7, 2022. It is now read-only.

Commit

Permalink
Support AssumeRole via .aws/config only when --profile is set
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Apr 24, 2017
1 parent b8ba120 commit 8c08e8c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: ruby
rvm: rvm:
- 2.0.0 - 2.0.0
script: script:
- bundle install
- bundle exec rake - bundle exec rake
env: env:
global: global:
Expand Down
22 changes: 19 additions & 3 deletions bin/piculet
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -60,9 +60,25 @@ ARGV.options do |opt|
} }
elsif profile_name or credentials_path elsif profile_name or credentials_path
credentials_opts = {} credentials_opts = {}
credentials_opts[:profile_name] = profile_name if profile_name if credentials_path
credentials_opts[:path] = credentials_path if credentials_path credentials_opts[:path] = credentials_path
provider = AWS::Core::CredentialProviders::SharedCredentialFileProvider.new(credentials_opts) AWSConfig.credentials_file = credentials_path
end
if profile_name
credentials_opts[:profile_name] = profile_name
role_arn = AWSConfig[profile_name][:role_arn]
end
if role_arn
session_name = "piculet-session-#{Time.now.to_i}"
sts = AWS::STS.new(AWSConfig[profile_name].config_hash)
provider = AWS::Core::CredentialProviders::AssumeRoleProvider.new(
sts: sts,
role_arn: role_arn,
role_session_name: session_name
)
else
provider = AWS::Core::CredentialProviders::SharedCredentialFileProvider.new(credentials_opts)
end
aws_opts[:credential_provider] = provider aws_opts[:credential_provider] = provider
elsif (access_key and !secret_key) or (!access_key and secret_key) or mode.nil? elsif (access_key and !secret_key) or (!access_key and secret_key) or mode.nil?
puts opt.help puts opt.help
Expand Down
1 change: 1 addition & 0 deletions lib/piculet.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'ipaddr' require 'ipaddr'


require 'aws-sdk-v1' require 'aws-sdk-v1'
require 'aws_config'


require 'piculet/ext/ec2-owner-id-ext' require 'piculet/ext/ec2-owner-id-ext'
require 'piculet/ext/security-group' require 'piculet/ext/security-group'
Expand Down
1 change: 1 addition & 0 deletions piculet.gemspec
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "diffy" spec.add_dependency "diffy"
spec.add_dependency "hashie" spec.add_dependency "hashie"
spec.add_dependency "nokogiri", "~> 1.6.8" spec.add_dependency "nokogiri", "~> 1.6.8"
spec.add_dependency "aws_config", "0.1.0"


#spec.files = `git ls-files`.split($/) #spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
Expand Down

0 comments on commit 8c08e8c

Please sign in to comment.