1
0
mirror of https://github.com/minio/mc.git synced 2025-11-12 01:02:26 +03:00

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
This commit is contained in:
Ashish Kumar Sinha
2019-07-16 15:10:06 +05:30
committed by kannappanr
parent 7c454d8f94
commit 9a25e66e87
3 changed files with 18 additions and 6 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -897,6 +897,7 @@ COMMANDS:
list list bucket notifications
FLAGS:
--ignore-existing, -p ignore if event already exists
--help, -h show help
```