package decorator

import (
	"time"

	sparta "github.com/mweagle/Sparta"
	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() sparta.TemplateDecoratorHookFunc {
	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 {

		lambdaResName := sparta.CloudFormationResourceName("LambdaVersion",
			buildID,
			time.Now().UTC().String())
		versionResource := &gocf.LambdaVersion{
			FunctionName: gocf.GetAtt(lambdaResourceName, "Arn").String(),
		}
		lambdaVersionRes := template.AddResource(lambdaResName, versionResource)
		lambdaVersionRes.DeletionPolicy = "Retain"
		// That's it...
		return nil
	}
}

package decorator

import (
	"context"
	"time"

	sparta "github.com/mweagle/Sparta"
	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() sparta.TemplateDecoratorHookFunc {
	return func(ctx context.Context,
		serviceName string,
		lambdaResourceName string,
		lambdaResource gocf.LambdaFunction,
		resourceMetadata map[string]interface{},
		lambdaFunctionCode *gocf.LambdaFunctionCode,
		buildID string,
		template *gocf.Template,
		logger *logrus.Logger) (context.Context, error) {

		lambdaResName := sparta.CloudFormationResourceName("LambdaVersion",
			buildID,
			time.Now().UTC().String())
		versionResource := &gocf.LambdaVersion{
			FunctionName: gocf.GetAtt(lambdaResourceName, "Arn").String(),
		}
		lambdaVersionRes := template.AddResource(lambdaResName, versionResource)
		lambdaVersionRes.DeletionPolicy = "Retain"
		// That's it...
		return ctx, nil
	}
}

Update decorators to new signature
Update decorators to new signature
