kumogata-template 0.0.35 → 0.0.36

Sign up to get free protection for your applications and to get access to all the features.
Files changed (278) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +4 -2
  3. data/Gemfile +1 -1
  4. data/Rakefile +1 -1
  5. data/kumogata-template.gemspec +4 -4
  6. data/lib/kumogata/template/alb.rb +48 -34
  7. data/lib/kumogata/template/api-gateway.rb +262 -0
  8. data/lib/kumogata/template/autoscaling.rb +17 -44
  9. data/lib/kumogata/template/certificate.rb +11 -8
  10. data/lib/kumogata/template/cloudfront.rb +67 -60
  11. data/lib/kumogata/template/cloudwatch.rb +7 -12
  12. data/lib/kumogata/template/codebuild.rb +4 -8
  13. data/lib/kumogata/template/codecommit.rb +2 -6
  14. data/lib/kumogata/template/codedeploy.rb +15 -0
  15. data/lib/kumogata/template/cognito.rb +203 -0
  16. data/lib/kumogata/template/const.rb +109 -47
  17. data/lib/kumogata/template/datapipeline.rb +16 -47
  18. data/lib/kumogata/template/dynamodb.rb +17 -8
  19. data/lib/kumogata/template/ec2.rb +61 -10
  20. data/lib/kumogata/template/ecr.rb +11 -9
  21. data/lib/kumogata/template/ecs.rb +256 -91
  22. data/lib/kumogata/template/elasticbeanstalk.rb +6 -9
  23. data/lib/kumogata/template/elb.rb +9 -24
  24. data/lib/kumogata/template/emr.rb +184 -51
  25. data/lib/kumogata/template/events.rb +22 -10
  26. data/lib/kumogata/template/ext/kumogata.rb +7 -7
  27. data/lib/kumogata/template/helper.rb +189 -130
  28. data/lib/kumogata/template/iam.rb +556 -146
  29. data/lib/kumogata/template/kinesis.rb +282 -0
  30. data/lib/kumogata/template/lambda.rb +43 -2
  31. data/lib/kumogata/template/logs.rb +2 -6
  32. data/lib/kumogata/template/nlb.rb +10 -0
  33. data/lib/kumogata/template/pinpoint.rb +83 -0
  34. data/lib/kumogata/template/rds.rb +52 -0
  35. data/lib/kumogata/template/redshift.rb +15 -6
  36. data/lib/kumogata/template/role.rb +425 -0
  37. data/lib/kumogata/template/s3.rb +120 -80
  38. data/lib/kumogata/template/sns.rb +2 -6
  39. data/lib/kumogata/template/version.rb +1 -1
  40. data/lib/kumogata/template.rb +9 -1
  41. data/template/_template.rb +2 -2
  42. data/template/alb-load-balancer.rb +5 -4
  43. data/template/alb-target-group.rb +8 -9
  44. data/template/api-gateway-account.rb +15 -0
  45. data/template/api-gateway-api-key.rb +22 -0
  46. data/template/api-gateway-authorizer.rb +38 -0
  47. data/template/api-gateway-base-path-mapping.rb +23 -0
  48. data/template/api-gateway-client-certificate.rb +16 -0
  49. data/template/api-gateway-deployment.rb +24 -0
  50. data/template/api-gateway-domain-name.rb +17 -0
  51. data/template/api-gateway-method.rb +71 -0
  52. data/template/api-gateway-model.rb +23 -0
  53. data/template/api-gateway-resource.rb +32 -0
  54. data/template/api-gateway-rest-api.rb +29 -0
  55. data/template/api-gateway-stage.rb +33 -0
  56. data/template/api-gateway-usage-plan-key.rb +19 -0
  57. data/template/api-gateway-usage-plan.rb +24 -0
  58. data/template/autoscaling-group.rb +2 -2
  59. data/template/autoscaling-launch-configuration.rb +7 -4
  60. data/template/autoscaling-scheduled-action.rb +0 -1
  61. data/template/certificate.rb +2 -2
  62. data/template/cloudfront-distribution.rb +4 -0
  63. data/template/cloudfront-origin-access-identity.rb +19 -0
  64. data/template/cloudtrail.rb +6 -4
  65. data/template/cloudwatch-alarm.rb +9 -3
  66. data/template/codebuild-project.rb +3 -3
  67. data/template/codecommit-repository.rb +2 -2
  68. data/template/codedeploy-application.rb +1 -1
  69. data/template/codedeploy-deployment-config.rb +1 -1
  70. data/template/codedeploy-deployment-group.rb +2 -0
  71. data/template/cognito-identity-pool.rb +34 -0
  72. data/template/cognito-identity-role-attachment.rb +22 -0
  73. data/template/cognito-user-pool-client.rb +28 -0
  74. data/template/cognito-user-pool-group.rb +24 -0
  75. data/template/cognito-user-pool-user-to-group-attachment.rb +20 -0
  76. data/template/cognito-user-pool-user.rb +28 -0
  77. data/template/cognito-user-pool.rb +45 -0
  78. data/template/datapipeline-pipeline.rb +4 -4
  79. data/template/dynamodb-table.rb +5 -1
  80. data/template/ec2-eip-association.rb +1 -1
  81. data/template/ec2-instance.rb +4 -1
  82. data/template/ec2-nat-gateway.rb +4 -0
  83. data/template/ec2-route.rb +4 -0
  84. data/template/ec2-security-group-ingress.rb +1 -1
  85. data/template/ec2-security-group.rb +2 -2
  86. data/template/ec2-subnet.rb +8 -4
  87. data/template/ec2-volume.rb +1 -2
  88. data/template/ec2-vpc-cidr-block.rb +4 -2
  89. data/template/ec2-vpc-endpoint.rb +5 -2
  90. data/template/ecr-repository.rb +2 -2
  91. data/template/ecs-cluster.rb +1 -1
  92. data/template/ecs-service.rb +19 -7
  93. data/template/ecs-task-definition.rb +4 -4
  94. data/template/elasticache-cache-cluster.rb +1 -1
  95. data/template/elasticache-parameter-group.rb +1 -1
  96. data/template/elasticache-replication-group.rb +1 -1
  97. data/template/elasticache-subnet-group.rb +1 -1
  98. data/template/elasticbeanstalk-application-version.rb +1 -1
  99. data/template/elasticbeanstalk-application.rb +1 -1
  100. data/template/elasticbeanstalk-configuration-template.rb +1 -1
  101. data/template/elasticbeanstalk-environment.rb +1 -1
  102. data/template/elb-load-balancer.rb +2 -2
  103. data/template/emr-cluster.rb +3 -3
  104. data/template/emr-instance-group-config.rb +4 -2
  105. data/template/emr-security-configuration.rb +17 -0
  106. data/template/emr-step.rb +2 -2
  107. data/template/events-rule.rb +8 -8
  108. data/template/iam-group.rb +2 -2
  109. data/template/iam-instance-profile.rb +2 -2
  110. data/template/iam-managed-policy.rb +1 -1
  111. data/template/iam-policy.rb +1 -1
  112. data/template/iam-role.rb +17 -2
  113. data/template/iam-user.rb +4 -4
  114. data/template/kinesis-firehose-delivery-stream.rb +36 -0
  115. data/template/kinesis-stream.rb +21 -0
  116. data/template/kms-alias.rb +2 -2
  117. data/template/kms-key.rb +1 -1
  118. data/template/lambda-alias.rb +2 -2
  119. data/template/lambda-event-source-mapping.rb +4 -4
  120. data/template/lambda-function.rb +17 -17
  121. data/template/lambda-permission.rb +31 -10
  122. data/template/lambda-version.rb +4 -2
  123. data/template/logs-destination.rb +1 -1
  124. data/template/logs-log-group.rb +1 -1
  125. data/template/logs-log-stream.rb +4 -2
  126. data/template/logs-metric-filter.rb +1 -1
  127. data/template/logs-subscription_filter.rb +1 -1
  128. data/template/mappings-ec2.rb +114 -52
  129. data/template/output-arn.rb +12 -4
  130. data/template/output-certificate.rb +11 -0
  131. data/template/output-distribution.rb +11 -0
  132. data/template/output-domain-name.rb +11 -0
  133. data/template/output-ecr-repository.rb +16 -0
  134. data/template/output-eip.rb +11 -0
  135. data/template/output-lambda-function.rb +6 -0
  136. data/template/output-name.rb +7 -2
  137. data/template/output-origin-access-identity.rb +13 -0
  138. data/template/output-rds-cluster.rb +17 -0
  139. data/template/{output-rds.rb → output-rds-instance.rb} +1 -1
  140. data/template/output-redshift.rb +11 -0
  141. data/template/output-rest-api.rb +11 -0
  142. data/template/output-s3.rb +3 -0
  143. data/template/output-stage.rb +19 -0
  144. data/template/output-subnet.rb +6 -3
  145. data/template/output-trail.rb +14 -0
  146. data/template/output-user-pool-client.rb +14 -0
  147. data/template/output-user-pool.rb +17 -0
  148. data/template/output-vpc.rb +13 -3
  149. data/template/output.rb +3 -2
  150. data/template/parameter-ec2.rb +10 -4
  151. data/template/parameter-elasticache.rb +1 -1
  152. data/template/parameter-rds.rb +51 -4
  153. data/template/parameter-redshift.rb +31 -1
  154. data/template/parameter.rb +87 -7
  155. data/template/rds-db-cluster-parameter-group.rb +18 -4
  156. data/template/rds-db-cluster.rb +19 -7
  157. data/template/rds-db-instance.rb +55 -131
  158. data/template/rds-db-parameter-group.rb +29 -3
  159. data/template/rds-db-subnet-group.rb +1 -1
  160. data/template/rds-event-subscription.rb +2 -4
  161. data/template/rds-option-group.rb +28 -5
  162. data/template/redshift-cluster-parameter-group.rb +3 -1
  163. data/template/redshift-cluster-security-group.rb +17 -0
  164. data/template/redshift-cluster-subnet-group.rb +3 -1
  165. data/template/redshift-cluster.rb +15 -12
  166. data/template/s3-bucket.rb +10 -5
  167. data/template/sns-topic.rb +2 -2
  168. data/template/sqs-queue.rb +1 -1
  169. data/test/abstract_unit.rb +2 -9
  170. data/test/cloudfront_test.rb +57 -28
  171. data/test/codedeploy_test.rb +21 -0
  172. data/test/datapipeline_test.rb +0 -22
  173. data/test/ec2_test.rb +12 -52
  174. data/test/ecs_test.rb +30 -26
  175. data/test/emr_test.rb +101 -20
  176. data/test/events_test.rb +47 -0
  177. data/test/helper_test.rb +251 -281
  178. data/test/iam_test.rb +572 -57
  179. data/test/lambda_test.rb +1 -1
  180. data/test/s3_test.rb +49 -14
  181. data/test/template/alb-load-balancer_test.rb +4 -5
  182. data/test/template/alb-target-group_test.rb +1 -3
  183. data/test/template/api-gateway-account_test.rb +26 -0
  184. data/test/template/api-gateway-api-key_test.rb +33 -0
  185. data/test/template/api-gateway-authorizer_test.rb +62 -0
  186. data/test/template/api-gateway-base-path-mapping_test.rb +27 -0
  187. data/test/template/api-gateway-client-certificate_test.rb +21 -0
  188. data/test/template/api-gateway-deployment_test.rb +27 -0
  189. data/test/template/api-gateway-domain-name_test.rb +26 -0
  190. data/test/template/api-gateway-method_test.rb +29 -0
  191. data/test/template/api-gateway-model_test.rb +37 -0
  192. data/test/template/api-gateway-resource_test.rb +82 -0
  193. data/test/template/api-gateway-rest-api_test.rb +33 -0
  194. data/test/template/api-gateway-stage_test.rb +39 -0
  195. data/test/template/api-gateway-usage-plan-key_test.rb +25 -0
  196. data/test/template/api-gateway-usage-plan_test.rb +42 -0
  197. data/test/template/cloudfront-distribution_test.rb +41 -3
  198. data/test/template/cloudtrail_test.rb +13 -5
  199. data/test/template/cloudwatch-alarm_test.rb +14 -2
  200. data/test/template/codebuild-project_test.rb +2 -11
  201. data/test/template/codecommit-repository_test.rb +12 -1
  202. data/test/template/cognito-identity-pool_test.rb +32 -0
  203. data/test/template/cognito-identity-role-attachment_test.rb +38 -0
  204. data/test/template/cognito-user-pool-client_test.rb +36 -0
  205. data/test/template/cognito-user-pool-group_test.rb +36 -0
  206. data/test/template/cognito-user-pool-user-to-group-attachment_test.rb +29 -0
  207. data/test/template/cognito-user-pool-user_test.rb +38 -0
  208. data/test/template/cognito-user-pool_test.rb +99 -0
  209. data/test/template/datapipeline-pipeline_test.rb +45 -6
  210. data/test/template/dynamodb-table_test.rb +19 -1
  211. data/test/template/ec2-instance_test.rb +9 -1
  212. data/test/template/ec2-nat-gateway_test.rb +29 -1
  213. data/test/template/ec2-security-group-egress_test.rb +1 -0
  214. data/test/template/ec2-security-group-ingress_test.rb +1 -0
  215. data/test/template/ec2-security-group_test.rb +11 -1
  216. data/test/template/ec2-spot-fleet_test.rb +1 -1
  217. data/test/template/ec2-subnet_test.rb +62 -1
  218. data/test/template/ec2-vpc-cidr-block_test.rb +1 -1
  219. data/test/template/ec2-vpc-endpoint_test.rb +56 -0
  220. data/test/template/ecr-repository_test.rb +63 -11
  221. data/test/template/ecs-service_test.rb +13 -2
  222. data/test/template/ecs-task-definition_test.rb +86 -13
  223. data/test/template/elasticache-cache-cluster_test.rb +4 -6
  224. data/test/template/elasticache-replication-group_test.rb +1 -1
  225. data/test/template/elasticbeanstalk-application-version_test.rb +1 -0
  226. data/test/template/elasticbeanstalk-application_test.rb +2 -1
  227. data/test/template/elasticbeanstalk-configuration-template_test.rb +2 -1
  228. data/test/template/elasticbeanstalk-template_test.rb +1 -0
  229. data/test/template/elb-load-balancer_test.rb +1 -3
  230. data/test/template/emr-cluster_test.rb +2 -14
  231. data/test/template/emr-instance-group-config_test.rb +2 -4
  232. data/test/template/emr-security-configuration_test.rb +34 -0
  233. data/test/template/emr-step_test.rb +2 -6
  234. data/test/template/events-rule_test.rb +3 -3
  235. data/test/template/iam-group_test.rb +11 -1
  236. data/test/template/iam-instance-profile_test.rb +11 -1
  237. data/test/template/iam-managed-policy_test.rb +1 -0
  238. data/test/template/iam-policy_test.rb +1 -3
  239. data/test/template/iam-role_test.rb +12 -2
  240. data/test/template/iam-user_test.rb +11 -17
  241. data/test/template/kinesis-firehorse-delivery-stream_test.rb +68 -0
  242. data/test/template/kinesis-stream_test.rb +61 -0
  243. data/test/template/kms-key_test.rb +1 -0
  244. data/test/template/lambda-alias_test.rb +2 -3
  245. data/test/template/lambda-event-source-mapping_test.rb +1 -1
  246. data/test/template/lambda-function_test.rb +20 -32
  247. data/test/template/lambda-permission_test.rb +7 -4
  248. data/test/template/lambda-version_test.rb +5 -2
  249. data/test/template/logs-log-group_test.rb +1 -3
  250. data/test/template/logs-log-stream_test.rb +2 -6
  251. data/test/template/logs-metric-filter_test.rb +1 -3
  252. data/test/template/logs-subscription-filter_test.rb +1 -3
  253. data/test/template/mappings-ec2_test.rb +10 -3
  254. data/test/template/output-domain-name_test.rb +30 -0
  255. data/test/template/output-name_test.rb +9 -0
  256. data/test/template/{output-rds_test.rb → output-rds-instance_test.rb} +2 -2
  257. data/test/template/output-rest-api_test.rb +30 -0
  258. data/test/template/output-s3_test.rb +9 -0
  259. data/test/template/output-stage_test.rb +43 -0
  260. data/test/template/output-user-pool-client_test.rb +39 -0
  261. data/test/template/output-user-pool_test.rb +48 -0
  262. data/test/template/output_test.rb +3 -1
  263. data/test/template/parameter-ec2_test.rb +22 -24
  264. data/test/template/parameter-elasticache_test.rb +2 -1
  265. data/test/template/parameter-rds_test.rb +32 -3
  266. data/test/template/parameter-redshift_test.rb +31 -2
  267. data/test/template/parameter_test.rb +37 -4
  268. data/test/template/rds-db-cluster-parameter-group_test.rb +1 -1
  269. data/test/template/rds-db-cluster_test.rb +4 -20
  270. data/test/template/rds-db-instance_test.rb +3 -373
  271. data/test/template/rds-db-parameter-group_test.rb +1 -1
  272. data/test/template/rds-option-group_test.rb +2 -2
  273. data/test/template/redshift-cluster-parameter-group_test.rb +28 -0
  274. data/test/template/redshift-cluster-security-group_test.rb +49 -0
  275. data/test/template/redshift-cluster-subnet-group_test.rb +28 -0
  276. data/test/template/redshift-cluster_test.rb +33 -5
  277. data/test/template/s3-bucket_test.rb +6 -20
  278. metadata +130 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ff8b5ee89f699fd747bf383b8dacb8c77f9719a7
