Skip to content
Permalink
Browse files

Support AssumeRole via .aws/config only when `--profile` is set

  • Loading branch information...
k1LoW committed Apr 24, 2017
1 parent b8ba120 commit 8c08e8cd2e2301b7919857beca99086afaee0fd1
Showing with 21 additions and 4 deletions.
  1. +0 −1 .travis.yml
  2. +19 −3 bin/piculet
  3. +1 −0 lib/piculet.rb
  4. +1 −0 piculet.gemspec
@@ -3,7 +3,6 @@ language: ruby
rvm:
- 2.0.0
script:
- bundle install
- bundle exec rake
env:
global:
@@ -60,9 +60,25 @@ ARGV.options do |opt|
}
elsif profile_name or credentials_path
credentials_opts = {}
credentials_opts[:profile_name] = profile_name if profile_name
credentials_opts[:path] = credentials_path if credentials_path
provider = AWS::Core::CredentialProviders::SharedCredentialFileProvider.new(credentials_opts)
if credentials_path
credentials_opts[:path] = credentials_path
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
elsif (access_key and !secret_key) or (!access_key and secret_key) or mode.nil?
puts opt.help
@@ -10,6 +10,7 @@
require 'ipaddr'

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

require 'piculet/ext/ec2-owner-id-ext'
require 'piculet/ext/security-group'
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "diffy"
spec.add_dependency "hashie"
spec.add_dependency "nokogiri", "~> 1.6.8"
spec.add_dependency "aws_config", "0.1.0"

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

0 comments on commit 8c08e8c

Please sign in to comment.
You can’t perform that action at this time.