Class: Ridoku::ConfigWizard

Inherits:
Object
  • Object
show all
Defined in:
lib/ridoku/config_wizard.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigWizard

Returns a new instance of ConfigWizard.



7
8
9
10
11
12
13
# File 'lib/ridoku/config_wizard.rb', line 7

def initialize
  self.fields = {
    service_role_arn: :arn_string,
    instance_profile_arn: :arn_string,
    ssh_key: :path
  }
end

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



5
6
7
# File 'lib/ridoku/config_wizard.rb', line 5

def fields
  @fields
end

Class Method Details

.fetch_input(output, required = {}, info = {}) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ridoku/config_wizard.rb', line 110

def fetch_input(output, required = {}, info = {})
  info ||= {}
  info.merge!({
    ssh_key: <<-EOF
    Key files (such as SSH keys) should be provided by file path.  In the case of
    GIT repository SSH keys (custom cookbooks, application respository), these 
    should be to the private keys.  I recommend generating keys specifically for 
    each use, so that the keys can be easily tracked and removed if necessary,
    without requiring you replace your keys on every machine you access.
    Enter 's' or 'skip' if you wish to keep the currently configured value.
    EOF
  })

  recurse_required(required, output, info)
end

.help_textObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ridoku/config_wizard.rb', line 83

def help_text
  help = <<-EOF
Configuration Wizard:

In order to get ridoku configured with your OpsWorks account, Ridoku must 
collect pertinent required info. The wizard can be run at any time after the
first with the command line option of `--wizard`.

Values to be configured:
  ssh_key: 
    Path to the SSH key to be used for git repositories
    (cook books, apps, etc).  It is recommended that this be generated
    separately from your personal SSH keys so that they can be revoked
    effecting other logins.

  service_role_arn:
    If a valid service_role_arn cannot be found, Ridoku will attempt to
    generate one for you.  If you've already used OpsWorks, Ridoku should be
    able to find the necessary Roles for you.

  instance_role_arn:
    If a valid instance_role_arn cannot be found, Ridoku will attempt to
    generate one for you.  If you've already used OpsWorks, Ridoku should be
    able to find the necessary Roles for you.
  EOF
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ridoku/config_wizard.rb', line 15

def run
  $stdout.puts $stdout.colorize(ConfigWizard.help_text, :bold)

  $stdout.puts "Do you wish to run the wizard now? [#{$stdout.colorize('Y', :bold)}|n]"
  res = $stdin.gets
  if res.match(%r(^[Nn]))
    Base.config[:local_init] = true
    Base.save_config(::RUNCOM)
    exit 1
  end

  sra_info = <<-EOF
Service Role ARN is used to access OpsWorks and issue commands on your
behalf.  No suitable role was found.

Please enter the appropriate Role used to issue commands on OpsWorks.
Leave the field blank to attempt to generate one or to refresh from account
credentials. 's' or 'skip' if you wish to use existing values.

#{$stdout.colorize('Current Service ARN:', [:white, :bold])} #{$stdout.colorize(Base.config[:service_arn], :green)}
EOF
  inst_info = <<-EOF
Instance Profile ARN is used to for each instance created for OpsWorks.

Please enter the appropriate default Role used for instance profiles.
Leave the field blank to attempt to generate one or to refresh from account
credentials. 's' or 'skip' if you wish to use existing values.

#{$stdout.colorize('Current Instance ARN:', [:white, :bold])} #{$stdout.colorize(Base.config[:instance_arn], :green)}
EOF
  info = {
    service_role_arn: sra_info,
    instance_profile_arn: inst_info
  }

  ConfigWizard.fetch_input(Base.config, fields, info)

  case Base.config[:service_role_arn]
  when ''
    Base.config.delete(:service_arn)
    Base.configure_service_roles
  when 's', 'skip'
  else
    Base.config[:service_arn] = Base.config[:service_role_arn]
  end

  case Base.config[:instance_profile_arn]
  when ''
    Base.config.delete(:instance_arn)
    Base.configure_instance_roles
  when 's', 'skip'
  else
    Base.config[:instance_arn] = Base.config[:instance_profile_arn]
  end

  Base.config[:local_init] = true
  Base.save_config(::RUNCOM)

  $stdout.puts 'Updating required Security Groups'
  Base.update_pg_security_groups_in_all_regions

  $stdout.puts 'Configuration complete.'
  exit 0
end