cfn-model 0.6.3 → 0.6.4

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: 6c85f3a966c7c0c6cf9dd798efbed371040c3dc48e1166e644514e00c46a4df0
4
- data.tar.gz: 24dd16f62e2c5bfecd5cb376971b07b6e0812fc6a3ad91e209afbd97b06a6b35
3
+ metadata.gz: 819df60d0212456c46c1fe5ae95b97bf33c8cb223a0d4f836e4d2f7e35a9d28e
4
+ data.tar.gz: 9e29152b3a2988ad4dc31ef0bb40307ae5fcb23dc5752ee13998280ee1b6e660
5
5
  SHA512:
6
- metadata.gz: ec86e02fb6eb3cd5aadcec87268c27211b62c99deb05db7c894ba7b3a0e76e8e43a87e2312b324bdb81214f1668beb6ed99871882d14ddac036ddc4ba4e811a7
7
- data.tar.gz: 23b0bba29253cc7fa5565dd891b471c0dd06ce53f591ebf09d3e7b5bc58de3614e24ea39dce89e3ee6dba99ad38d99a706a6690e4fabe32e27279cbec1076549
6
+ metadata.gz: 60dff3853250130a0d39e7a4844e1e84f11be354c88600e3b127387e71afbfd6f5aac4f90b8192c7b19559dfd263ef127d7eb0070e016c79347579d3d8efae42
7
+ data.tar.gz: ec6b71a0376167b1a52857c4570a8e1c199ccf40901d1cff5d31cf26da32d6c01dccd035f0504e712eb344ca62e90b70408277223eff5de8dc85c7c4ef9a2f71
@@ -3,7 +3,7 @@
3
3
  class CfnModel
4
4
  class Transforms
5
5
  # Handle transformation of model elements performed by the
6
- # Serverless trasnform, see
6
+ # Serverless transform, see
7
7
  # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-aws-serverless.html
8
8
  class Serverless
9
9
  def perform_transform(cfn_hash)
@@ -108,6 +108,8 @@ class CfnModel
108
108
  def replace_serverless_function(cfn_hash, resource_name, with_line_numbers)
109
109
  serverless_function = cfn_hash['Resources'][resource_name]
110
110
 
111
+ original_line_number = serverless_function['Type']['line']
112
+
111
113
  lambda_fn_params = serverless_function_properties(cfn_hash,
112
114
  serverless_function,
113
115
  resource_name,
@@ -120,15 +122,17 @@ class CfnModel
120
122
  role: lambda_fn_params[:role],
121
123
  runtime: lambda_fn_params[:runtime],
122
124
  reserved_concurrent_executions: lambda_fn_params[:reserved_concurrent_executions],
125
+ line_number: original_line_number,
123
126
  with_line_numbers: lambda_fn_params[:with_line_numbers]
124
127
  )
125
128
  unless serverless_function['Properties']['Role']
126
129
  cfn_hash['Resources'][resource_name + 'Role'] = function_role(serverless_function,
127
130
  resource_name,
131
+ original_line_number,
128
132
  with_line_numbers)
129
133
  end
130
134
 
131
- transform_function_events(cfn_hash, serverless_function, resource_name, with_line_numbers) if \
135
+ transform_function_events(cfn_hash, serverless_function, resource_name, original_line_number, with_line_numbers) if \
132
136
  serverless_function['Properties']['Events']
133
137
 
134
138
  # Handle passing along cfn-nag specific metadata. SAM itself does not support metadata during transformation.
@@ -156,9 +160,9 @@ class CfnModel
156
160
 
157
161
  # Return the hash structure of the '<function_name>Role'
158
162
  # AWS::IAM::Role resource as created by Serverless transform
