Class: Jets::Cfn::Resource::Config::ConfigRule

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/cfn/resource/config/config_rule.rb

Direct Known Subclasses

ManagedRule

Instance Method Summary collapse

Methods inherited from Base

#attributes, #logical_id, #outputs, #parameters, #permission, #properties, #replacements, #replacer, #standarize, #template, truncate_id, #type

Methods included from Util::Camelize

#camelize

Constructor Details

#initialize(app_class, meth, props = {}) ⇒ ConfigRule

Returns a new instance of ConfigRule.



3
4
5
6
7
# File 'lib/jets/cfn/resource/config/config_rule.rb', line 3

def initialize(app_class, meth, props={})
  @app_class = app_class.to_s
  @meth = meth
  @props = props # associated_properties from dsl.rb
end

Instance Method Details

#config_rule_logical_idObject



47
48
49
# File 'lib/jets/cfn/resource/config/config_rule.rb', line 47

def config_rule_logical_id
  "{namespace}ConfigRule"
end

#config_rule_nameObject



51
52
53
54
55
56
# File 'lib/jets/cfn/resource/config/config_rule.rb', line 51

def config_rule_name
  app_class = @app_class.underscore.gsub(/_rule$/,'')
  ns = namespace
  ns = nil if ns == false # for compact
  [ns, "#{app_class}_#{@meth}"].compact.join('_').dasherize
end

#definitionObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jets/cfn/resource/config/config_rule.rb', line 9

def definition
  base = {
    config_rule_logical_id => {
      Type: "AWS::Config::ConfigRule",
      Properties: definition_properties
    }
  }

  # Explicitly set depends_on to help with CloudFormation random race condition.
  # Seems to be a new CloudFormation and AWS Config resource issue.
  if definition_properties[:Source][:Owner] == 'CUSTOM_LAMBDA'
    base[config_rule_logical_id][:DependsOn] = "{namespace}Permission"
  end

  base
end

#definition_propertiesObject

Do not name this method properties, that is a computed method of ‘Jets::Cfn::Resource`



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jets/cfn/resource/config/config_rule.rb', line 27

def definition_properties
  {
    ConfigRuleName: config_rule_name,
    Source: {
      Owner: "CUSTOM_LAMBDA",
      SourceIdentifier: "!GetAtt {namespace}LambdaFunction.Arn",
      SourceDetails: [
        {
          EventSource: "aws.config",
          MessageType: "ConfigurationItemChangeNotification"
        },
        {
          EventSource: "aws.config",
          MessageType: "OversizedConfigurationItemChangeNotification"
        }
      ]
    },
  }.deep_merge(@props)
end

#namespaceObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/jets/cfn/resource/config/config_rule.rb', line 58

def namespace
  namespace = nil
  klass = @app_class.constantize
  while klass != Jets::Lambda::Functions
    namespace = klass.rule_namespace
    break if namespace or namespace == false
    klass = klass.superclass
  end

  if namespace.nil?
    Jets.project_namespace
  else
    namespace
  end
end