From 9a25e66e87ec61a4e53ca38185736e23ec59f2ac Mon Sep 17 00:00:00 2001 From: Ashish Kumar Sinha Date: Tue, 16 Jul 2019 15:10:06 +0530 Subject: [PATCH] Add --ignore-existing/-p flag in mc event add command (#2773) If the event is already present the server throws an error. With the --ignore-existing/ -p flag these error messages are discarded --- cmd/client-s3.go | 5 ++++- cmd/event-add.go | 18 +++++++++++++----- docs/minio-client-complete-guide.md | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cmd/client-s3.go b/cmd/client-s3.go index 3be8d61d..1590b4ed 100644 --- a/cmd/client-s3.go +++ b/cmd/client-s3.go @@ -230,7 +230,7 @@ func (c *s3Client) GetURL() clientURL { } // Add bucket notification -func (c *s3Client) AddNotificationConfig(arn string, events []string, prefix, suffix string) *probe.Error { +func (c *s3Client) AddNotificationConfig(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error { bucket, _ := c.url2BucketAndObject() // Validate total fields in ARN. fields := strings.Split(arn, ":") @@ -286,6 +286,9 @@ func (c *s3Client) AddNotificationConfig(arn string, events []string, prefix, su // Set the new bucket configuration if err := c.api.SetBucketNotification(bucket, mb); err != nil { + if ignoreExisting && strings.Contains(err.Error(), "An object key name filtering rule defined with overlapping prefixes, overlapping suffixes, or overlapping combinations of prefixes and suffixes for the same event types") { + return nil + } return probe.NewError(err) } return nil diff --git a/cmd/event-add.go b/cmd/event-add.go index c4348bd4..988d6449 100644 --- a/cmd/event-add.go +++ b/cmd/event-add.go @@ -41,6 +41,10 @@ var ( Name: "suffix", Usage: "filter event associated to the specified suffix", }, + cli.BoolFlag{ + Name: "ignore-existing, p", + Usage: "ignore if event already exists", + }, } ) @@ -60,11 +64,14 @@ FLAGS: {{range .VisibleFlags}}{{.}} {{end}} EXAMPLES: - 1. Enable bucket notification with a specific arn - $ {{.HelpName}} myminio/mybucket arn:aws:sqs:us-west-2:444455556666:your-queue + 1. Enable bucket notification with a specific arn + $ {{.HelpName}} myminio/mybucket arn:aws:sqs:us-west-2:444455556666:your-queue - 2. Enable bucket notification with filters parameters - $ {{.HelpName}} s3/mybucket arn:aws:sqs:us-west-2:444455556666:your-queue --event put,delete,get --prefix photos/ --suffix .jpg + 2. Enable bucket notification with filters parameters + $ {{.HelpName}} s3/mybucket arn:aws:sqs:us-west-2:444455556666:your-queue --event put,delete,get --prefix photos/ --suffix .jpg + + 3. Ignore duplicate bucket notification with -p flag + $ {{.HelpName}} s3/mybucket arn:aws:sqs:us-west-2:444455556666:your-queue -p --event put,delete,get --prefix photos/ --suffix .jpg `, } @@ -105,6 +112,7 @@ func mainEventAdd(ctx *cli.Context) error { args := ctx.Args() path := args[0] arn := args[1] + ignoreExisting := ctx.Bool("p") event := strings.Split(ctx.String("event"), ",") prefix := ctx.String("prefix") @@ -120,7 +128,7 @@ func mainEventAdd(ctx *cli.Context) error { fatalIf(errDummy().Trace(), "The provided url doesn't point to a S3 server.") } - err = s3Client.AddNotificationConfig(arn, event, prefix, suffix) + err = s3Client.AddNotificationConfig(arn, event, prefix, suffix, ignoreExisting) fatalIf(err, "Cannot enable notification on the specified bucket.") printMsg(eventAddMessage{ ARN: arn, diff --git a/docs/minio-client-complete-guide.md b/docs/minio-client-complete-guide.md index 32a650c1..d6c630ea 100644 --- a/docs/minio-client-complete-guide.md +++ b/docs/minio-client-complete-guide.md @@ -897,6 +897,7 @@ COMMANDS: list list bucket notifications FLAGS: + --ignore-existing, -p ignore if event already exists --help, -h show help ```