4
- data.tar.gz: 6f49fa10979f3561aa30ecd31557bee15e6de2fb
2
+ SHA256:
3
+ metadata.gz: 7c8d9ab5748134f2d4b2f803d7a699707c951515945790d0874e2dbae7d290f0
4
+ data.tar.gz: 401347892cbc9146e7e7f8c35eb6f0a57026695eeee659c4f038610a4c51d957
5
5
  SHA512:
6
- metadata.gz: db7151f224695cd9aee542fffed40f72bf28de7bcbc6a473af16f31a9ca3120d95fa7e5fa7210f8af82d494d9e541b3748a5880a8a67a67b79e2c819b8205758
7
- data.tar.gz: ba826e18ad1d8b61d1258ae0447aa04255dee4f8ca6be65e9039d6ac5fa3d51ae7830696e4b773c2f235e600b0578152d6895af070c01689e45021c95ebd403e
6
+ metadata.gz: 7acf0b5c6353373debd184868eb057e6a07ac307307ef4de9e3c4a0115460514ef90a049232f9721be81e2e6d35510d820dd20e2a20dfb84da401854ad119d8a
7
+ data.tar.gz: 4cf9d0c4105dde1a10aa1dd903c42a0f2b1d8c1caed6e539db15490221f34ab26dcb35a68e2fa482d5ed88d7d45e431b960b1b1dd1c116b1da0a23e419c39694
data/.travis.yml CHANGED
@@ -2,8 +2,10 @@ sudo: false
2
2
  language: ruby
