Class: CfnModel
- Inherits:
-
Object
- Object
- CfnModel
- Defined in:
- lib/cfn-model/model/cfn_model.rb,
lib/cfn-model/transforms/serverless.rb,
lib/cfn-model/parser/transform_registry.rb,
lib/cfn-model/parser/transform_registry.rb
Defined Under Namespace
Classes: TransformRegistry, Transforms
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#globals ⇒ Object
readonly
Returns the value of attribute globals.
-
#line_numbers ⇒ Object
readonly
Returns the value of attribute line_numbers.
-
#mappings ⇒ Object
readonly
Returns the value of attribute mappings.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#raw_model ⇒ Object
if you really want it, here it is - the raw Hash from YAML.load.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
-
#copy ⇒ Object
A new instance of CfnModel with a copy of the raw_model and and resources.
- #find_security_group_by_group_id(security_group_reference) ⇒ Object
- #iam_users ⇒ Object
-
#initialize ⇒ CfnModel
constructor
A new instance of CfnModel.
- #resource_by_id(resource_id) ⇒ Object
- #resource_by_ref(reference, attr = nil) ⇒ Object
- #resources_by_type(resource_type) ⇒ Object
- #security_groups ⇒ Object
- #standalone_egress ⇒ Object
- #standalone_ingress ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ CfnModel
Returns a new instance of CfnModel.
14 15 16 17 18 19 20 21 22 |
# File 'lib/cfn-model/model/cfn_model.rb', line 14 def initialize @parameters = {} @resources = {} @conditions = {} @globals = {} @mappings = {} @raw_model = nil @line_numbers = {} end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
6 7 8 |
# File 'lib/cfn-model/model/cfn_model.rb', line 6 def conditions @conditions end |
#globals ⇒ Object (readonly)
Returns the value of attribute globals.
6 7 8 |
# File 'lib/cfn-model/model/cfn_model.rb', line 6 def globals @globals end |
#line_numbers ⇒ Object (readonly)
Returns the value of attribute line_numbers.
6 7 8 |
# File 'lib/cfn-model/model/cfn_model.rb', line 6 def line_numbers @line_numbers end |
#mappings ⇒ Object (readonly)
Returns the value of attribute mappings.
6 7 8 |
# File 'lib/cfn-model/model/cfn_model.rb', line 6 def mappings @mappings end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
6 7 8 |
# File 'lib/cfn-model/model/cfn_model.rb', line 6 def parameters @parameters end |
#raw_model ⇒ Object
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
12 13 14 |
# File 'lib/cfn-model/model/cfn_model.rb', line 12 def raw_model @raw_model end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
6 7 8 |
# File 'lib/cfn-model/model/cfn_model.rb', line 6 def resources @resources end |
Instance Method Details
#copy ⇒ Object
A new instance of CfnModel with a copy of the raw_model and and resources. The resource objects themselves aren’t cloned but the Hash is a clone
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cfn-model/model/cfn_model.rb', line 28 def copy new_cfn_model = CfnModel.new @conditions.each do |k,v| new_cfn_model.conditions[k] = v end @globals.each do |k,v| new_cfn_model.globals[k] = v end @parameters.each do |k,v| new_cfn_model.parameters[k] = v end @resources.each do |k, v| new_cfn_model.resources[k] = v end @mappings.each do |k, v| new_cfn_model.mappings[k] = v end new_cfn_model.raw_model = @raw_model.dup unless @raw_model.nil? new_cfn_model end |
#find_security_group_by_group_id(security_group_reference) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/cfn-model/model/cfn_model.rb', line 92 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_users ⇒ Object
53 54 55 |
# File 'lib/cfn-model/model/cfn_model.rb', line 53 def iam_users resources_by_type 'AWS::IAM::User' end |
#resource_by_id(resource_id) ⇒ Object
71 72 73 |
# File 'lib/cfn-model/model/cfn_model.rb', line 71 def resource_by_id(resource_id) @resources.values.find { |resource| resource.logical_resource_id == resource_id } end |
#resource_by_ref(reference, attr = nil) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cfn-model/model/cfn_model.rb', line 79 def resource_by_ref(reference, attr = nil) # If reference is a String, look for a matching object as is (best effort) # Although, the caller could just use resource_by_id on this value, since it # would be the logical_resource_id. logical_resource_id = reference if reference.is_a? String # Otherwise, obtain logical_resource_id from References class logical_resource_id ||= References.resolve_resource_id reference, attr # Search resources for a matching ID resource_by_id logical_resource_id end |
#resources_by_type(resource_type) ⇒ Object
75 76 77 |
# File 'lib/cfn-model/model/cfn_model.rb', line 75 def resources_by_type(resource_type) @resources.values.select { |resource| resource.resource_type == resource_type } end |
#security_groups ⇒ Object
49 50 51 |
# File 'lib/cfn-model/model/cfn_model.rb', line 49 def security_groups resources_by_type 'AWS::EC2::SecurityGroup' end |
#standalone_egress ⇒ Object
64 65 66 67 68 69 |
# File 'lib/cfn-model/model/cfn_model.rb', line 64 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_ingress ⇒ Object
57 58 59 60 61 62 |
# File 'lib/cfn-model/model/cfn_model.rb', line 57 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_s ⇒ Object
110 111 112 |
# File 'lib/cfn-model/model/cfn_model.rb', line 110 def to_s @resources.to_s end |