Class: CfnModel

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCfnModel

Returns a new instance of CfnModel.



12
13
14
15
# File 'lib/cfn-model/model/cfn_model.rb', line 12

def initialize
  @resources = {}
  @raw_model = nil
end

Instance Attribute Details

#raw_modelObject

if you really want it, here it is - the raw Hash from YAML.load. you’ll have to mess with structural nits of CloudFormation and deal with variations between yaml/json refs and all that



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

def raw_model
  @raw_model
end

#resourcesObject (readonly)

Returns the value of attribute resources.



4
5
6
# File 'lib/cfn-model/model/cfn_model.rb', line 4

def resources
  @resources
end

Instance Method Details

#find_security_group_by_group_id(security_group_reference) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cfn-model/model/cfn_model.rb', line 43

def find_security_group_by_group_id(security_group_reference)
  security_group_id = References.resolve_security_group_id(security_group_reference)
  if security_group_id.nil?
    # leave it alone since external ref or something we don't grok
    security_group_reference
  else
    matched_security_group = security_groups.find do |security_group|
      security_group.logical_resource_id == security_group_id
    end
    if matched_security_group.nil?
      # leave it alone since external ref or something we don't grok
      security_group_reference
    else
      matched_security_group
    end
  end
end

#iam_usersObject



21
22
23
# File 'lib/cfn-model/model/cfn_model.rb', line 21

def iam_users
  resources_by_type 'AWS::IAM::User'
end

#resources_by_type(resource_type) ⇒ Object



39
40
41
# File 'lib/cfn-model/model/cfn_model.rb', line 39

def resources_by_type(resource_type)
  @resources.values.select { |resource| resource.resource_type == resource_type }
end

#security_groupsObject



17
18
19
# File 'lib/cfn-model/model/cfn_model.rb', line 17

def security_groups
  resources_by_type 'AWS::EC2::SecurityGroup'
end

#standalone_egressObject



32
33
34
35
36
37
# File 'lib/cfn-model/model/cfn_model.rb', line 32

def standalone_egress
  security_group_egresses = resources_by_type 'AWS::EC2::SecurityGroupEgress'
  security_group_egresses.select do |security_group_egress|
    References.is_security_group_id_external(security_group_egress.groupId)
  end
end

#standalone_ingressObject



25
26
27
28
29
30
# File 'lib/cfn-model/model/cfn_model.rb', line 25

def standalone_ingress
  security_group_ingresses = resources_by_type 'AWS::EC2::SecurityGroupIngress'
  security_group_ingresses.select do |security_group_ingress|
    References.is_security_group_id_external(security_group_ingress.groupId)
  end
end

#to_sObject



61
62
63
# File 'lib/cfn-model/model/cfn_model.rb', line 61

def to_s
  @resources.to_s
end