3
3
  cache: bundler
4
4
  rvm:
5
- - 2.4.1
6
- gemfile: n0ts/kumogata-template/Gemfile
5
+ - 2.5.1
6
+ gemfile: Gemfile
7
+ before_install:
8
+ - export TZ=Asia/Tokyo
7
9
  script:
8
10
  - bundle install --path vendor/bundle
9
11
  - bundle exec rake
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ source 'https://rubygems.org'
3
3
  ENV['NOKOGIRI_USE_SYSTEM_LIBRARIES'] = 'YES'
4
4
 
5
5
  # Specify your gem's dependencies in kumogata.gemspec
6
- gemspec
6
+ gemspec
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ Rake::TestTask.new do |t|
9
9
  t.libs << 'test'
10
10
  t.pattern = 'test/**/*_test.rb'
11
11
  # disable output - warning: assigned but unused variable
12
- t.warning = false
12
+ t.warning = true
13
13
  t.verbose = false
14
14
  t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
15
15
  end
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'aws-sdk', '~> 2.3'
22
- spec.add_dependency 'kumogata2-plugin-ruby', '>= 0.1.6'
23
- spec.add_development_dependency 'bundler'
24
- spec.add_development_dependency 'rake'
25
- spec.add_development_dependency 'minitest'
22
+ spec.add_dependency 'kumogata2-plugin-ruby', '~> 0.1'
23
+ spec.add_development_dependency 'bundler', '~> 1.16'
24
+ spec.add_development_dependency 'rake', '~> 12.3'
25
+ spec.add_development_dependency 'minitest', '~> 5.11'
26
26
  end
