Class: CFnDK::Command

Inherits:
Thor
  • Object
show all
Includes:
ConfigFileLoadable, 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)


6
7
8
# File 'lib/cfndk/command.rb', line 6

def exit_on_failure?
  true
end

Instance Method Details

#createObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cfndk/command.rb', line 49

def create
  CFnDK.logger.info 'create...'.color(:green)
  data = load_config_data(options)

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

  stacks.validate
  keypairs.create
  stacks.create
  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



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/cfndk/command.rb', line 73

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

  credentials = CFnDK::CredentialProviderChain.new.resolve
  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



20
21
22
23
# File 'lib/cfndk/command.rb', line 20

def generate_uuid
  puts SecureRandom.uuid
  0
end

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



11
12
13
14
# File 'lib/cfndk/command.rb', line 11

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

#initObject



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

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



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/cfndk/command.rb', line 102

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

  data = load_config_data(options)

  credentials = CFnDK::CredentialProviderChain.new.resolve
  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



26
27
28
29
# File 'lib/cfndk/command.rb', line 26

def version
  puts CFnDK::VERSION
  0
end