Class: Awshark::ProfileResolver
- Inherits:
-
Object
- Object
- Awshark::ProfileResolver
- Defined in:
- lib/awshark/profile_resolver.rb
Instance Method Summary collapse
- #credentials ⇒ Object
-
#initialize(options) ⇒ ProfileResolver
constructor
A new instance of ProfileResolver.
- #mfa_token ⇒ Object
-
#region ⇒ Object
Returns Aws region from option, env or .aws/config.
-
#role_credentials ⇒ Object
Returns Aws credentials for configuration with [profile] role_arn = ROLE_ARN source_profile = SOURCE_PROFILE.
-
#user_credentials ⇒ Object
Returns Aws credentials for configuration with [profile] aws_access_key_id=AWS_ACCESS_KEY_ID aws_secret_access_key=AWS_SECRET_ACCESS_KEY.
Constructor Details
#initialize(options) ⇒ ProfileResolver
Returns a new instance of ProfileResolver.
5 6 7 8 9 10 11 12 |
# File 'lib/awshark/profile_resolver.rb', line 5 def initialize() @profile = [:profile] || ENV.fetch('AWS_PROFILE') @shared_config = ::Aws::SharedConfig.new( profile_name: @profile, config_enabled: true ) @region = [:region] || ENV.fetch('REGION', nil) end |
Instance Method Details
#credentials ⇒ Object
14 15 16 |
# File 'lib/awshark/profile_resolver.rb', line 14 def credentials user_credentials || role_credentials end |
#mfa_token ⇒ Object
54 55 56 57 |
# File 'lib/awshark/profile_resolver.rb', line 54 def mfa_token print %(Please enter MFA token for AWS account #{@profile}: ) $stdin.gets.strip end |
#region ⇒ Object
Returns Aws region from option, env or .aws/config
36 37 38 |
# File 'lib/awshark/profile_resolver.rb', line 36 def region @region || @shared_config.region || 'eu-central-1' end |
#role_credentials ⇒ Object
Returns Aws credentials for configuration with
[profile]
role_arn = ROLE_ARN
source_profile = SOURCE_PROFILE
47 48 49 50 51 52 |
# File 'lib/awshark/profile_resolver.rb', line 47 def role_credentials @shared_config.assume_role_credentials_from_config( region: region, token_code: mfa_token ) end |
#user_credentials ⇒ Object
Returns Aws credentials for configuration with
[profile]
aws_access_key_id=AWS_ACCESS_KEY_ID
aws_secret_access_key=AWS_SECRET_ACCESS_KEY
Returns nil for configuration with
[profile]
role_arn = ROLE_ARN
source_profile = SOURCE_PROFILE
29 30 31 |
# File 'lib/awshark/profile_resolver.rb', line 29 def user_credentials @shared_config.credentials end |