@@ -24,6 +24,12 @@ def _alb_to_lb_attribute_idle_timeout(value)
24
24
  }
25
25
  end
26
26
 
27
+ def _alb_to_lb_http2(value = true)
28
+ {
29
+ "routing.http2.enabled": value
30
+ }
31
+ end
32
+
27
33
  def _alb_to_target_group_attribute_delay_timeout(value)
28
34
  # wait before changing the state of a deregistering target from draining to unused 0-3600 seconds.
29
35
  {
@@ -40,6 +46,18 @@ def _alb_to_target_group_stickiness(value)
40
46
  }
41
47
  end
42
48
 
49
+ def _alb_to_min_health_check(args)
50
+ {
51
+ protocol: _valid_values(args[:protocol], %w( http https ), 'http').upcase,
52
+ path: args[:path] || '/',
53
+ port: args[:port] || 80,
54
+ healthy: args[:healthy] || 2,
55
+ unhealthly: args[:unhealthly] || 2,
56
+ timeout: args[:timeout] || 2,
57
+ interval: args[:interval] || 5,
58
+ }
59
+ end
60
+
43
61
  def _alb_certificates(args)
44
62
  certificate = _ref_string("certificate", args)
45
63
 
@@ -51,46 +69,39 @@ def _alb_certificates(args)
51
69
  end
52
70
 
53
71
  def _alb_actions(args)
54
- defaults = args[:actions] || []
55
-
56
- array = []
57
- defaults.each do |default|
72
+ (args[:actions] || []).collect do |default|
58
73
  target = _ref_string("target", default, "target group")
59
- array << _{
74
+ _{
60
75
  TargetGroupArn target
61
76
  Type "forward"
62
77
  }
63
78
  end
64
- array
65
79
  end
66
80
 
67
81
  def _alb_conditions(args)
68
- conditions = args[:conditions] || []
69
-
70
- array = []
71
- conditions.each do |condition|
82
+ (args[:conditions] || []).collect do |condition|
72
83
  condition = [ condition ] unless condition.is_a? Array
73
- array << _{
84
+ _{
74
85
  Field "path-pattern"
75
86
  Values condition
76
87
  }
77
88
  end
78
- array
79
89
  end
80
90
 
81
91
  def _alb_attributes(args)
82
- attributes = args[:attributes] || []
83
-
84
- array = []
85
- attributes.each do |attribute|
86
- attribute.each_pair{|key, value|
87
- array << _{
88
- Key key
89
- Value value
90
- }
91
- }
92
- end
93
- array
92
+ (args[:attributes] || []).collect do |attribute|
93
+ type = attribute[:type] || ''
94
+ case type
95
+ when 'log'
96
+ attribute = _alb_to_lb_attribute_access_log(attribute)
97
+ when 'timeout'
98
+ attribute = _alb_to_lb_attribute_idle_timeout(attribute[:timeout])
99
+ when 'delay-timeout'
100
+ attribute = _alb_to_target_group_attribute_delay_timeout(attribute[:timeout])
101
+ end
102
+
103
+ _pair_value({ attribute: attribute }, 'attribute')
104
+ end.flatten
94
105
  end
95
106
 
96
107
  def _alb_matcher(args)
@@ -103,8 +114,15 @@ def _alb_matcher(args)
103
114
  end
104
115
 
105
116
  def _alb_health_check(args)
117
+ type = args[:type] || ''
118
+ case type
119
+ when 'min'
120
+ return _alb_to_min_health_check(args)
121
+ end
122
+
106
123
  protocol = _valid_values(args[:protocol] || "", %w( http https ), "http")
107
- # Return to native hash
124
+
125
+ # return to native hash
108
126
  {
109
127
  interval: args[:interval] || 30,
110
128
  path: args[:path] || "/",
@@ -117,24 +135,20 @@ def _alb_health_check(args)
117
135
  end
118
136
 
119
137
  def _alb_targets(args)
120
- targets = args[:targets] || []
121
- ref_targets = args[:ref_targets] || []
122
-
123
- array = []
124
- targets.each do |target|
138
+ targets = (args[:targets] || []).collect do |target|
125
139
  id = _ref_string("instance", target, "instance")
126
- array << _{
140
+ _{
127
141
  Id id
128
142
  Port target[:port] if target.key? :port
129
143
  }
130
144
  end
131
145
 
132
- ref_targets.each do |target|
133
- array << _{
146
+ targets += (args[:ref_targets] || []).collect do |target|
147
+ _{
134
148
  Id _ref_string("instance", { ref_instance: target }, "instance")
135
149
  Port 80
136
150
  }
137
151
  end
138
152
 
139
- array
153
+ targets
140
154
  end
@@ -0,0 +1,262 @@
1
+ #
2
+ # Helper - Api Gateway
3
+ #
4
+ require 'kumogata/template/helper'
5
+
6
+ def _api_gateway_to_parameter(args)
7
+ type = _valid_values(args[:type], %w( integration method ), "method")
8
+ location = _valid_values(args[:location], %w( querystring path header ), "path")
9
+ operation = args[:operation] || "request"
10
+ "#{type}.#{operation}.#{location}.#{args[:name]}"
11
+ end
12
+
13
+ def _api_gateway_to_parameter_headers(kind)
14
+ headers =
15
+ case kind
16
+ when "aws"
17
+ [
18
+ { name: "X-AWS-Request-Id", value: "context.requestId" },
19
+ { name: "X-AWS-API-Id", value: "context.apiId" },
20
+ ]
21
+ when "cognito"
22
+ [
23
+ { name: "X-AWS-Cognito-Identity-Id", value: "context.identity.cognitoIdentityId" },
24
+ { name: "X-AWS-Cognito-Identity-Pool-Id", value: "context.identity.cognitoIdentityPoolId" },
25
+ { name: "X-AWS-Cognito-Authentication-Type", value: "context.identity.cognitoAuthenticationType" },
26
+ { name: "X-AWS-Cognito-Authentication-Provider", value: "context.identity.cognitoAuthenticationProvider" },
27
+ ]
28
+ else
29
+ []
30
+ end
31
+ return headers if headers.empty?
32
+
33
+ headers.collect{|v| v.merge!({ location: "header" }) }
34
+ end
35
+
36
+ def _api_gateway_to_parameter_response_headers(args = {})
37
+ headers = {}
38
+ key = _api_gateway_to_parameter({ operation: "response",
39
+ location: "header",
40
+ name: "Access-Control-Allow-Methods" })
41
+ headers[key] = "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
42
+
43
+ key = _api_gateway_to_parameter({ operation: "response",
44
+ location: "header",
45
+ name: "Access-Control-Allow-Headers" })
46
+ allow_headers = %w( Content-Type Authorization X-Amz-Date X-Api-Key X-Amz-Security-Token)
47
+ allow_headers += args[:allow_headers] if args.key? :allow_headers
48
+ headers[key] = sprintf("'%s'", allow_headers.join(','))
49
+
50
+ key = _api_gateway_to_parameter({ operation: "response",
51
+ location: "header",
52
+ name: "Access-Control-Allow-Origin" })
53
+ headers[key] = "'*'"
54
+
55
+ headers
56
+ end
57
+
58
+ def _api_gateway_stage_keys(args)
59
+ (args[:stage_keys] || []).collect do |key|
60
+ rest = _ref_string("rest", key, "reset api")
61
+ stage = _ref_string("stage", key)
62
+ _{
63
+ RestApiId rest
64
+ StageName stage
65
+ }
66
+ end
67
+ end
68
+
69
+ def _api_gateway_integration(args)
70
+ args_proxy = _bool("proxy", args, false)
71
+ args_parameters = args[:parameters] || []
72
+
73
+ integration = args[:integration] || {}
74
+ return integration if integration.empty?
75
+
76
+ cache_keys = integration[:cache_keys] || []
77
+ cache_keys << _api_gateway_to_parameter({ type: "method", location: "path", name: "proxy" }) if args_proxy
78
+ cache_ns = integration[:cache_ns] || ""
79
+ http =
80
+ if args_proxy
81
+ "any"
82
+ else
83
+ _valid_values(integration[:http], %w( delete get head options patch post put any ), "any")
84
+ end
85
+ responses =
86
+ if integration.key? :responses
87
+ integration[:responses].collect{|v| _api_gateway_integration_response(v) }
88
+ else
89
+ []
90
+ end
91
+ responses << _api_gateway_integration_response({ template: { "application/json": "null" } }) if args_proxy
92
+ pass =
93
+ if args_proxy
94
+ "when_no_match"
95
+ else
96
+ _valid_values(integration[:pass], %w( when_no_match when_no_templates never ), "")
97
+ end
98
+ role = _ref_attr_string("role", "Arn", integration)
99
+ parameters = {}
100
+ args_parameters.collect do |v|
101
+ k = _api_gateway_to_parameter({ type: "integration", location: v[:location], name: v[:name] })
102
+ parameters[k] = _api_gateway_to_parameter(v)
103
+ end
104
+ (integration[:parameters] || []).collect do |v|
105
+ k = _api_gateway_to_parameter({ type: "integration", location: v[:location], name: v[:name] })
106
+ parameters[k] = v[:value]
107
+ end
108
+ # RequestTemplates
109
+ # - Key: The content type value
110
+ # - Value: the template http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
111
+ templates = integration[:templates] || {}
112
+ type =
113
+ if args_proxy
114
+ "http_proxy"
115
+ else
116
+ _valid_values(integration[:type], %w( mock http http_proxy aws aws_proxy ), "http")
117
+ end
118
+
119
+ uri =
120
+ case type
121
+ when /http/
122
+ _ref_string("uri", integration)
123
+ when /aws/
124
+ _iam_arn("api-gateway", integration)
125
+ else
126
+ ""
127
+ end
128
+ uri = _join([ uri, "{proxy}" ], "/") if args_proxy
129
+
130
+ _{
131
+ CacheKeyParameters cache_keys unless cache_keys.empty?
132
+ CacheNamespace cache_ns unless cache_ns.empty?
133
+ Credentials role unless role.empty?
134
+ IntegrationHttpMethod http.upcase if type != "mock"
135
+ IntegrationResponses responses unless responses.empty?
136
+ PassthroughBehavior pass.upcase unless pass.empty?
137
+ RequestParameters parameters unless parameters.empty?
138
+ RequestTemplates templates unless templates.empty?
139
+ Type type.upcase
140
+ Uri uri unless uri.empty?
141
+ }
142
+ end
143
+
144
+ def _api_gateway_integration_response(args)
145
+ parameter = args[:parameter] || {}
146
+ template = args[:template] || {}
147
+ selection = args[:selection] || ""
148
+ status = args[:status] || 200
149
+
150
+ _{
151
+ ResponseParameters parameter unless parameter.empty?
152
+ ResponseTemplates template unless template.empty?
153
+ SelectionPattern selection unless selection.empty?
154
+ StatusCode status
155
+ }
156
+ end
157
+
158
+ def _api_gateway_responses(args)
159
+ (args[:responses] || []).collect do |response|
160
+ models = response[:models] || []
161
+ parameters = response[:parameters] || []
162
+ status = response[:status] || 200
163
+
164
+ _{
165
+ ResponseModels models unless models.empty?
166
+ ResponseParameters parameters unless parameters.empty?
167
+ StatusCode status
168
+ }
169
+ end
170
+ end
171
+
172
+ def _api_gateway_stage_description(args)
173
+ description = args[:stage_description] || {}
174
+ return description if description.empty?
175
+
176
+ cache = description[:cache] || {}
177
+ certificate = _ref_string_default("certificate", description, "certificate")
178
+ data_trace = _bool("data_trace", description, false)
179
+ description_desc = description[:description] || ""
180
+ logging = _valid_values(description[:logging], %w( off error info ), "off")
181
+ method = _api_gateway_method_settings(description)
182
+ metrics = _bool("metrics", description, false)
183
+ stage = _name("stage", description)
184
+ throtting = description[:throtting] || {}
185
+ variables = description[:variables] || {}
186
+
187
+ _{
188
+ CacheClusterEnabled true if cache.key? :cluster
189
+ CacheClusterSize cache[:size] unless cache.empty?
190
+ CacheDataEncrypted true if cache.key? :encrypted
191
+ CacheTtlInSeconds cache[:ttl] unless cache.empty?
192
+ CachingEnabled cache.empty? ? false : true
193
+ ClientCertificateId certificate unless certificate.empty?
194
+ DataTraceEnabled data_trace
195
+ Description description unless description_desc.empty?
196
+ LoggingLevel logging.upcase
197
+ MethodSettings method unless method.empty?
198
+ MetricsEnabled metrics
199
+ StageName stage
200
+ ThrottlingBurstLimit throtting[:burst] unless throtting.empty?
201
+ ThrottlingRateLimit throtting[:rate] unless throtting.empty?
202
+ Variables variables unless variables.empty?
203
+ }
204
+ end
205
+
206
+ def _api_gateway_method_settings(args)
207
+ (args[:settings] || []).collect do |setting|
208
+ cache = setting[:cache] || {}
209
+ data_trace = _bool("data_trace", setting, false)
210
+ http = setting[:http] || "*"
211
+ logging = _valid_values(setting[:logging], %w( off error info ), "info")
212
+ metrics = _bool("metrics", setting, false)
213
+ resource = setting[:resource] || "/*"
214
+ throtting = setting[:throtting] || {}
215
+
216
+ _{
217
+ CacheDataEncrypted cache[:encrypted] unless cache.empty?
218
+ CacheTtlInSeconds cache[:ttl] unless cache.empty?
219
+ CachingEnabled cache.empty? ? false : true
220
+ DataTraceEnabled data_trace
221
+ HttpMethod http
222
+ LoggingLevel logging.upcase
223
+ MetricsEnabled metrics
224
+ ResourcePath resource
225
+ ThrottlingBurstLimit throtting[:burst] unless throtting.empty?
226
+ ThrottlingRateLimit throtting[:rate] unless throtting.empty?
227
+ }
228
+ end
229
+ end
230
+
231
+ def _api_gateway_stages(args)
232
+ (args[:stages] || []).collect do |stage|
233
+ _{
234
+ ApiId _ref_string("rest", stage, "rest api")
235
+ Stage _ref_string("stage", stage, "stage")
236
+ }
237
+ end
238
+ end
239
+
240
+ def _api_gateway_quota(args)
241
+ quota = args[:quota] || {}
242
+ return quota if quota.empty?
243
+
244
+ offset = quota[:offset] || ""
245
+ period = _valid_values(quota[:period], %w( day week month ), "month")
246
+
247
+ _{
248
+ Limit quota[:limit]
249
+ Offset offset unless offset.empty?
250
+ Period period.upcase
251
+ }
252
+ end
253
+
254
+ def _api_gateway_throttle(args)
255
+ throttle = args[:throttle] || {}
256
+ return throttle if throttle.empty?
257
+
258
+ _{
259
+ BurstLimit throttle[:bust]
260
+ RateLimit throttle[:rate]
261
+ }
262
+ end
@@ -107,53 +107,26 @@ def _autoscaling_step(args)
107
107
  }
108
108
  end
109
109
 
110
- def _autoscaling_tags(args)
111
- tags = [
112
- _{
113
- Key "Name"
114
- Value _tag_name(args)
115
- PropagateAtLaunch _bool("tag_name_launch", args, true)
116
- },
117
- _{
118
- Key "Service"
119
- Value { Ref _resource_name("service") }
120
- PropagateAtLaunch _bool("tag_service_launch", args, true)
121
- },
122
- _{
123
- Key "Version"
124
- Value { Ref _resource_name("version") }
125
- PropagateAtLaunch _bool("tag_version_launch", args, true)
126
- },
127
- ]
128
- if args.key? :tags_append
129
- args[:tags_append].each do|key, value|
130
- tag = _tag({ key: key, value: value })
131
- tag["PropagateAtLaunch"] = _bool("tag_#{key}_launch", args, true)
132
- tags << tag
133
- end
110
+ def _autoscaling_tags(args, tag_name = "tag_name")
111
+ _tags(args, tag_name).collect do |tag|
112
+ tag["PropagateAtLaunch"] = _bool("#{tag["Key"].downcase}_launch", args, true).to_s
113
+ tag
134
114
  end
135
- tags
136
115
  end
137
116
 
138
117
  def _autoscaling_terminations(args)
139
- terminations = args[:terminations]
140
- return [] if terminations.nil?
141
-
142
- array = []
143
- terminations.each do |termination|
144
- array <<
145
- case termination.downcase
146
- when "old instance"
147
- "OldestInstance"
148
- when "new instance"
149
- "NewestInstance"
150
- when "old launch"
151
- "OldestLaunchConfiguration"
152
- when "close"
153
- "ClosestToNextInstanceHour"
154
- else
155
- "Default"
156
- end
118
+ (args[:terminations] || []).collect do |termination|
119
+ case termination.downcase
120
+ when "old instance"
121
+ "OldestInstance"
122
+ when "new instance"
123
+ "NewestInstance"
124
+ when "old launch"
125
+ "OldestLaunchConfiguration"
126
+ when "close"
127
+ "ClosestToNextInstanceHour"
128
+ else
129
+ "Default"
130
+ end
157
131
  end
158
- array
159
132
  end
@@ -4,15 +4,18 @@
4
4
  require 'kumogata/template/helper'
5
5
 
6
6
  def _certificate_validations(args)
7
- validation = args[:validation] || []
8
- validation << { domain: args[:domain], validation: args[:domain] } if validation.empty?
7
+ validations = args[:validation] || []
8
+ return [ _{
9
+ DomainName _ref_string("domain", args, "domain")
10
+ ValidationDomain _ref_string("domain", args, "domain")
11
+ } ] if validations.empty?
9
12
 
10
- result = []
11
- validation.each do |val|
12
- result << _{
13
- DomainName val[:domain]
14
- ValidationDomain val[:validation]
13
+ validations.collect do |validation|
14
+ domain = _ref_string("domain", validation, "domain")
15
+ validation = _ref_string("validation", validation, "domain")
16
+ _{
17
+ DomainName domain
18
+ ValidationDomain validation || domain
15
19
  }
16
20
  end
17
- result
18
21
  end