Use NewArnFromString when parsing user-provided ARN string (#4378)
This commit is contained in:
+19
-22
@@ -38,9 +38,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/minio/mc/pkg/deadlineconn"
|
||||
"github.com/minio/mc/pkg/httptracer"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/minio/minio-go/v7/pkg/encrypt"
|
||||
@@ -48,11 +45,14 @@ import (
|
||||
"github.com/minio/minio-go/v7/pkg/notification"
|
||||
"github.com/minio/minio-go/v7/pkg/policy"
|
||||
"github.com/minio/minio-go/v7/pkg/replication"
|
||||
"github.com/minio/minio-go/v7/pkg/sse"
|
||||
|
||||
"github.com/minio/minio-go/v7/pkg/s3utils"
|
||||
"github.com/minio/minio-go/v7/pkg/sse"
|
||||
"github.com/minio/minio-go/v7/pkg/tags"
|
||||
"github.com/minio/pkg/mimedb"
|
||||
|
||||
"github.com/minio/mc/pkg/deadlineconn"
|
||||
"github.com/minio/mc/pkg/httptracer"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
// S3Client construct
|
||||
@@ -266,11 +266,12 @@ func (c *S3Client) GetURL() ClientURL {
|
||||
// AddNotificationConfig - Add bucket notification
|
||||
func (c *S3Client) AddNotificationConfig(ctx context.Context, arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
|
||||
bucket, _ := c.url2BucketAndObject()
|
||||
// Validate total fields in ARN.
|
||||
fields := strings.Split(arn, ":")
|
||||
if len(fields) != 6 {
|
||||
return errInvalidArgument()
|
||||
|
||||
accountArn, err := notification.NewArnFromString(arn)
|
||||
if err != nil {
|
||||
return probe.NewError(invalidArgumentErr(err)).Untrace()
|
||||
}
|
||||
nc := notification.NewConfig(accountArn)
|
||||
|
||||
// Get any enabled notification.
|
||||
mb, e := c.api.GetBucketNotification(ctx, bucket)
|
||||
@@ -278,9 +279,6 @@ func (c *S3Client) AddNotificationConfig(ctx context.Context, arn string, events
|
||||
return probe.NewError(e)
|
||||
}
|
||||
|
||||
accountArn := notification.NewArn(fields[1], fields[2], fields[3], fields[4], fields[5])
|
||||
nc := notification.NewConfig(accountArn)
|
||||
|
||||
// Configure events
|
||||
for _, event := range events {
|
||||
switch event {
|
||||
@@ -306,7 +304,7 @@ func (c *S3Client) AddNotificationConfig(ctx context.Context, arn string, events
|
||||
nc.AddFilterSuffix(suffix)
|
||||
}
|
||||
|
||||
switch fields[2] {
|
||||
switch accountArn.Service {
|
||||
case "sns":
|
||||
if !mb.AddTopic(nc) {
|
||||
return errInvalidArgument().Trace("Overlapping Topic configs")
|
||||
@@ -320,7 +318,7 @@ func (c *S3Client) AddNotificationConfig(ctx context.Context, arn string, events
|
||||
return errInvalidArgument().Trace("Overlapping lambda configs")
|
||||
}
|
||||
default:
|
||||
return errInvalidArgument().Trace(fields[2])
|
||||
return errInvalidArgument().Trace(accountArn.Service)
|
||||
}
|
||||
|
||||
// Set the new bucket configuration
|
||||
@@ -349,11 +347,10 @@ func (c *S3Client) RemoveNotificationConfig(ctx context.Context, arn string, eve
|
||||
return probe.NewError(e)
|
||||
}
|
||||
|
||||
fields := strings.Split(arn, ":")
|
||||
if len(fields) != 6 {
|
||||
return errInvalidArgument().Trace(fields...)
|
||||
accountArn, err := notification.NewArnFromString(arn)
|
||||
if err != nil {
|
||||
return probe.NewError(invalidArgumentErr(err)).Untrace()
|
||||
}
|
||||
accountArn := notification.NewArn(fields[1], fields[2], fields[3], fields[4], fields[5])
|
||||
|
||||
// if we are passed filters for either events, suffix or prefix, then only delete the single event that matches
|
||||
// the arguments
|
||||
@@ -380,7 +377,7 @@ func (c *S3Client) RemoveNotificationConfig(ctx context.Context, arn string, eve
|
||||
}
|
||||
var err error
|
||||
// based on the arn type, we'll look for the event in the corresponding sublist and delete it if there's a match
|
||||
switch fields[2] {
|
||||
switch accountArn.Service {
|
||||
case "sns":
|
||||
err = mb.RemoveTopicByArnEventsPrefixSuffix(accountArn, eventsTyped, prefix, suffix)
|
||||
case "sqs":
|
||||
@@ -388,7 +385,7 @@ func (c *S3Client) RemoveNotificationConfig(ctx context.Context, arn string, eve
|
||||
case "lambda":
|
||||
err = mb.RemoveLambdaByArnEventsPrefixSuffix(accountArn, eventsTyped, prefix, suffix)
|
||||
default:
|
||||
return errInvalidArgument().Trace(fields[2])
|
||||
return errInvalidArgument().Trace(accountArn.Service)
|
||||
}
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
@@ -396,7 +393,7 @@ func (c *S3Client) RemoveNotificationConfig(ctx context.Context, arn string, eve
|
||||
|
||||
} else {
|
||||
// remove all events for matching arn
|
||||
switch fields[2] {
|
||||
switch accountArn.Service {
|
||||
case "sns":
|
||||
mb.RemoveTopicByArn(accountArn)
|
||||
case "sqs":
|
||||
@@ -404,7 +401,7 @@ func (c *S3Client) RemoveNotificationConfig(ctx context.Context, arn string, eve
|
||||
case "lambda":
|
||||
mb.RemoveLambdaByArn(accountArn)
|
||||
default:
|
||||
return errInvalidArgument().Trace(fields[2])
|
||||
return errInvalidArgument().Trace(accountArn.Service)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user