cfn-model 0.4.22 → 0.4.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06e74464ef87db60b2652a0dcefe8f57ce6bdc00b9b0a3d048e0ee2e8b72353e
4
- data.tar.gz: 78a2bbd49071fa15c27b084bd4840b648d29e7345188744f0a160278f89c8050
3
+ metadata.gz: 82b727cdb60f1f606204c54f5cbc7bcc730e481126d9a3815541f54add0de308
4
+ data.tar.gz: 1c1026cfdcd134576c11e4a2c11046b441fcc3e1179bc89de89c8c81b1dbe961
5
5
  SHA512:
6
- metadata.gz: 27f8ed29ff48d8d5be8bb2d0b210863f1f55fc4c19fed24b94f52380c50dcbefdf7a2c9daaab24d9abd59b7571e30107f9d82f0bfb1d12a1e1ace88859d5db7e
7
- data.tar.gz: d519c045bbd93a1f6eb931b3ae0a6e1dd85ff0bbd48f14a928d8ef99b7bab2ddb9f43e777e1797dd77533c3c94f7fb6473d762b816015030e05a50ede1d97faf
6
+ metadata.gz: 93623be9812b065eb4fdf1a7f9bdedd7942ac997d46c66fd5bc1c50a940f7ae27652984e36dec7e4d9304a0641d1341d613ded703935834ad1cf50f6eb44819e
7
+ data.tar.gz: edde0501eac183a6e9b04d5190f7e3396d4af16467b8604721331a901cbe9d6fdedd1f8c04edbda8d59d1741f0921ba06fa96f49ed5e0b4589a172e327e5c1c5
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'model_element'
4
+
5
+ class AWS::ApiGateway::Deployment < ModelElement
6
+ attr_accessor :usage_plan_ids
7
+
8
+ def initialize(cfn_model)
9
+ super
10
+ @usage_plan_ids = []
11
+ @resource_type = 'AWS::ApiGateway::Deployment'
12
+ end
13
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'parser_error'
4
+ require 'cfn-model/model/api_gateway_deployment'
5
+ require 'cfn-model/model/references'
6
+
7
+ class ApiGatewayDeploymentParser
8
+
9
+ def parse(cfn_model:, resource:)
10
+ deployment = resource
11
+
12
+ attach_usage_plan_to_api_deployment(cfn_model: cfn_model, deployment: deployment)
13
+ deployment
14
+ end
15
+
16
+ private
17
+
18
+ def attached_usage_plans(cfn_model)
19
+ usage_plans = cfn_model.resources_by_type 'AWS::ApiGateway::UsagePlan'
20
+ usage_plans.select { |usage_plan| !usage_plan.apiStages.nil? }
21
+ end
22
+
23
+ def stages_for_deployment(cfn_model, deployment)
24
+ stages = cfn_model.resources_by_type 'AWS::ApiGateway::Stage'
25
+ stages.select { |stage| stage.deploymentId ? References.resolve_resource_id(stage.deploymentId) == deployment.logical_resource_id : false }
26
+ end
27
+
28
+ def deployment_creates_stage?(deployment)
29
+ !deployment.stageName.nil?
30
+ end
31
+
32
+ def usage_plans_for_stage_by_resource_id(cfn_model, logical_resource_id)
33
+ usage_plans = attached_usage_plans(cfn_model)
34
+ usage_plans.select do |usage_plan|
35
+ stages = usage_plan.apiStages.select do |up_api_stage|
36
+ References.resolve_resource_id(up_api_stage['Stage']) == logical_resource_id
37
+ end
38
+ !stages.empty?
39
+ end
40
+ end
41
+
42
+ def usage_plans_for_stage_by_stage_name(cfn_model, stage_name)
43
+ usage_plans = attached_usage_plans(cfn_model)
44
+ usage_plans.select do |usage_plan|
45
+ stages = usage_plan.apiStages.select do |up_api_stage|
46
+ up_api_stage['Stage'] == stage_name
47
+ end
48
+ !stages.empty?
49
+ end
50
+ end
51
+
52
+ def attach_usage_plans_for_deployment_that_creates_stage(cfn_model, deployment)
53
+ usage_plans_for_stage_by_stage_name(cfn_model, deployment.stageName).each do |usage_plan|
54
+ deployment.usage_plan_ids << usage_plan.logical_resource_id
55
+ end
56
+ end
57
+
58
+ def attach_usage_plans_for_deployment_without_stage_name(cfn_model, deployment)
59
+ stages_for_deployment(cfn_model, deployment).each do |stage|
60
+ usage_plans_for_stage_by_resource_id(cfn_model, stage.logical_resource_id).each do |usage_plan|
61
+ deployment.usage_plan_ids << usage_plan.logical_resource_id
62
+ end
63
+ end
64
+ end
65
+
66
+ def attach_usage_plan_to_api_deployment(cfn_model:, deployment:)
67
+ if deployment_creates_stage?(deployment)
68
+ attach_usage_plans_for_deployment_that_creates_stage(cfn_model, deployment)
69
+ else
70
+ attach_usage_plans_for_deployment_without_stage_name(cfn_model, deployment)
71
+ end
72
+ end
73
+ end
@@ -23,6 +23,7 @@ class ParserRegistry
23
23
  'AWS::SNS::TopicPolicy' => WithPolicyDocumentParser,
24
24
  'AWS::SQS::QueuePolicy' => WithPolicyDocumentParser,
25
25
  'AWS::ApiGateway::Stage' => ApiGatewayStageParser,
26
+ 'AWS::ApiGateway::Deployment' => ApiGatewayDeploymentParser
26
27
  }
27
28
  end
28
29
 
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.22
4
+ version: 0.4.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kascic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-11 00:00:00.000000000 Z
11
+ date: 2020-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - bin/cfn_parse
63
63
  - lib/cfn-model.rb
64
+ - lib/cfn-model/model/api_gateway_deployment.rb
64
65
  - lib/cfn-model/model/api_gateway_stage.rb
65
66
  - lib/cfn-model/model/bucket_policy.rb
66
67
  - lib/cfn-model/model/cfn_model.rb
@@ -88,6 +89,7 @@ files:
88
89
  - lib/cfn-model/model/statement.rb
89
90
  - lib/cfn-model/model/topic_policy.rb
90
91
  - lib/cfn-model/monkey_patches/psych/nodes/node.rb
92
+ - lib/cfn-model/parser/api_gateway_deployment_parser.rb
91
93
  - lib/cfn-model/parser/api_gateway_stage_parser.rb
92
94
  - lib/cfn-model/parser/cfn_parser.rb
93
95
  - lib/cfn-model/parser/ec2_instance_parser.rb