forked from mweagle/Sparta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversioning.go
39 lines (37 loc) · 1.17 KB
/
versioning.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package sparta
import (
spartaCF "github.com/mweagle/Sparta/aws/cloudformation"
gocf "github.com/mweagle/go-cloudformation"
"github.com/sirupsen/logrus"
)
// LambdaVersioningDecorator returns a TemplateDecorator
// that is responsible for including a versioning resource
// with the given lambda function
func LambdaVersioningDecorator() TemplateDecorator {
return func(serviceName string,
lambdaResourceName string,
lambdaResource gocf.LambdaFunction,
resourceMetadata map[string]interface{},
S3Bucket string,
S3Key string,
buildID string,
template *gocf.Template,
context map[string]interface{},
logger *logrus.Logger) error {
incrementer, incrementerErr :=
spartaCF.AddAutoIncrementingLambdaVersionResource(serviceName,
lambdaResourceName,
template,
logger)
if incrementerErr != nil {
return nil
}
versionsMap, versionsMapExists := context[ContextKeyLambdaVersions].(map[string]*spartaCF.AutoIncrementingLambdaVersionInfo)
if !versionsMapExists {
versionsMap = make(map[string]*spartaCF.AutoIncrementingLambdaVersionInfo)
}
versionsMap[lambdaResourceName] = incrementer
context[ContextKeyLambdaVersions] = versionsMap
return nil
}
}