forked from fujiwara/lambroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff.go
57 lines (49 loc) · 1.38 KB
/
diff.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package lambroll
import (
"fmt"
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/kylelemons/godebug/diff"
"github.com/pkg/errors"
)
// DiffOption represents options for Diff()
type DiffOption struct {
FunctionFilePath *string
}
// Diff prints diff of function.json compared with latest function
func (app *App) Diff(opt DiffOption) error {
newFunc, err := app.loadFunction(*opt.FunctionFilePath)
if err != nil {
return errors.Wrap(err, "failed to load function")
}
fillDefaultValues(newFunc)
name := *newFunc.FunctionName
var latest *lambda.FunctionConfiguration
if res, err := app.lambda.GetFunction(&lambda.GetFunctionInput{
FunctionName: &name,
}); err != nil {
return errors.Wrapf(err, "failed to GetFunction %s", name)
} else {
latest = res.Configuration
}
arn := app.functionArn(name)
log.Printf("[debug] listing tags of %s", arn)
var tags Tags
if res, err := app.lambda.ListTags(&lambda.ListTagsInput{
Resource: aws.String(arn),
}); err != nil {
return errors.Wrap(err, "faled to list tags")
} else {
tags = res.Tags
}
latestFunc := newFuctionFrom(latest, tags)
latestJSON, _ := marshalJSON(latestFunc)
newJSON, _ := marshalJSON(newFunc)
if ds := diff.Diff(string(latestJSON), string(newJSON)); ds != "" {
fmt.Println("---", arn)
fmt.Println("+++", *opt.FunctionFilePath)
fmt.Println(ds)
}
return nil
}