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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ require (
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/inconshreveable/mousetrap v1.0.1
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/klauspost/compress v1.15.11
|
||||
github.com/klauspost/compress v1.15.12
|
||||
github.com/mattn/go-ieproxy v0.0.1
|
||||
github.com/mattn/go-isatty v0.0.16
|
||||
github.com/minio/cli v1.24.0
|
||||
@@ -21,7 +21,7 @@ require (
|
||||
github.com/minio/filepath v1.0.0
|
||||
github.com/minio/madmin-go v1.7.5
|
||||
github.com/minio/md5-simd v1.1.2 // indirect
|
||||
github.com/minio/minio-go/v7 v7.0.43
|
||||
github.com/minio/minio-go/v7 v7.0.44
|
||||
github.com/minio/pkg v1.5.4
|
||||
github.com/minio/selfupdate v0.5.0
|
||||
github.com/minio/sha256-simd v1.0.0
|
||||
@@ -34,7 +34,7 @@ require (
|
||||
github.com/rs/xid v1.4.0
|
||||
github.com/shirou/gopsutil/v3 v3.22.9
|
||||
github.com/tidwall/gjson v1.14.3
|
||||
golang.org/x/crypto v0.2.0
|
||||
golang.org/x/crypto v0.3.0
|
||||
golang.org/x/net v0.2.0
|
||||
golang.org/x/text v0.4.0
|
||||
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b
|
||||
@@ -70,7 +70,7 @@ require (
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/jedib0t/go-pretty/v6 v6.3.8
|
||||
github.com/klauspost/cpuid/v2 v2.1.2 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.1 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
|
||||
github.com/lestrrat-go/blackmagic v1.0.1 // indirect
|
||||
|
||||
@@ -432,13 +432,14 @@ github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
|
||||
github.com/klauspost/compress v1.15.11 h1:Lcadnb3RKGin4FYM/orgq0qde+nc15E5Cbqg4B9Sx9c=
|
||||
github.com/klauspost/compress v1.15.11/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
|
||||
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
|
||||
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
|
||||
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.1.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
|
||||
github.com/klauspost/cpuid/v2 v2.1.2 h1:XhdX4fqAJUA0yj+kUwMavO0hHrSPAecYdYf1ZmxHvak=
|
||||
github.com/klauspost/cpuid/v2 v2.1.2/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
|
||||
github.com/klauspost/cpuid/v2 v2.2.1 h1:U33DW0aiEj633gHYw3LoDNfkDiYnE5Q8M/TKJn2f2jI=
|
||||
github.com/klauspost/cpuid/v2 v2.2.1/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
|
||||
@@ -508,8 +509,8 @@ github.com/minio/madmin-go v1.7.5/go.mod h1:3SO8SROxHN++tF6QxdTii2SSUaYSrr8lnE9E
|
||||
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
|
||||
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
|
||||
github.com/minio/minio-go/v7 v7.0.41/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw=
|
||||
github.com/minio/minio-go/v7 v7.0.43 h1:14Q4lwblqTdlAmba05oq5xL0VBLHi06zS4yLnIkz6hI=
|
||||
github.com/minio/minio-go/v7 v7.0.43/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw=
|
||||
github.com/minio/minio-go/v7 v7.0.44 h1:9zUJ7iU7ax2P1jOvTp6nVrgzlZq3AZlFm0XfRFDKstM=
|
||||
github.com/minio/minio-go/v7 v7.0.44/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw=
|
||||
github.com/minio/pkg v1.5.4 h1:tP89j5EPym0C/kwacUm3NKgvpWEksDq2bVJJMQYLkmk=
|
||||
github.com/minio/pkg v1.5.4/go.mod h1:2MOaRFdmFKULD+uOLc3qHLGTQTuxCNPKNPfLBTxC8CA=
|
||||
github.com/minio/selfupdate v0.5.0 h1:0UH1HlL49+2XByhovKl5FpYTjKfvrQ2sgL1zEXK6mfI=
|
||||
@@ -731,8 +732,8 @@ golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.2.0 h1:BRXPfhNivWL5Yq0BGQ39a2sW6t44aODpfxkWjYdzewE=
|
||||
golang.org/x/crypto v0.2.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A=
|
||||
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
|
||||
Reference in New Issue
Block a user