cfn-model 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cfn-model.rb +2 -0
  3. data/lib/cfn-model/model/bucket_policy.rb +1 -0
  4. data/lib/cfn-model/model/cfn_model.rb +2 -0
  5. data/lib/cfn-model/model/ec2_instance.rb +2 -0
  6. data/lib/cfn-model/model/ec2_network_interface.rb +2 -0
  7. data/lib/cfn-model/model/iam_group.rb +2 -0
  8. data/lib/cfn-model/model/iam_managed_policy.rb +2 -0
  9. data/lib/cfn-model/model/iam_policy.rb +2 -0
  10. data/lib/cfn-model/model/iam_role.rb +2 -0
  11. data/lib/cfn-model/model/iam_user.rb +2 -0
  12. data/lib/cfn-model/model/lambda_principal.rb +2 -0
  13. data/lib/cfn-model/model/load_balancer.rb +2 -0
  14. data/lib/cfn-model/model/model_element.rb +2 -0
  15. data/lib/cfn-model/model/parameter.rb +2 -0
  16. data/lib/cfn-model/model/policy.rb +2 -0
  17. data/lib/cfn-model/model/policy_document.rb +2 -0
  18. data/lib/cfn-model/model/principal.rb +2 -0
  19. data/lib/cfn-model/model/queue_policy.rb +2 -0
  20. data/lib/cfn-model/model/references.rb +1 -0
  21. data/lib/cfn-model/model/security_group.rb +2 -0
  22. data/lib/cfn-model/model/security_group_egress.rb +2 -0
  23. data/lib/cfn-model/model/security_group_ingress.rb +2 -0
  24. data/lib/cfn-model/model/statement.rb +2 -0
  25. data/lib/cfn-model/model/topic_policy.rb +2 -0
  26. data/lib/cfn-model/monkey_patches/psych/nodes/node.rb +2 -0
  27. data/lib/cfn-model/parser/cfn_parser.rb +4 -1
  28. data/lib/cfn-model/parser/ec2_instance_parser.rb +2 -0
  29. data/lib/cfn-model/parser/ec2_network_interface_parser.rb +2 -0
  30. data/lib/cfn-model/parser/iam_group_parser.rb +2 -0
  31. data/lib/cfn-model/parser/iam_role_parser.rb +2 -0
  32. data/lib/cfn-model/parser/iam_user_parser.rb +2 -0
  33. data/lib/cfn-model/parser/load_balancer_parser.rb +2 -0
  34. data/lib/cfn-model/parser/load_balancer_v2_parser.rb +2 -0
  35. data/lib/cfn-model/parser/parameter_substitution.rb +2 -0
  36. data/lib/cfn-model/parser/parser_error.rb +2 -0
  37. data/lib/cfn-model/parser/parser_registry.rb +2 -0
  38. data/lib/cfn-model/parser/policy_document_parser.rb +2 -0
  39. data/lib/cfn-model/parser/security_group_parser.rb +4 -2
  40. data/lib/cfn-model/parser/transform_registry.rb +2 -0
  41. data/lib/cfn-model/parser/with_policy_document_parser.rb +2 -0
  42. data/lib/cfn-model/psych/handlers/line_number_handler.rb +2 -0
  43. data/lib/cfn-model/psych/visitors/to_ruby_with_line_numbers.rb +3 -1
  44. data/lib/cfn-model/transforms/serverless.rb +2 -0
  45. data/lib/cfn-model/validator/cloudformation_validator.rb +5 -3
  46. data/lib/cfn-model/validator/reference_validator.rb +2 -0
  47. data/lib/cfn-model/validator/resource_type_validator.rb +4 -2
  48. data/lib/cfn-model/validator/schema_generator.rb +8 -6
  49. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68a4e445da9675875b5414f73501cb35a9f903ea89ce5f18013b45aed9fd0ecc
4
- data.tar.gz: e2b3ec103eb8a3666e82a6e7a53c15582637c855bfaf2d7051a37c8d7ab7bad1
3
+ metadata.gz: e39e1e4457d48accfce980b48675a4c4621e2a4c53361ed04585ce3daa552d7e
4
+ data.tar.gz: 67b896b4f06c5098b35967a0b4ec08d0561f7e9c9fd8ac42cf6cc5b93db6f4e7
5
5
  SHA512:
6
- metadata.gz: d0b0ffdee38353e30698e759d5c83e695b942eb1bf9f6691a5ae6669eaabaea42432ea01d33a0cecbf07282b78ef4012cbfa21e41519ed45fbd634c3b680bf49
7
- data.tar.gz: 8aef73ceda3ab93de719dcdc840b83524e099f16949c54637835d4595ebb2351487a63cf4b8e4bf1913c335038079ce9ae6e29a23341b2f11106b31fcf758b27
6
+ metadata.gz: 8acf757dd507bd6e02e029975b1eabc2f24d1bd9cc78754d3e8dc823cb159fdb6a76d795b1db935aa6ceccee71955abbda11727936c6c4a9f820de7131627a28
7
+ data.tar.gz: 44d4ae7825f11a8e1bb09d37c340f7d8a29bdd5ee85729356dd912b847b6118a2d7c7e56a81f2baa72e1816b1ad71a79bf453e8456750d2c96828b96e082a501
data/lib/cfn-model.rb CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cfn-model/parser/cfn_parser'
2
4
  require 'cfn-model/model/cfn_model'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'model_element'
2
3
 
3
4
  class AWS::S3::BucketPolicy < ModelElement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'references'
2
4
 
3
5
  class CfnModel
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  class AWS::EC2::Instance < ModelElement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  class AWS::EC2::NetworkInterface < ModelElement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  class AWS::IAM::Group < ModelElement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  class AWS::IAM::ManagedPolicy < ModelElement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  class AWS::IAM::Policy < ModelElement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  class AWS::IAM::Role < ModelElement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  class AWS::IAM::User < ModelElement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class LambdaPrincipal
2
4
  def self.wildcard?(principal)
3
5
  if principal.is_a? String
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  class AWS::ElasticLoadBalancing::LoadBalancer < ModelElement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'references'
2
4
 
3
5
  module AWS
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #copy-paste alert with ModelElement which should instead be Resource anyway
2
4
  class Parameter
3
5
  attr_accessor :id, :type
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  class Policy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'statement'
2
4
 
3
5
  class PolicyDocument
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Principal
2
4
  def self.wildcard?(principal)
3
5
  if principal.is_a? String
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  class AWS::SQS::QueuePolicy < ModelElement
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  ##
3
4
  # this is a placeholder for anything related to resolving references
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  class AWS::EC2::SecurityGroup < ModelElement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  # this could have been inline or freestanding
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  # this could have been inline or freestanding
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'principal'
2
4
 
3
5
  class Statement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'model_element'
2
4
 
3
5
  class AWS::SNS::TopicPolicy < ModelElement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Psych's first step is to parse the Yaml into an AST of Node objects
2
4
  # so we open the Node class and add a way to track the line.
3
5
  class Psych::Nodes::Node
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'psych'
3
5
  require 'json'
@@ -142,7 +144,7 @@ class CfnParser
142
144
  end
143
145
 
144
146
  def transform_hash_into_parameters(cfn_hash, cfn_model)
145
- return cfn_model unless cfn_hash.has_key?('Parameters')
147
+ return cfn_model unless cfn_hash.key?('Parameters')
146
148
 
147
149
  cfn_hash['Parameters'].each do |parameter_name, parameter_hash|
148
150
  parameter = Parameter.new
@@ -176,6 +178,7 @@ class CfnParser
176
178
  def assign_fields_based_upon_properties(resource_object, resource)
177
179
  unless resource['Properties'].nil?
178
180
  resource['Properties'].each do |property_name, property_value|
181
+ next if %w(Fn::Transform).include? property_name
179
182
  resource_object.send("#{map_property_name_to_attribute(property_name)}=", property_value)
180
183
  end
181
184
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Parser for EC2 instances
2
4
  class Ec2InstanceParser
3
5
  def parse(cfn_model:, resource:)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Ec2NetworkInterfaceParser
2
4
  def parse(cfn_model:, resource:)
3
5
  network_interface = resource
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cfn-model/model/iam_role'
2
4
  require 'cfn-model/model/policy'
3
5
  require_relative 'policy_document_parser'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cfn-model/model/iam_role'
2
4
  require 'cfn-model/model/policy'
3
5
  require_relative 'policy_document_parser'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cfn-model/model/policy_document'
2
4
  require 'cfn-model/model/policy'
3
5
  require_relative 'policy_document_parser'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class LoadBalancerParser
2
4
  def parse(cfn_model:, resource:)
3
5
  load_balancer = resource
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class LoadBalancerV2Parser
2
4
  def parse(cfn_model:, resource:)
3
5
  load_balancer = resource
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
 
3
5
  class ParameterSubstitution
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ParserError < RuntimeError
2
4
  attr_accessor :errors
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dir["#{__dir__}/*_parser.rb"].each { |model| require "cfn-model/parser/#{File.basename(model, '.rb')}" }
2
4
 
3
5
  class ParserRegistry
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cfn-model/model/iam_policy'
2
4
  require 'cfn-model/model/policy_document'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'parser_error'
2
4
  require 'cfn-model/model/security_group_egress'
3
5
  require 'cfn-model/model/security_group_ingress'
@@ -34,7 +36,7 @@ class SecurityGroupParser
34
36
  security_group.ingresses = security_group.securityGroupIngress.map do |ingress|
35
37
  mapped_at_least_one_attribute = false
36
38
  ingress_object = AWS::EC2::SecurityGroupIngress.new cfn_model
37
- ingress.each do |k,v|
39
+ ingress.each do |k, v|
38
40
  silently_fail do
39
41
  ingress_object.send("#{initialLower(k)}=", v)
40
42
  mapped_at_least_one_attribute = true
