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
-
#line_numbers ⇒ Object
readonly
Returns the value of attribute line_numbers.
-
#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.
- #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 |
# File 'lib/cfn-model/model/cfn_model.rb', line 14 def initialize @parameters = {} @resources = {} @raw_model = nil @line_numbers = {} end |
Instance Attribute Details
#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 |
#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
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cfn-model/model/cfn_model.rb', line 25 def copy new_cfn_model = CfnModel.new @parameters.each do |k,v| new_cfn_model.parameters[k] = v end @resources.each do |k, v| new_cfn_model.resources[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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cfn-model/model/cfn_model.rb', line 63 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
41 42 43 |
# File 'lib/cfn-model/model/cfn_model.rb', line 41 def iam_users resources_by_type 'AWS::IAM::User' end |
#resources_by_type(resource_type) ⇒ Object
59 60 61 |
# File 'lib/cfn-model/model/cfn_model.rb', line 59 def resources_by_type(resource_type) @resources.values.select { |resource| resource.resource_type == resource_type } end |
#security_groups ⇒ Object
37 38 39 |
# File 'lib/cfn-model/model/cfn_model.rb', line 37 def security_groups resources_by_type 'AWS::EC2::SecurityGroup' end |
#standalone_egress ⇒ Object
52 53 54 55 56 57 |
# File 'lib/cfn-model/model/cfn_model.rb', line 52 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
45 46 47 48 49 50 |
# File 'lib/cfn-model/model/cfn_model.rb', line 45 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
81 82 83 |
# File 'lib/cfn-model/model/cfn_model.rb', line 81 def to_s @resources.to_s end |