class AwsAssumeRole::Cli::Actions::AbstractAction
Constants
- CommandSchema
Public Class Methods
new(global_options, options, args)
click to toggle source
# File lib/aws_assume_role/cli/actions/abstract_action.rb, line 13 def initialize(global_options, options, args) config = ProfileConfiguration.new_from_cli(global_options, options, args) logger.debug "Config initialized with #{config.to_hash}" result = validate_options(config.to_hash) logger.debug "Config validated as #{result.to_hash}" result.success? ? act_on(config) : Ui.show_validation_errors(result) end
Private Instance Methods
act_on(_options)
click to toggle source
# File lib/aws_assume_role/cli/actions/abstract_action.rb, line 58 def act_on(_options) raise "Act On Not Implemented" end
prompt_for_option(key, option_name, validator, fmt: nil)
click to toggle source
# File lib/aws_assume_role/cli/actions/abstract_action.rb, line 52 def prompt_for_option(key, option_name, validator, fmt: nil) text_lookup = t("options.#{key}") text = fmt.nil? ? text_lookup : format(text_lookup, fmt) Ui.ask_with_validation(option_name, text) { instance_eval(&validator) } end
resolved_profile()
click to toggle source
# File lib/aws_assume_role/cli/actions/abstract_action.rb, line 40 def resolved_profile @provider.profile end
resolved_region()
click to toggle source
# File lib/aws_assume_role/cli/actions/abstract_action.rb, line 36 def resolved_region @provider.region end
try_for_credentials(config)
click to toggle source
# File lib/aws_assume_role/cli/actions/abstract_action.rb, line 23 def try_for_credentials(config) @provider ||= AwsAssumeRole::Credentials::Factories::DefaultChainProvider.new(config.to_hash) creds = @provider.resolve(nil_with_role_not_set: true) logger.debug "Got credentials #{creds}" return creds unless creds.nil? rescue Smartcard::PCSC::Exception error t("errors.SmartcardException") exit 403 rescue NoMethodError error t("errors.MissingCredentialsError") exit 404 end
validate_options(options)
click to toggle source
# File lib/aws_assume_role/cli/actions/abstract_action.rb, line 44 def validate_options(options) command_schema = self.class::CommandSchema ::Dry::Validation.Schema do configure { config.messages = :i18n } instance_eval(&command_schema) end.call(options) end