cfn-model 0.1.24 → 0.1.25

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
  SHA1:
3
- metadata.gz: 99ae976c5f51a3dd20649127f9cf9f121d14b013
4
- data.tar.gz: 47484978c5fe38df5cf003472a83013c27d7cba1
3
+ metadata.gz: 10958dfafdaa000fa3e7de361a28f31bdcc16436
4
+ data.tar.gz: f0871cea3dbddc961834402690da91f95cfbd5cc
5
5
  SHA512:
6
- metadata.gz: c5015a2a0e92b54cf8a6aeb4d25787e9f71ea4135dd906913f5c72d4169196a0c8a57bef1e78638f053c556ae8b6f2dba471690b0e2d9169d9ee58a3aaf12b9d
7
- data.tar.gz: 8f1f04480fd6e462423fa9bf4b5099b282d0348cf3aa358225e9ea10a4cd993240e875c3638d9b567c9ecf69487f1cf7d70a194a870d7673514ef1fe8e54a243
6
+ metadata.gz: 3656ead12b0ddc08c62f837456ffdd90ef633f57bb7a04ee23a39d4fdae06e4fa0a7d0eb0bf306890249b334d84f6095aabf8fa1df0a2b1589572f210721627f
7
+ data.tar.gz: b3b2f02377d312540fcd8ae1beb13b642b437785621658dd2b46d2bdcfcba8eef63acf1c94938f05079b19a066d27f0c72fcad0d787fe2a6d585cde80d38bdd5
@@ -16,7 +16,7 @@ class CfnModel
16
16
 
17
17
  def perform_transforms(cfn_hash)
18
18
  transform_name = cfn_hash['Transform']
19
- return unless transform_name
19
+ return unless transform_name && @registry[transform_name]
20
20
  @registry[transform_name].instance.perform_transform cfn_hash
21
21
  end
22
22
 
@@ -29,22 +29,28 @@ class CfnModel
29
29
  uri.split('/')[3..-1].join('/')
30
30
  end
31
31
 
32
+ # Is a URL a S3 URL
33
+ def is_s3_uri?(uri)
34
+ uri[0..4].eql? 's3://'
35
+ end
36
+
32
37
  # rubocop:disable Metrics/AbcSize
33
38
  # rubocop:disable Metrics/MethodLength
34
39
 
35
40
  def replace_serverless_function(cfn_hash, resource_name)
36
41
  resource = cfn_hash['Resources'][resource_name]
42
+ code_uri = resource['Properties']['CodeUri']
37
43
 
38
- code_bucket = bucket_from_uri resource['Properties']['CodeUri']
39
- code_key = object_key_from_uri resource['Properties']['CodeUri']
40
-
44
+ lambda_fn_params = {
45
+ handler: resource['Properties']['Handler'],
46
+ runtime: resource['Properties']['Runtime']
47
+ }
48
+ if is_s3_uri? code_uri
49
+ lambda_fn_params[:code_bucket] = bucket_from_uri code_uri
50
+ lambda_fn_params[:code_key] = object_key_from_uri code_uri
51
+ end
41
52
  cfn_hash['Resources'][resource_name] = \
42
- lambda_function(
43
- handler: resource['Properties']['Handler'],
44
- code_bucket: code_bucket,
45
- code_key: code_key,
46
- runtime: resource['Properties']['Runtime']
47
- )
53
+ lambda_function lambda_fn_params
48
54
 
49
55
  cfn_hash['Resources']['FunctionNameRole'] = function_name_role
50
56
  end
@@ -76,15 +82,24 @@ class CfnModel
76
82
 
77
83
  # Return the hash structure of a AWS::Lambda::Function as created
78
84
  # by Serverless transform
79
- def lambda_function(handler:, code_bucket:, code_key:, runtime:)
85
+ def lambda_function(handler:,
86
+ code_bucket: nil,
87
+ code_key: nil,
88
+ runtime:)
89
+ fn_resource = \
80
90
  { 'Type' => 'AWS::Lambda::Function',
81
91
  'Properties' => {
82
92
  'Handler' => handler,
83
- 'Code' => { 'S3Bucket' => code_bucket,
84
- 'S3Key' => code_key },
85
93
  'Role' => { 'Fn::GetAtt' => %w[FunctionNameRole Arn] },
86
94
  'Runtime' => runtime
87
95
  } }
96
+ if code_bucket && code_key
97
+ fn_resource['Properties']['Code'] = {
98
+ 'S3Bucket' => code_bucket,
99
+ 'S3Key' => code_key
100
+ }
101
+ end
102
+ fn_resource
88
103
  end
89
104
  end
90
105
  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.1.24
4
+ version: 0.1.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kascic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-25 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop