diff --git a/CREDITS b/CREDITS index aece6082b..df67c3354 100644 --- a/CREDITS +++ b/CREDITS @@ -28435,6 +28435,39 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================================ +golang.org/x/exp +https://golang.org/x/exp +---------------------------------------------------------------- +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +================================================================ + golang.org/x/mod https://golang.org/x/mod ---------------------------------------------------------------- diff --git a/cmd/object-api-utils.go b/cmd/object-api-utils.go index 5a45366fc..8fc5be622 100644 --- a/cmd/object-api-utils.go +++ b/cmd/object-api-utils.go @@ -49,6 +49,7 @@ import ( "github.com/minio/minio/internal/logger" "github.com/minio/pkg/trie" "github.com/minio/pkg/wildcard" + "golang.org/x/exp/slices" ) const ( @@ -377,7 +378,7 @@ func removeStandardStorageClass(metadata map[string]string) map[string]string { func cleanMetadataKeys(metadata map[string]string, keyNames ...string) map[string]string { newMeta := make(map[string]string, len(metadata)) for k, v := range metadata { - if contains(keyNames, k) { + if slices.Contains(keyNames, k) { continue } newMeta[k] = v diff --git a/cmd/server-main.go b/cmd/server-main.go index e6321ccce..86ebfccfe 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -50,6 +50,7 @@ import ( "github.com/minio/minio/internal/logger" "github.com/minio/pkg/certs" "github.com/minio/pkg/env" + "golang.org/x/exp/slices" ) // ServerFlags - server command specific flags @@ -792,7 +793,7 @@ func serverMain(ctx *cli.Context) { } for _, v := range os.Environ() { // Do not print sensitive creds in debug. - if contains(ks, strings.Split(v, "=")[0]) { + if slices.Contains(ks, strings.Split(v, "=")[0]) { continue } logger.Info(v) diff --git a/cmd/signature-v4-utils.go b/cmd/signature-v4-utils.go index 9f7d949e7..c635583a0 100644 --- a/cmd/signature-v4-utils.go +++ b/cmd/signature-v4-utils.go @@ -31,6 +31,7 @@ import ( xhttp "github.com/minio/minio/internal/http" "github.com/minio/minio/internal/logger" iampolicy "github.com/minio/pkg/iam/policy" + "golang.org/x/exp/slices" ) // http Header "x-amz-content-sha256" == "UNSIGNED-PAYLOAD" indicates that the @@ -199,7 +200,7 @@ func extractSignedHeaders(signedHeaders []string, r *http.Request) (http.Header, reqQueries := r.Form // find whether "host" is part of list of signed headers. // if not return ErrUnsignedHeaders. "host" is mandatory. - if !contains(signedHeaders, "host") { + if !slices.Contains(signedHeaders, "host") { return nil, ErrUnsignedHeaders } extractedSignedHeaders := make(http.Header) diff --git a/cmd/utils.go b/cmd/utils.go index 3ba600313..fc7384e88 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -32,7 +32,6 @@ import ( "os" "path" "path/filepath" - "reflect" "runtime" "runtime/pprof" "runtime/trace" @@ -278,18 +277,6 @@ func isMaxPartID(partID int) bool { return partID > globalMaxPartID } -func contains(slice interface{}, elem interface{}) bool { - v := reflect.ValueOf(slice) - if v.Kind() == reflect.Slice { - for i := 0; i < v.Len(); i++ { - if v.Index(i).Interface() == elem { - return true - } - } - } - return false -} - // profilerWrapper is created becauses pkg/profiler doesn't // provide any API to calculate the profiler file path in the // disk since the name of this latter is randomly generated. diff --git a/cmd/utils_test.go b/cmd/utils_test.go index 463f12285..e788ca478 100644 --- a/cmd/utils_test.go +++ b/cmd/utils_test.go @@ -288,40 +288,6 @@ func TestToS3ETag(t *testing.T) { } } -// Test contains -func TestContains(t *testing.T) { - testErr := errors.New("test err") - - testCases := []struct { - slice interface{} - elem interface{} - found bool - }{ - {nil, nil, false}, - {"1", "1", false}, - {nil, "1", false}, - {[]string{"1"}, nil, false}, - {[]string{}, "1", false}, - {[]string{"1"}, "1", true}, - {[]string{"2"}, "1", false}, - {[]string{"1", "2"}, "1", true}, - {[]string{"2", "1"}, "1", true}, - {[]string{"2", "1", "3"}, "1", true}, - {[]int{1, 2, 3}, "1", false}, - {[]int{1, 2, 3}, 2, true}, - {[]int{1, 2, 3, 4, 5, 6}, 7, false}, - {[]error{errors.New("new err")}, testErr, false}, - {[]error{errors.New("new err"), testErr}, testErr, true}, - } - - for i, testCase := range testCases { - found := contains(testCase.slice, testCase.elem) - if found != testCase.found { - t.Fatalf("Test %v: expected: %v, got: %v", i+1, testCase.found, found) - } - } -} - // Test ceilFrac func TestCeilFrac(t *testing.T) { cases := []struct { diff --git a/go.mod b/go.mod index 05056cc69..d67f5f38f 100644 --- a/go.mod +++ b/go.mod @@ -88,6 +88,7 @@ require ( go.uber.org/zap v1.24.0 goftp.io/server/v2 v2.0.0 golang.org/x/crypto v0.9.0 + golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 golang.org/x/oauth2 v0.8.0 golang.org/x/sys v0.8.0 golang.org/x/time v0.3.0 diff --git a/go.sum b/go.sum index 1db1ff015..2937830d6 100644 --- a/go.sum +++ b/go.sum @@ -1179,6 +1179,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=