From 683d53852a690305d39db56147ecca39c47ddf26 Mon Sep 17 00:00:00 2001 From: Bennie Mosher Date: Mon, 25 Oct 2021 14:45:28 -0600 Subject: [PATCH] BAM: Added line numbers for Parameters (#95) * BAM: Added line numbers and logical resource id to Parameters * Add specs --- lib/cfn-model/parser/cfn_parser.rb | 2 ++ spec/parser/cfn_parser_line_numbers_spec.rb | 9 +++++---- .../iam_user_with_literal_username_and_addition.yml | 4 ++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/cfn-model/parser/cfn_parser.rb b/lib/cfn-model/parser/cfn_parser.rb index a172872..d1dd081 100644 --- a/lib/cfn-model/parser/cfn_parser.rb +++ b/lib/cfn-model/parser/cfn_parser.rb @@ -184,6 +184,7 @@ def transform_hash_into_parameters(cfn_hash, cfn_model) parameter = Parameter.new parameter.id = parameter_name parameter.type = parameter_hash['Type'] + parameter.logical_resource_id = parameter_name parameter_hash.each do |property_name, property_value| next if %w(Type).include? property_name @@ -191,6 +192,7 @@ def transform_hash_into_parameters(cfn_hash, cfn_model) end cfn_model.parameters[parameter_name] = parameter + cfn_model.line_numbers[parameter_name] = parameter_hash['Type']['line'] end cfn_model end diff --git a/spec/parser/cfn_parser_line_numbers_spec.rb b/spec/parser/cfn_parser_line_numbers_spec.rb index 3522f9e..4104517 100644 --- a/spec/parser/cfn_parser_line_numbers_spec.rb +++ b/spec/parser/cfn_parser_line_numbers_spec.rb @@ -11,10 +11,11 @@ cloudformation_template_yml = IO.read(yaml_test_templates('iam_user/iam_user_with_literal_username_and_addition').first) actual_cfn_model = @cfn_parser.parse cloudformation_template_yml, nil, true expected_line_numbers = { - "iamUserWithAddition" => 4, - "groupA" => 9, - "addition1" => 14, - "addition2" => 24 + "AccessKey" => 4, + "iamUserWithAddition" => 8, + "groupA" => 13, + "addition1" => 18, + "addition2" => 28 } expect(actual_cfn_model.line_numbers).to eq expected_line_numbers end diff --git a/spec/test_templates/yaml/iam_user/iam_user_with_literal_username_and_addition.yml b/spec/test_templates/yaml/iam_user/iam_user_with_literal_username_and_addition.yml index e379423..2183a5d 100644 --- a/spec/test_templates/yaml/iam_user/iam_user_with_literal_username_and_addition.yml +++ b/spec/test_templates/yaml/iam_user/iam_user_with_literal_username_and_addition.yml @@ -1,4 +1,8 @@ --- +Parameters: + AccessKey: + Type: String + Resources: iamUserWithAddition: Type: "AWS::IAM::User"