159
- def function_role(serverless_function, function_name, with_line_numbers)
163
+ def function_role(serverless_function, function_name, line_number, with_line_numbers)
160
164
  fn_role = {
161
- 'Type' => format_resource_type('AWS::IAM::Role', -1, with_line_numbers),
165
+ 'Type' => format_resource_type('AWS::IAM::Role', line_number, with_line_numbers),
162
166
  'Properties' => {
163
167
  'ManagedPolicyArns' => function_role_managed_policies(serverless_function['Properties']),
164
168
  'AssumeRolePolicyDocument' => lambda_service_can_assume_role
@@ -226,9 +230,10 @@ class CfnModel
226
230
  role:,
227
231
  runtime:,
228
232
  reserved_concurrent_executions:,
233
+ line_number:,
229
234
  with_line_numbers: false)
230
235
  fn_resource = {
231
- 'Type' => format_resource_type('AWS::Lambda::Function', -1, with_line_numbers),
236
+ 'Type' => format_resource_type('AWS::Lambda::Function', line_number, with_line_numbers),
232
237
  'Properties' => {
233
238
  'Handler' => handler,
234
239
  'Role' => role,
@@ -242,16 +247,16 @@ class CfnModel
242
247
 
243
248
  # Return the Event structure of a AWS::Lambda::Function as created
244
249
  # by Serverless transform
245
- def transform_function_events(cfn_hash, serverless_function, function_name, with_line_numbers)
250
+ def transform_function_events(cfn_hash, serverless_function, function_name, line_number, with_line_numbers)
246
251
  serverless_function['Properties']['Events'].each do |_, event|
247
- serverlessrestapi_resources(cfn_hash, event, function_name, with_line_numbers) if \
252
+ serverlessrestapi_resources(cfn_hash, event, function_name, line_number, with_line_numbers) if \
248
253
  matching_resource_type?(event['Type'], 'Api')
249
254
  end
250
255
  end
251
256
 
252
- def serverlessrestapi_resources(cfn_hash, event, func_name, with_line_numbers)
257
+ def serverlessrestapi_resources(cfn_hash, event, func_name, line_number, with_line_numbers)
253
258
  # ServerlessRestApi
254
- cfn_hash['Resources']['ServerlessRestApi'] ||= serverlessrestapi_base with_line_numbers
259
+ cfn_hash['Resources']['ServerlessRestApi'] ||= serverlessrestapi_base line_number, with_line_numbers
255
260
  add_serverlessrestapi_event(
256
261
  cfn_hash['Resources']['ServerlessRestApi']['Properties']['Body']['paths'],
257
262
  event,
@@ -259,15 +264,15 @@ class CfnModel
259
264
  )
260
265
 
261
266
  # ServerlessRestApiDeployment
262
- cfn_hash['Resources']['ServerlessRestApiDeployment'] = serverlessrestapi_deployment with_line_numbers
267
+ cfn_hash['Resources']['ServerlessRestApiDeployment'] ||= serverlessrestapi_deployment line_number, with_line_numbers
263
268
 
264
269
  # ServerlessRestApiProdStage
265
- cfn_hash['Resources']['ServerlessRestApiProdStage'] = serverlessrestapi_stage with_line_numbers
270
+ cfn_hash['Resources']['ServerlessRestApiProdStage'] ||= serverlessrestapi_stage line_number, with_line_numbers
266
271
  end
267
272
 
268
- def serverlessrestapi_base(with_line_nos)
273
+ def serverlessrestapi_base(line_number, with_line_numbers)
269
274
  {
270
- 'Type' => format_resource_type('AWS::ApiGateway::RestApi', -1, with_line_nos),
275
+ 'Type' => format_resource_type('AWS::ApiGateway::RestApi', line_number, with_line_numbers),
271
276
  'Properties' => {
272
277
  'Body' => {
273
278
  'info' => {
@@ -294,9 +299,9 @@ class CfnModel
294
299
  }
295
300
  end
296
301
 
297
- def serverlessrestapi_deployment(with_line_nos)
302
+ def serverlessrestapi_deployment(line_number, with_line_numbers)
298
303
  {
299
- 'Type' => format_resource_type('AWS::ApiGateway::Deployment', -1, with_line_nos),
304
+ 'Type' => format_resource_type('AWS::ApiGateway::Deployment', line_number, with_line_numbers),
300
305
  'Properties' => {
301
306
  'Description' => 'Generated by cfn-model',
302
307
  'RestApiId' => { 'Ref' => 'ServerlessRestApi' },
@@ -311,9 +316,9 @@ class CfnModel
311
316
  }
312
317
  end
313
318
 
314
- def serverlessrestapi_stage(with_line_nos)
319
+ def serverlessrestapi_stage(line_number, with_line_numbers)
315
320
  {
316
- 'Type' => format_resource_type('AWS::ApiGateway::Stage', -1, with_line_nos),
321
+ 'Type' => format_resource_type('AWS::ApiGateway::Stage', line_number, with_line_numbers),
317
322
  'Properties' => {
318
323
  'DeploymentId' => { 'Ref' => 'ServerlessRestApiDeployment' },
319
324
  'RestApiId' => { 'Ref' => 'ServerlessRestApi' },
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.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kascic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-13 00:00:00.000000000 Z
11
+ date: 2021-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -193,9 +193,9 @@ licenses:
193
193
  metadata:
194
194
  bug_tracker_uri: https://github.com/stelligent/cfn-model/issues
195
195
  changelog_uri: https://github.com/stelligent/cfn-model/releases
196
- documentation_uri: https://www.rubydoc.info/gems/cfn-model/0.6.3
196
+ documentation_uri: https://www.rubydoc.info/gems/cfn-model/0.6.4
197
197
  homepage_uri: https://github.com/stelligent/cfn-model
198
- source_code_uri: https://github.com/stelligent/cfn-model/tree/v0.6.3
198
+ source_code_uri: https://github.com/stelligent/cfn-model/tree/v0.6.4
199
199
  post_install_message:
200
200
  rdoc_options: []
201
201
  require_paths: