Class: CFnDK::Command

Inherits:
Thor
  • Object
show all
Includes:
ConfigFileLoadable, CredentialResolvable, Thor::Actions
Defined in:
lib/cfndk/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/cfndk/command.rb', line 8

def exit_on_failure?
  true
end

Instance Method Details

#createObject



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
# File 'lib/cfndk/command.rb', line 51

def create
  CFnDK.logger.info 'create...'.color(:green)
  data = load_config_data(options)
  credentials = resolve_credential(data, options)
  global_config = CFnDK::GlobalConfig.new(data, options)
  stacks = CFnDK::Stacks.new(data, options, credentials)
  keypairs = CFnDK::KeyPairs.new(data, options, credentials)

  global_config.pre_command_execute
  stacks.pre_command_execute
  stacks.validate
  keypairs.pre_command_execute
  keypairs.create
  keypairs.post_command_execute
  stacks.create
  stacks.post_command_execute
  global_config.post_command_execute
  return 0
rescue => e
  CFnDK.logger.error "#{e.class}: #{e.message}".color(:red)
  e.backtrace_locations.each do |line|
    CFnDK.logger.debug line
  end
  return 1
end

#destroyObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/cfndk/command.rb', line 81

def destroy
  CFnDK.logger.info 'destroy...'.color(:green)
  data = load_config_data(options)
  credentials = resolve_credential(data, options)

  stacks = CFnDK::Stacks.new(data, options, credentials)
  keypairs = CFnDK::KeyPairs.new(data, options, credentials)

  if options[:force] || yes?('Are you sure you want to destroy? (y/n)', :yellow)
    stacks.destroy
    keypairs.destroy
    return 0
  else
    CFnDK.logger.info 'destroy command was canceled'.color(:green)
    return 2
  end
rescue => e
  CFnDK.logger.error "#{e.class}: #{e.message}".color(:red)
  e.backtrace_locations.each do |line|
    CFnDK.logger.debug line
  end
  return 1
end

#generate_uuidObject



22
23
24
25
# File 'lib/cfndk/command.rb', line 22

def generate_uuid
  puts SecureRandom.uuid
  0
end

#help(command = nil, subcommand = false) ⇒ Object



13
14
15
16
# File 'lib/cfndk/command.rb', line 13

def help(command = nil, subcommand = false)
  super(command, subcommand)
  2
end

#initObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/cfndk/command.rb', line 34

def init
  config_path = "#{Dir.getwd}/cfndk.yml"
  if File.file?(config_path)
    CFnDK.logger.error "File exist. #{config_path}".color(:red)
    return 1
  end
  CFnDK.logger.info 'init...'.color(:green)
  FileUtils.cp_r(Dir.glob(File.dirname(__FILE__) + '/../../skel/*'), './')
  CFnDK.logger.info "create #{config_path}".color(:green)
end

#reportObject



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

def report
  CFnDK.logger.info 'report...'.color(:green)

  data = load_config_data(options)
  credentials = resolve_credential(data, options)

  stacks = CFnDK::Stacks.new(data, options, credentials)
  stacks.report
  return 0
rescue => e
  CFnDK.logger.error "#{e.class}: #{e.message}".color(:red)
  e.backtrace_locations.each do |line|
    CFnDK.logger.debug line
  end
  return 1
end

#versionObject



28
29
30
31
# File 'lib/cfndk/command.rb', line 28

def version
  puts CFnDK::VERSION
  0
end