Class: CfnModel

Inherits:
Object
  • Object
show all
Defined in:
lib/model/cfn_model.rb

Overview

consider a canonical form for template too… always transform optional things into more general forms.… although referencing violations becomes tricky then (a la c preprocessor)

Instance Method Summary collapse

Constructor Details

#initializeCfnModel

Returns a new instance of CfnModel.



9
10
11
12
# File 'lib/model/cfn_model.rb', line 9

def initialize
  @dangling_ingress_or_egress_rules = []
  @dangler = Object.new
end

Instance Method Details

#bucket_policiesObject



43
44
45
46
# File 'lib/model/cfn_model.rb', line 43

def bucket_policies
  bucket_policy_hash = resources_by_type('AWS::S3::BucketPolicy')
  bucket_policy_hash.values
end

#dangling_ingress_or_egress_rulesObject



31
32
33
34
# File 'lib/model/cfn_model.rb', line 31

def dangling_ingress_or_egress_rules
  fail 'must call parse first' unless @json_hash
  @dangling_ingress_or_egress_rules
end

#iam_usersObject



36
37
38
39
40
41
# File 'lib/model/cfn_model.rb', line 36

def iam_users
  fail 'must call parse first' unless @json_hash
  iam_users_hash = resources_by_type('AWS::IAM::User')
  wire_user_to_group_additions_to_users(iam_users_hash)
  iam_users_hash.values
end

#parametersObject



19
20
21
# File 'lib/model/cfn_model.rb', line 19

def parameters
  @json_hash['Parameters']
end

#parse(cfn_json_string) ⇒ Object



14
15
16
17
# File 'lib/model/cfn_model.rb', line 14

def parse(cfn_json_string)
  @json_hash = JSON.load cfn_json_string
  self
end

#resources_by_type(resource_type) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/model/cfn_model.rb', line 48

def resources_by_type(resource_type)
  resources_map = {}
  resources.each do |resource_name, resource|
    if resource['Type'] == resource_type
      resource_parser = ParserRegistry.instance.registry[resource_type].new
      resources_map[resource_name] = resource_parser.parse(resource_name, resource)
    end
  end
  resources_map
end

#security_groupsObject



23
24
25
26
27
28
29
# File 'lib/model/cfn_model.rb', line 23

def security_groups
  fail 'must call parse first' unless @json_hash
  security_groups_hash = resources_by_type('AWS::EC2::SecurityGroup')
  wire_ingress_rules_to_security_groups(security_groups_hash)
  wire_egress_rules_to_security_groups(security_groups_hash)
  security_groups_hash.values
end