-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from fujiwara/diff
Add diff subcommand
- Loading branch information
Showing
5 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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") | ||
} | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters