Class: CFnDK::GlobalConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/cfndk/global_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, option) ⇒ GlobalConfig

Returns a new instance of GlobalConfig.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cfndk/global_config.rb', line 4

def initialize(data, option)
  @timeout_in_minutes = 1
  @s3_template_bucket = 'cfndk-templates'
  @s3_template_hash = Uuid.instance.uuid
  @region = ENV['AWS_REGION'] || 'us-east-1'
  @package = false
  @profile = ENV['AWS_PROFILE'] || nil
  return unless data['global'].is_a?(Hash)
  @timeout_in_minutes = data['global']['timeout_in_minutes'] || 1
  @s3_template_bucket = data['global']['s3_template_bucket'] || 'cfndk-templates'
  @region = data['global']['region'] || ENV['AWS_REGION'] || 'us-east-1'
  @package = data['global']['package'] === 'true' ? true : false
  @role_arn = data['global']['role_arn'] || nil
  @profile = ENV['AWS_PROFILE'] || data['global']['default_profile'] || nil
  @pre_command = data['global']['pre_command'] || nil
  @post_command = data['global']['post_command'] || nil
end

Instance Attribute Details

#packageObject (readonly)

Returns the value of attribute package.



3
4
5
# File 'lib/cfndk/global_config.rb', line 3

def package
  @package
end

#post_commandObject (readonly)

Returns the value of attribute post_command.



3
4
5
# File 'lib/cfndk/global_config.rb', line 3

def post_command
  @post_command
end

#pre_commandObject (readonly)

Returns the value of attribute pre_command.



3
4
5
# File 'lib/cfndk/global_config.rb', line 3

def pre_command
  @pre_command
end

#profileObject (readonly)

Returns the value of attribute profile.



3
4
5
# File 'lib/cfndk/global_config.rb', line 3

def profile
  @profile
end

#regionObject (readonly)

Returns the value of attribute region.



3
4
5
# File 'lib/cfndk/global_config.rb', line 3

def region
  @region
end

#role_arnObject (readonly)

Returns the value of attribute role_arn.



3
4
5
# File 'lib/cfndk/global_config.rb', line 3

def role_arn
  @role_arn
end

#s3_template_bucketObject (readonly)

Returns the value of attribute s3_template_bucket.



3
4
5
# File 'lib/cfndk/global_config.rb', line 3

def s3_template_bucket
  @s3_template_bucket
end

#s3_template_hashObject (readonly)

Returns the value of attribute s3_template_hash.



3
4
5
# File 'lib/cfndk/global_config.rb', line 3

def s3_template_hash
  @s3_template_hash
end

#timeout_in_minutesObject (readonly)

Returns the value of attribute timeout_in_minutes.



3
4
5
# File 'lib/cfndk/global_config.rb', line 3

def timeout_in_minutes
  @timeout_in_minutes
end

Instance Method Details

#post_command_executeObject



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

def post_command_execute
  if @post_command
    CFnDK.logger.info(('execute global post command: ' + @post_command).color(:green))
    IO.popen(@post_command, :err => [:child, :out]) do |io|
      io.each_line do |line|
        CFnDK.logger.info((line).color(:green))
      end
    end
    raise 'global post command is error. status: ' + $?.exitstatus.to_s + ' command: ' + @post_command if $?.exitstatus != 0
  end
end

#pre_command_executeObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cfndk/global_config.rb', line 22

def pre_command_execute
  if @pre_command
    CFnDK.logger.info(('execute global pre command: ' + @pre_command).color(:green))
    IO.popen(@pre_command, :err => [:child, :out]) do |io|
      io.each_line do |line|
        CFnDK.logger.info((line).color(:green))
      end
    end
    raise 'global pre command is error. status: ' + $?.exitstatus.to_s + ' command: ' + @pre_command if $?.exitstatus != 0
  end
end