added --dry-run

This commit is contained in:
Brad Rydzewski 2016-11-19 14:34:46 +01:00
parent 7e3a9e3888
commit 32492e4d02
4 changed files with 34 additions and 5 deletions

View File

@ -1,9 +1,6 @@
# drone-s3-sync
[![Build Status](http://beta.drone.io/api/badges/drone-plugins/drone-s3-sync/status.svg)](http://beta.drone.io/drone-plugins/drone-s3-sync)
[![Go Doc](https://godoc.org/github.com/drone-plugins/drone-s3-sync?status.svg)](http://godoc.org/github.com/drone-plugins/drone-s3-sync)
[![Go Report](https://goreportcard.com/badge/github.com/drone-plugins/drone-s3-sync)](https://goreportcard.com/report/github.com/drone-plugins/drone-s3-sync)
[![Join the chat at https://gitter.im/drone/drone](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/drone/drone)
Drone plugin to synchronize a directory with an Amazon S3 Bucket. For the
usage information and a listing of the available options please take a look at

29
aws.go
View File

@ -108,8 +108,8 @@ func (a *AWS) Upload(local, remote string) error {
Bucket: aws.String(p.Bucket),
Key: aws.String(remote),
})
if err != nil {
if err.(awserr.Error).Code() != "404" {
if err != nil && err.(awserr.Error).Code() != "404" {
if err.(awserr.Error).Code() == "404" {
return err
}
@ -131,6 +131,11 @@ func (a *AWS) Upload(local, remote string) error {
putObject.ContentEncoding = aws.String(contentEncoding)
}
// skip upload during dry run
if a.plugin.DryRun {
return nil
}
_, err = a.client.PutObject(putObject)
return err
}
@ -246,6 +251,11 @@ func (a *AWS) Upload(local, remote string) error {
copyObject.ContentEncoding = aws.String(contentEncoding)
}
// skip update if dry run
if a.plugin.DryRun {
return nil
}
_, err = a.client.CopyObject(copyObject)
return err
} else {
@ -272,6 +282,11 @@ func (a *AWS) Upload(local, remote string) error {
putObject.ContentEncoding = aws.String(contentEncoding)
}
// skip upload if dry run
if a.plugin.DryRun {
return nil
}
_, err = a.client.PutObject(putObject)
return err
}
@ -280,6 +295,11 @@ func (a *AWS) Upload(local, remote string) error {
func (a *AWS) Redirect(path, location string) error {
p := a.plugin
debug("Adding redirect from \"%s\" to \"%s\"", path, location)
if a.plugin.DryRun {
return nil
}
_, err := a.client.PutObject(&s3.PutObjectInput{
Bucket: aws.String(p.Bucket),
Key: aws.String(path),
@ -292,6 +312,11 @@ func (a *AWS) Redirect(path, location string) error {
func (a *AWS) Delete(remote string) error {
p := a.plugin
debug("Removing remote file \"%s\"", remote)
if a.plugin.DryRun {
return nil
}
_, err := a.client.DeleteObject(&s3.DeleteObjectInput{
Bucket: aws.String(p.Bucket),
Key: aws.String(remote),

View File

@ -97,6 +97,11 @@ func main() {
Usage: "id of cloudfront distribution to invalidate",
EnvVar: "PLUGIN_CLOUDFRONT_DISTRIBUTION",
},
cli.BoolFlag{
Name: "dry-run",
Usage: "dry run disables api calls",
EnvVar: "DRY_RUN,PLUGIN_DRY_RUN",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
@ -128,6 +133,7 @@ func run(c *cli.Context) error {
Metadata: c.Generic("metadata").(*DeepStringMapFlag).Get(),
Redirects: c.Generic("redirects").(*MapFlag).Get(),
CloudFrontDistribution: c.String("cloudfront-distribution"),
DryRun: c.Bool("dry-run"),
}
return plugin.Exec()

View File

@ -23,6 +23,7 @@ type Plugin struct {
Metadata map[string]map[string]string
Redirects map[string]string
CloudFrontDistribution string
DryRun bool
client AWS
jobs []job
}