@@ -54,7 +56,7 @@ class SecurityGroupParser
54
56
  mapped_at_least_one_attribute = false
55
57
 
56
58
  egress_object = AWS::EC2::SecurityGroupEgress.new cfn_model
57
- egress.each do |k,v|
59
+ egress.each do |k, v|
58
60
  next if k.match /::/
59
61
  silently_fail do
60
62
  egress_object.send("#{initialLower(k)}=", v)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dir["#{__dir__}/../transforms/*.rb"].each do |transform|
2
4
  require "cfn-model/transforms/#{File.basename(transform, '.rb')}"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cfn-model/model/iam_policy'
2
4
  require 'cfn-model/model/policy_document'
3
5
  require_relative 'policy_document_parser'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # We need to provide a handler that will add the line to the node
2
4
  # as it is parsed. TreeBuilder is the "usual" handler, that
3
5
  # creates the AST.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ToRubyWithLineNumbers < Psych::Visitors::ToRuby
2
4
  def revive_hash hash, o
3
5
  o.children.each_slice(2) { |k,v|
@@ -10,7 +12,7 @@ class ToRubyWithLineNumbers < Psych::Visitors::ToRuby
10
12
  # This is the important bit. If the value is a scalar,
11
13
  # we replace it with the desired hash.
12
14
  if v.is_a?(::Psych::Nodes::Scalar) && key == 'Type'
13
- val = { "value" => val, "line" => line}
15
+ val = { "value" => val, "line" => line }
14
16
  end
15
17
 
16
18
  hash[key] = val
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CfnModel
2
4
  class Transforms
3
5
  # Handle transformation of model elements performed by the
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'schema_generator'
2
4
  require 'kwalify'
3
5
  require 'json'
@@ -10,7 +12,7 @@ class CloudFormationValidator
10
12
 
11
13
  schema = SchemaGenerator.new.generate cloudformation_string
12
14
  validator = Kwalify::Validator.new(schema)
13
- validator.validate(YAML.load(cloudformation_string))
15
+ validator.validate(YAML.safe_load(cloudformation_string))
14
16
  end
15
17
 
16
18
  private
@@ -23,8 +25,8 @@ class CloudFormationValidator
23
25
 
24
26
  def valid_json?(cloudformation_string)
25
27
  JSON.parse(cloudformation_string)
26
- return true
28
+ true
27
29
  rescue JSON::ParserError => error
28
- return false
30
+ false
29
31
  end
30
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
 
3
5
  class ReferenceValidator
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cfn-model/parser/parser_error'
2
4
 
3
5
  class ResourceTypeValidator
4
6
 
5
7
  def self.validate(cloudformation_yml)
6
- hash = YAML.load cloudformation_yml
8
+ hash = YAML.safe_load cloudformation_yml
7
9
  if hash == false || hash.nil?
8
10
  raise ParserError.new 'yml empty'
9
11
  end
@@ -31,4 +33,4 @@ class ResourceTypeValidator
31
33
 
32
34
  hash
33
35
  end
34
- end
36
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'resource_type_validator'
2
4
  require 'yaml'
3
5
 
@@ -17,7 +19,7 @@ class SchemaGenerator
17
19
  parameters_schema = generate_schema_for_parameter_keys cloudformation_hash
18
20
  resources_schema = generate_schema_for_resource_keys cloudformation_hash
19
21
 
20
- main_schema = YAML.load IO.read(schema_file('schema.yml.erb'))
22
+ main_schema = YAML.safe_load IO.read(schema_file('schema.yml.erb'))
21
23
  if parameters_schema.empty?
22
24
  main_schema['mapping'].delete 'Parameters'
23
25
  else
@@ -37,10 +39,10 @@ class SchemaGenerator
37
39
  return {} if cloudformation_hash['Parameters'].nil?
38
40
 
39
41
  parameters_schema = {
40
- '=' => { 'type' => 'any'}
42
+ '=' => { 'type' => 'any' }
41
43
  }
42
44
 
43
- cloudformation_hash['Parameters'].each do |parameter_key, parameter|
45
+ cloudformation_hash['Parameters'].each do |parameter_key, _|
44
46
  parameters_schema[parameter_key] = {
45
47
  'type' => 'map',
46
48
  'mapping' => {
@@ -58,7 +60,7 @@ class SchemaGenerator
58
60
 
59
61
  def generate_schema_for_resource_keys(cloudformation_hash)
60
62
  resources_schema = {
61
- '=' => { 'type' => 'any'}
63
+ '=' => { 'type' => 'any' }
62
64
  }
63
65
 
64
66
  cloudformation_hash['Resources'].each do |resource_id, resource|
@@ -80,7 +82,7 @@ class SchemaGenerator
80
82
  if !File.exist? schema_file_path
81
83
  nil
82
84
  else
83
- YAML.load IO.read(schema_file_path)
85
+ YAML.safe_load IO.read(schema_file_path)
84
86
  end
85
87
  end
86
- end
88
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfn-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kascic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-16 00:00:00.000000000 Z
11
+ date: 2019-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop