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:
committed by
kannappanr
parent
7c454d8f94
commit
9a25e66e87
@@ -230,7 +230,7 @@ func (c *s3Client) GetURL() clientURL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add bucket notification
|
// 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()
|
bucket, _ := c.url2BucketAndObject()
|
||||||
// Validate total fields in ARN.
|
// Validate total fields in ARN.
|
||||||
fields := strings.Split(arn, ":")
|
fields := strings.Split(arn, ":")
|
||||||
@@ -286,6 +286,9 @@ func (c *s3Client) AddNotificationConfig(arn string, events []string, prefix, su
|
|||||||
|
|
||||||
// Set the new bucket configuration
|
// Set the new bucket configuration
|
||||||
if err := c.api.SetBucketNotification(bucket, mb); err != nil {
|
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 probe.NewError(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ var (
|
|||||||
Name: "suffix",
|
Name: "suffix",
|
||||||
Usage: "filter event associated to the specified 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}}{{.}}
|
{{range .VisibleFlags}}{{.}}
|
||||||
{{end}}
|
{{end}}
|
||||||
EXAMPLES:
|
EXAMPLES:
|
||||||
1. Enable bucket notification with a specific arn
|
1. Enable bucket notification with a specific arn
|
||||||
$ {{.HelpName}} myminio/mybucket arn:aws:sqs:us-west-2:444455556666:your-queue
|
$ {{.HelpName}} myminio/mybucket arn:aws:sqs:us-west-2:444455556666:your-queue
|
||||||
|
|
||||||
2. Enable bucket notification with filters parameters
|
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
|
$ {{.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()
|
args := ctx.Args()
|
||||||
path := args[0]
|
path := args[0]
|
||||||
arn := args[1]
|
arn := args[1]
|
||||||
|
ignoreExisting := ctx.Bool("p")
|
||||||
|
|
||||||
event := strings.Split(ctx.String("event"), ",")
|
event := strings.Split(ctx.String("event"), ",")
|
||||||
prefix := ctx.String("prefix")
|
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.")
|
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.")
|
fatalIf(err, "Cannot enable notification on the specified bucket.")
|
||||||
printMsg(eventAddMessage{
|
printMsg(eventAddMessage{
|
||||||
ARN: arn,
|
ARN: arn,
|
||||||
|
|||||||
@@ -897,6 +897,7 @@ COMMANDS:
|
|||||||
list list bucket notifications
|
list list bucket notifications
|
||||||
|
|
||||||
FLAGS:
|
FLAGS:
|
||||||
|
--ignore-existing, -p ignore if event already exists
|
||||||
--help, -h show help
|
--help, -h show help
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user