Class: Jets::Cfn::Base

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Util::Camelize, Util::Logging
Defined in:
lib/jets/cfn/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::Camelize

#camelize

Methods included from Util::Logging

#log

Class Method Details

.truncate_id(id, postfix = "") ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/jets/cfn/base.rb', line 81

def truncate_id(id, postfix = "")
  # Api Gateway resource name has a limit of 64 characters.
  # Yet it throws not found when ID is longer than 62 characters and I don't know why.
  # To keep it safe, let's stick to the 62 characters limit.
  if id.size + postfix.size > 62
    "#{id[0..(55 - postfix.size)]}#{Digest::MD5.hexdigest(id)[0..5]}#{postfix}"
  else
    "#{id}#{postfix}"
  end
end

Instance Method Details

#attributesObject



51
52
53
54
55
# File 'lib/jets/cfn/base.rb', line 51

def attributes
  attributes = template.values.first
  attributes = replacer.replace_placeholders(attributes)
  camelize(attributes)
end

#configObject

interface method



76
77
78
# File 'lib/jets/cfn/base.rb', line 76

def config
  Jets.bootstrap.config
end

#logical_idObject



37
38
39
40
41
# File 'lib/jets/cfn/base.rb', line 37

def logical_id
  id = template.keys.first
  id = replacer.replace_value(id) # IE: replace possible {namespace} in the logical id
  Jets::Camelizer.camelize(id) # logical id limit is 256 chars
end

#normalize_tags(tags) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/jets/cfn/base.rb', line 65

def normalize_tags(tags)
  if tags.is_a?(Hash)
    tags.map do |k, v|
      {Key: k.to_s, Value: v.to_s}
    end
  else # Array passthrough
    tags
  end
end

#outputsObject



61
62
63
# File 'lib/jets/cfn/base.rb', line 61

def outputs
  {}
end

#parametersObject



57
58
59
# File 'lib/jets/cfn/base.rb', line 57

def parameters
  {}
end

#propertiesObject



47
48
49
# File 'lib/jets/cfn/base.rb', line 47

def properties
  attributes[:Properties]
end

#replacementsObject

interface method



18
19
20
# File 'lib/jets/cfn/base.rb', line 18

def replacements
  @replacements || {}
end

#replacerObject



22
23
24
# File 'lib/jets/cfn/base.rb', line 22

def replacer
  Resource::Replacer.new(replacements)
end

#standarize(*definition) ⇒ Object

CloudFormation Resources reference: amzn.to/2NKg6ip



33
34
35
# File 'lib/jets/cfn/base.rb', line 33

def standarize(*definition)
  Resource::Standardizer.new(definition).template
end

#templateObject



27
28
29
# File 'lib/jets/cfn/base.rb', line 27

def template
  standarize(definition)
end

#typeObject



43
44
45
# File 'lib/jets/cfn/base.rb', line 43

def type
  attributes[:Type]
end