@@ -5,7 +5,7 @@ import Foundation
5
5
//
6
6
public struct DeploymentDefinition {
7
7
8
- private var deployment : DeploymentDescriptor ? = nil // optional is required to allow initialization after the capturing closure (compactMap)
8
+ private var deployment : DeploymentDescriptor
9
9
10
10
public init (
11
11
// the description of the SAM template
@@ -18,7 +18,7 @@ public struct DeploymentDefinition {
18
18
resources: [ Resource ] )
19
19
{
20
20
21
- let functionResources = createResources ( for: functions)
21
+ let functionResources = DeploymentDefinition . createResources ( for: functions)
22
22
23
23
self . deployment = SAMDeployment ( description: description,
24
24
resources: functionResources + resources)
@@ -29,7 +29,7 @@ public struct DeploymentDefinition {
29
29
}
30
30
31
31
// create one Resource per function + additional resource for the function dependencies (ex: a SQS queue)
32
- private func createResources( for functions: [ Function ] ) -> [ Resource ] {
32
+ private static func createResources( for functions: [ Function ] ) -> [ Resource ] {
33
33
34
34
var additionalresources : [ Resource ] = [ ]
35
35
let functionResources = functions. compactMap { function in
@@ -43,7 +43,7 @@ public struct DeploymentDefinition {
43
43
lambdaPackage = " \( archiveArg) / \( function. name) / \( function. name) .zip "
44
44
}
45
45
}
46
-
46
+
47
47
// check the ZIP file exists
48
48
if !FileManager. default. fileExists ( atPath: lambdaPackage!) {
49
49
// I choose to report an error in the generated JSON.
@@ -57,9 +57,9 @@ public struct DeploymentDefinition {
57
57
// TODO: can we add code in `Plugin.swift` to force it to fail when such error is detected
58
58
lambdaPackage = " ### ERROR package does not exist: \( lambdaPackage!) ### "
59
59
}
60
-
60
+
61
61
// extract sqs resources to be created, if any
62
- additionalresources += self . explicitQueueResources ( function: function)
62
+ additionalresources += DeploymentDefinition . explicitQueueResources ( function: function)
63
63
64
64
return Resource . serverlessFunction ( name: function. name,
65
65
architecture: function. architecture,
@@ -77,7 +77,7 @@ public struct DeploymentDefinition {
77
77
// the event source eventually creates the queue resource and it returns a reference to the resource it has created
78
78
// This function collects all queue resources created by SQS event sources or passed by Lambda function developer
79
79
// to add them to the list of resources to synthetize
80
- private func explicitQueueResources( function: Function ) -> [ Resource ] {
80
+ private static func explicitQueueResources( function: Function ) -> [ Resource ] {
81
81
82
82
return function. eventSources
83
83
// first filter on event sources of type SQS where the `queue` property is defined (not nil)
@@ -93,10 +93,10 @@ public struct DeploymentDefinition {
93
93
if pretty {
94
94
encoder. outputFormatting = . prettyPrinted
95
95
}
96
- let jsonData = try ! encoder. encode ( self . deployment! )
96
+ let jsonData = try ! encoder. encode ( self . deployment)
97
97
return String ( data: jsonData, encoding: . utf8) !
98
98
}
99
-
99
+
100
100
}
101
101
102
102
// Intermediate structure to generate SAM Resources of type AWS::Serverless::Function
0 commit comments