Class: Bosh::Providers::Cli::AwsProviderCli

Inherits:
ProviderCli
  • Object
show all
Defined in:
lib/bosh/providers/cli/aws_provider_cli.rb

Overview

Interactively prompt user for region & credential information for AWS

Primary use within inception is to pass settings.provider hash run #perform to gather credentials, then export the credentials/attributes.

settings["provider"] = {}
provider = AwsProviderCli.new(settings.provider)
provider_client.perform
settings.provider = provider_cli.export_attributes

Instance Attribute Summary

Attributes inherited from ProviderCli

#attributes, #provider_client

Instance Method Summary collapse

Methods inherited from ProviderCli

#initialize

Methods included from Inception::CliHelpers::Interactions

#bold, #clear, #cyan, #green, #hl, #red, #yellow

Constructor Details

This class inherits a constructor from Bosh::Providers::Cli::ProviderCli

Instance Method Details

#aws_constantsObject



55
56
57
# File 'lib/bosh/providers/cli/aws_provider_cli.rb', line 55

def aws_constants
  Bosh::Providers::Constants::AwsConstants
end

#choose_regionObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bosh/providers/cli/aws_provider_cli.rb', line 30

def choose_region
  hl.choose do |menu|
    menu.prompt = "Choose AWS region: "
    default_menu_item = nil
    aws_constants.region_labels.each do |region_info|
      label, code = region_info[:label], region_info[:code]
      menu_item = "#{label} (#{code})"
      if code == aws_constants.default_region_code
        menu_item = "*#{menu_item}"
        default_menu_item = menu_item 
      end
      menu.choice(menu_item) do
        attributes["region"] = code
      end
    end
    menu.default = default_menu_item if default_menu_item
  end
end

#export_attributesObject

helper to export the complete nested attributes as a pure Hash



26
27
28
# File 'lib/bosh/providers/cli/aws_provider_cli.rb', line 26

def export_attributes
  attributes.to_nested_hash
end

#performObject



19
20
21
22
23
# File 'lib/bosh/providers/cli/aws_provider_cli.rb', line 19

def perform
  attributes.set("name", "aws") # ensure this property is correct
  choose_region unless attributes.exists?("region")
  setup_credentials unless attributes.exists?("credentials.aws_access_key_id")
end

#setup_credentialsObject



49
50
51
52
53
# File 'lib/bosh/providers/cli/aws_provider_cli.rb', line 49

def setup_credentials
  attributes.set_default("credentials", {})
  attributes.credentials["aws_access_key_id"] = hl.ask("Access key: ")
  attributes.credentials["aws_secret_access_key"] = hl.ask("Secret key: ")
end