From b5055451074b74e4464287275bc91798beca4305 Mon Sep 17 00:00:00 2001 From: Sean Zatz Date: Tue, 9 Apr 2024 15:13:43 +0000 Subject: [PATCH 1/4] Update test file manifest paths for e2e tests (cherry picked from commit f6f109169d6f23e250dc715e3a94332e222ae8fc) --- .../test/e2e/storage/testsuites/provisioning.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vendor/k8s.io/kubernetes/test/e2e/storage/testsuites/provisioning.go b/vendor/k8s.io/kubernetes/test/e2e/storage/testsuites/provisioning.go index 5a18638d2..1920124bd 100644 --- a/vendor/k8s.io/kubernetes/test/e2e/storage/testsuites/provisioning.go +++ b/vendor/k8s.io/kubernetes/test/e2e/storage/testsuites/provisioning.go @@ -255,9 +255,9 @@ func (p *provisioningTestSuite) DefineTests(driver storageframework.TestDriver, ginkgo.By("Deploying validator") valManifests := []string{ - "test/e2e/testing-manifests/storage-csi/any-volume-datasource/crd/populator.storage.k8s.io_volumepopulators.yaml", - "test/e2e/testing-manifests/storage-csi/any-volume-datasource/volume-data-source-validator/rbac-data-source-validator.yaml", - "test/e2e/testing-manifests/storage-csi/any-volume-datasource/volume-data-source-validator/setup-data-source-validator.yaml", + "vendor/k8s.io/kubernetes/test/e2e/testing-manifests/storage-csi/any-volume-datasource/crd/populator.storage.k8s.io_volumepopulators.yaml", + "vendor/k8s.io/kubernetes/test/e2e/testing-manifests/storage-csi/any-volume-datasource/volume-data-source-validator/rbac-data-source-validator.yaml", + "vendor/k8s.io/kubernetes/test/e2e/testing-manifests/storage-csi/any-volume-datasource/volume-data-source-validator/setup-data-source-validator.yaml", } valCleanup, err := storageutils.CreateFromManifests(f, valNamespace, func(item interface{}) error { return nil }, @@ -279,8 +279,8 @@ func (p *provisioningTestSuite) DefineTests(driver storageframework.TestDriver, ginkgo.By("Deploying hello-populator") popManifests := []string{ - "test/e2e/testing-manifests/storage-csi/any-volume-datasource/crd/hello-populator-crd.yaml", - "test/e2e/testing-manifests/storage-csi/any-volume-datasource/hello-populator-deploy.yaml", + "vendor/k8s.io/kubernetes/test/e2e/testing-manifests/storage-csi/any-volume-datasource/crd/hello-populator-crd.yaml", + "vendor/k8s.io/kubernetes/test/e2e/testing-manifests/storage-csi/any-volume-datasource/hello-populator-deploy.yaml", } popCleanup, err := storageutils.CreateFromManifests(f, popNamespace, func(item interface{}) error { From 2d2af3433034522cf517cfffafa1ad2944fdb51e Mon Sep 17 00:00:00 2001 From: Sean Zatz Date: Thu, 11 Apr 2024 21:09:01 +0000 Subject: [PATCH 2/4] Add script + instructions for in-place upgrade test. (cherry picked from commit 80715880a24e427df69e56ced7e2a778eff6a977) --- test/e2e/README.md | 54 +++++++++++++++++++ test/e2e/upgrade_driver_version.sh | 86 ++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100755 test/e2e/upgrade_driver_version.sh diff --git a/test/e2e/README.md b/test/e2e/README.md index 9836d44bb..8fef6a8a2 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -26,3 +26,57 @@ go test -v -timeout 0 ./... -report-dir=$ARTIFACTS -ginkgo.focus="\[efs-csi\]" - ``` The E2E flags that you can pass to `go test` are defined in [e2e_test.go](https://github.com/kubernetes-sigs/aws-efs-csi-driver/blob/master/test/e2e/e2e_test.go#L66-L75). + + +### Running Upgrade Test +In order to test upgrades from previous releases to the current development version of the driver, the following steps can be followed: + +1. Ensure the EFS CSI Driver is not currently deployed on your cluster. +2. Ensure that the EFS CSI Node and Controller service accounts are deployed on your cluster. Ex: +``` +$ cat ~/efs-service-account.yaml +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + app.kubernetes.io/name: aws-efs-csi-driver + name: efs-csi-controller-sa + namespace: kube-system + annotations: + eks.amazonaws.com/role-arn: arn:aws:iam::123456789:role/test-cluster-iam-sa-role +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + app.kubernetes.io/name: aws-efs-csi-driver + name: efs-csi-node-sa + namespace: kube-system + annotations: + eks.amazonaws.com/role-arn: arn:aws:iam::123456789:role/test-cluster-iam-sa-role + +$ kubectl apply -f ~/efs-service-account.yaml +``` +3. Run the upgrade script, for example: +```sh +# The release version of the driver you would like to test upgrading from. +# Pulls most recent image from the release-$PREV_RELEASE branch +PREV_RELEASE=1.7 +# Region of private ECR +REGION=us-east-1 +# Account of private ECR +ACCOUNT=123456789 +chmod +x ./upgrade_driver_version.sh +./upgrade_driver_version.sh $PREV_RELEASE $REGION $ACCOUNT +``` +4. Run the e2e tests, note that $REGION should be that of the EKS cluster. +```sh +export KUBECONFIG=$HOME/.kube/config +go test -v -timeout 0 ./... -report-dir=$ARTIFACTS -ginkgo.focus="\[efs-csi\]" -ginkgo.skip="\[Disruptive\]" \ + --file-system-id=$FS_ID --create-file-system=false --deploy-driver=false --region=$REGION +``` +5. Clean Up: The driver + kubernetes service accounts can be cleaned up via the following command: +```sh +kubectl delete -k github.com/kubernetes-sigs/aws-efs-csi-driver/deploy/kubernetes/overlays/stable/?ref=master +``` \ No newline at end of file diff --git a/test/e2e/upgrade_driver_version.sh b/test/e2e/upgrade_driver_version.sh new file mode 100755 index 000000000..c42569792 --- /dev/null +++ b/test/e2e/upgrade_driver_version.sh @@ -0,0 +1,86 @@ +#!/bin/sh +set -eux + +# Check for dependencies +if ! command -v kubectl &> /dev/null; then + echo "kubectl is not installed." + exit 1 +fi +if ! command -v docker &> /dev/null; then + echo "Docker is not installed." + exit 1 +fi +if ! command -v aws &> /dev/null; then + echo "AWS CLI is not installed." + exit 1 +fi + +prevRelease=$1 +region=$2 +account=$3 + +# The private ECR Repo is expected to take the following format: +# $account.dkr.ecr.$region.amazonaws.com/aws-efs-csi-driver +ecrRegistry="$account.dkr.ecr.$region.amazonaws.com" +ecrRepo="aws-efs-csi-driver" + +# Make temp folder for temp files +mkdir ./temp +publicDriverManifest="./temp/public-driver-manifest.yaml" + +# Build & push image of driver's development version +cd ../.. && make +aws ecr get-login-password --region $region | docker login --username AWS --password-stdin $ecrRegistry +docker build --pull --no-cache -t aws-efs-csi-driver . +docker tag aws-efs-csi-driver:latest $ecrRegistry/$ecrRepo:latest +docker push $ecrRegistry/$ecrRepo:latest +cd ./test/e2e + +# Download starting version manifest +kubectl kustomize \ + "github.com/kubernetes-sigs/aws-efs-csi-driver/deploy/kubernetes/overlays/stable/?ref=release-$prevRelease" > $publicDriverManifest + +# Remove the predefined service accounts +awk ' + /apiVersion: v1/ {recording=1} + recording && /app.kubernetes.io\/name: aws-efs-csi-driver/ {found=1} + recording && /name: efs-csi-controller-sa/ {controller_sa=1} + recording && /name: efs-csi-node-sa/ {node_sa=1} + recording && /---/ { + if (found && (controller_sa || node_sa)) { + recording=0; found=0; controller_sa=0; node_sa=0; next + } + } + !recording {print} +' $publicDriverManifest > ./temp/temp.yaml && mv ./temp/temp.yaml $publicDriverManifest + +# Deploy starting version of driver for the upgrade test +kubectl apply -f $publicDriverManifest + +# Tear down starting version +kubectl delete -f $publicDriverManifest + +# Create private manifest file & modify to use the private ecr repo +privateDriverManifest="./temp/private-driver-manifest.yaml" +kubectl kustomize \ + "github.com/kubernetes-sigs/aws-efs-csi-driver/deploy/kubernetes/overlays/stable/ecr/?ref=release-$prevRelease" > $privateDriverManifest + +sed -i -e "s|602401143452.dkr.ecr.us-west-2.amazonaws.com/eks/aws-efs-csi-driver:v[0-9]\+\.[0-9]\+\.[0-9]\+|$account.dkr.ecr.$region.amazonaws.com/aws-efs-csi-driver:latest|" $privateDriverManifest + +# Remove the predefined service accounts +awk ' + /apiVersion: v1/ {recording=1} + recording && /app.kubernetes.io\/name: aws-efs-csi-driver/ {found=1} + recording && /name: efs-csi-controller-sa/ {controller_sa=1} + recording && /name: efs-csi-node-sa/ {node_sa=1} + recording && /---/ { + if (found && (controller_sa || node_sa)) { + recording=0; found=0; controller_sa=0; node_sa=0; next + } + } + !recording {print} +' $privateDriverManifest > ./temp/temp.yaml && mv ./temp/temp.yaml $privateDriverManifest + +kubectl apply -f $privateDriverManifest + +rm -rf ./temp \ No newline at end of file From 399d525e59495378fb75feba5d61f937cd3c4bf2 Mon Sep 17 00:00:00 2001 From: Ryan Stankiewicz Date: Fri, 12 Apr 2024 19:47:21 +0000 Subject: [PATCH 3/4] Install Rust and Cargo for building efs-proxy Rust and Cargo are required to build efs-utils v2.0.0. I also a TODO to one of our integration tests - now that non-tls mounts are also re-directed to localhost (efs-utils v2), we need a new method of determining whether 'encryptInTransit' is working as expected. (cherry picked from commit f50335473e7b63d1d0541a5a79025808c904d26e) --- Dockerfile | 2 +- test/e2e/e2e.go | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 15b34de7c..71e10a507 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,7 +38,7 @@ RUN mkdir -p /tmp/rpms && \ then echo "Installing efs-utils from Amazon Linux 2 yum repo" && \ yum -y install --downloadonly --downloaddir=/tmp/rpms amazon-efs-utils-1.35.0-1.amzn2.noarch; \ else echo "Installing efs-utils from github using the latest git tag" && \ - yum -y install git rpm-build make && \ + yum -y install git rpm-build make rust cargo openssl-devel && \ git clone https://github.com/aws/efs-utils && \ cd efs-utils && \ git checkout $(git describe --tags $(git rev-list --tags --max-count=1)) && \ diff --git a/test/e2e/e2e.go b/test/e2e/e2e.go index 5a2df25c6..dd49b36fb 100644 --- a/test/e2e/e2e.go +++ b/test/e2e/e2e.go @@ -305,6 +305,11 @@ var _ = ginkgo.Describe("[efs-csi] EFS CSI", func() { }) testEncryptInTransit := func(f *framework.Framework, encryptInTransit *bool) { + // TODO [RyanStan 4-15-24] + // Now that non-tls mounts are re-directed to efs-proxy (efs-utils v2), + // we need a new method of determining whether encrypt in transit is correctly working. + // One way to do this could be to parse the arguments passed to efs-proxy and look for the '--tls' flag. + ginkgo.By("Creating efs pvc & pv") volumeAttributes := map[string]string{} if encryptInTransit != nil { @@ -320,20 +325,16 @@ var _ = ginkgo.Describe("[efs-csi] EFS CSI", func() { _ = f.ClientSet.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.Name, metav1.DeleteOptions{}) }() - // If mount.efs is passed option tls, the mount table entry should be... + // mount.efs connects the local NFS client to efs-proxy which listens on localhost and forwards NFS operations to EFS. + // This occurs for both non-tls and tls mounts. + // Therefore, the mount table entry should be // 127.0.0.1:/ on /mnt/volume1 type nfs4 (rw,relatime,vers=4.1,rsize=1048576,wsize=1048576,namlen=255,hard,noresvport,proto=tcp,port=20052,timeo=600,retrans=2,sec=sys,clientaddr=127.0.0.1,local_lock=none,addr=127.0.0.1) - // Note the tls option is not actually there. The proof that tls is passed - // to mount.efs is the server is 127.0.0.1 // (stunnel proxy running on localhost) // instead of the EFS DNS name // (file-system-id.efs.aws-region.amazonaws.com). // Call `mount` alone first to print it for debugging. + command := "mount && mount | grep /mnt/volume1 | grep 127.0.0.1" - if encryptInTransit != nil { - if !*encryptInTransit { - command = fmt.Sprintf("mount && mount | grep /mnt/volume1 | grep %v", FileSystemId) - } - } ginkgo.By(fmt.Sprintf("Creating pod to mount pvc %q and run %q", pvc.Name, command)) pod := e2epod.MakePod(f.Namespace.Name, nil, []*v1.PersistentVolumeClaim{pvc}, false, command) pod.Spec.RestartPolicy = v1.RestartPolicyNever From 7d61e03aa40a1f6c8c088f397e37c44d2d817736 Mon Sep 17 00:00:00 2001 From: Ryan Stankiewicz Date: Mon, 15 Apr 2024 15:49:00 +0000 Subject: [PATCH 4/4] Update go-restful dependency (cherry picked from commit 5a73a76d6fc1229a102161d5e59b74a3dc255c0c) --- go.mod | 2 +- go.sum | 4 ++ .../emicklei/go-restful/v3/CHANGES.md | 36 +++++++++++- .../emicklei/go-restful/v3/README.md | 7 +-- .../emicklei/go-restful/v3/compress.go | 10 ++++ .../emicklei/go-restful/v3/constants.go | 2 + .../go-restful/v3/entity_accessors.go | 7 +++ .../github.com/emicklei/go-restful/v3/json.go | 11 ---- .../emicklei/go-restful/v3/jsoniter.go | 12 ---- .../emicklei/go-restful/v3/jsr311.go | 2 +- .../emicklei/go-restful/v3/request.go | 5 +- .../emicklei/go-restful/v3/response.go | 3 + .../emicklei/go-restful/v3/route.go | 17 +++++- .../emicklei/go-restful/v3/route_builder.go | 55 ++++++++++++------- vendor/modules.txt | 2 +- 15 files changed, 118 insertions(+), 57 deletions(-) delete mode 100644 vendor/github.com/emicklei/go-restful/v3/json.go delete mode 100644 vendor/github.com/emicklei/go-restful/v3/jsoniter.go diff --git a/go.mod b/go.mod index 4b9fe290b..fb588b764 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/emicklei/go-restful/v3 v3.9.0 // indirect + github.com/emicklei/go-restful/v3 v3.12.0 // indirect github.com/evanphx/json-patch v4.12.0+incompatible // indirect github.com/felixge/httpsnoop v1.0.3 // indirect github.com/go-logr/logr v1.3.0 // indirect diff --git a/go.sum b/go.sum index 68e917243..6ce2b16dd 100644 --- a/go.sum +++ b/go.sum @@ -33,6 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -79,6 +81,8 @@ github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3 github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153 h1:yUdfgN0XgIJw7foRItutHYUIhlcKzcSf5vDpdhQAKTc= github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE= github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/emicklei/go-restful/v3 v3.12.0 h1:y2DdzBAURM29NFF94q6RaY4vjIH1rtwDapwQtU84iWk= +github.com/emicklei/go-restful/v3 v3.12.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= diff --git a/vendor/github.com/emicklei/go-restful/v3/CHANGES.md b/vendor/github.com/emicklei/go-restful/v3/CHANGES.md index 74a378157..9e790390b 100644 --- a/vendor/github.com/emicklei/go-restful/v3/CHANGES.md +++ b/vendor/github.com/emicklei/go-restful/v3/CHANGES.md @@ -1,10 +1,42 @@ # Change history of go-restful -## [v3.9.0] - 20221-07-21 + +## [v3.12.0] - 2024-03-11 +- add Flush method #529 (#538) +- fix: Improper handling of empty POST requests (#543) + +## [v3.11.3] - 2024-01-09 +- better not have 2 tags on one commit + +## [v3.11.1, v3.11.2] - 2024-01-09 + +- fix by restoring custom JSON handler functions (Mike Beaumont #540) + +## [v3.11.0] - 2023-08-19 + +- restored behavior as <= v3.9.0 with option to change path strategy using TrimRightSlashEnabled. + +## [v3.10.2] - 2023-03-09 - DO NOT USE + +- introduced MergePathStrategy to be able to revert behaviour of path concatenation to 3.9.0 + see comment in Readme how to customize this behaviour. + +## [v3.10.1] - 2022-11-19 - DO NOT USE + +- fix broken 3.10.0 by using path package for joining paths + +## [v3.10.0] - 2022-10-11 - BROKEN + +- changed tokenizer to match std route match behavior; do not trimright the path (#511) +- Add MIME_ZIP (#512) +- Add MIME_ZIP and HEADER_ContentDisposition (#513) +- Changed how to get query parameter issue #510 + +## [v3.9.0] - 2022-07-21 - add support for http.Handler implementations to work as FilterFunction, issue #504 (thanks to https://github.com/ggicci) -## [v3.8.0] - 20221-06-06 +## [v3.8.0] - 2022-06-06 - use exact matching of allowed domain entries, issue #489 (#493) - this changes fixes [security] Authorization Bypass Through User-Controlled Key diff --git a/vendor/github.com/emicklei/go-restful/v3/README.md b/vendor/github.com/emicklei/go-restful/v3/README.md index 0625359dc..7234604e4 100644 --- a/vendor/github.com/emicklei/go-restful/v3/README.md +++ b/vendor/github.com/emicklei/go-restful/v3/README.md @@ -2,7 +2,6 @@ go-restful ========== package for building REST-style Web Services using Google Go -[![Build Status](https://travis-ci.org/emicklei/go-restful.png)](https://travis-ci.org/emicklei/go-restful) [![Go Report Card](https://goreportcard.com/badge/github.com/emicklei/go-restful)](https://goreportcard.com/report/github.com/emicklei/go-restful) [![GoDoc](https://godoc.org/github.com/emicklei/go-restful?status.svg)](https://pkg.go.dev/github.com/emicklei/go-restful) [![codecov](https://codecov.io/gh/emicklei/go-restful/branch/master/graph/badge.svg)](https://codecov.io/gh/emicklei/go-restful) @@ -79,7 +78,7 @@ func (u UserResource) findUser(request *restful.Request, response *restful.Respo - Content encoding (gzip,deflate) of request and response payloads - Automatic responses on OPTIONS (using a filter) - Automatic CORS request handling (using a filter) -- API declaration for Swagger UI ([go-restful-openapi](https://github.com/emicklei/go-restful-openapi), see [go-restful-swagger12](https://github.com/emicklei/go-restful-swagger12)) +- API declaration for Swagger UI ([go-restful-openapi](https://github.com/emicklei/go-restful-openapi)) - Panic recovery to produce HTTP 500, customizable using RecoverHandler(...) - Route errors produce HTTP 404/405/406/415 errors, customizable using ServiceErrorHandler(...) - Configurable (trace) logging @@ -95,7 +94,7 @@ There are several hooks to customize the behavior of the go-restful package. - Trace logging - Compression - Encoders for other serializers -- Use [jsoniter](https://github.com/json-iterator/go) by building this package using a build tag, e.g. `go build -tags=jsoniter .` +- Use the package variable `TrimRightSlashEnabled` (default true) to control the behavior of matching routes that end with a slash `/` ## Resources @@ -108,4 +107,4 @@ There are several hooks to customize the behavior of the go-restful package. Type ```git shortlog -s``` for a full list of contributors. -© 2012 - 2022, http://ernestmicklei.com. MIT License. Contributions are welcome. +© 2012 - 2023, http://ernestmicklei.com. MIT License. Contributions are welcome. diff --git a/vendor/github.com/emicklei/go-restful/v3/compress.go b/vendor/github.com/emicklei/go-restful/v3/compress.go index 1ff239f99..80adf55fd 100644 --- a/vendor/github.com/emicklei/go-restful/v3/compress.go +++ b/vendor/github.com/emicklei/go-restful/v3/compress.go @@ -49,6 +49,16 @@ func (c *CompressingResponseWriter) CloseNotify() <-chan bool { return c.writer.(http.CloseNotifier).CloseNotify() } +// Flush is part of http.Flusher interface. Noop if the underlying writer doesn't support it. +func (c *CompressingResponseWriter) Flush() { + flusher, ok := c.writer.(http.Flusher) + if !ok { + // writer doesn't support http.Flusher interface + return + } + flusher.Flush() +} + // Close the underlying compressor func (c *CompressingResponseWriter) Close() error { if c.isCompressorClosed() { diff --git a/vendor/github.com/emicklei/go-restful/v3/constants.go b/vendor/github.com/emicklei/go-restful/v3/constants.go index 203439c5e..2328bde6c 100644 --- a/vendor/github.com/emicklei/go-restful/v3/constants.go +++ b/vendor/github.com/emicklei/go-restful/v3/constants.go @@ -7,12 +7,14 @@ package restful const ( MIME_XML = "application/xml" // Accept or Content-Type used in Consumes() and/or Produces() MIME_JSON = "application/json" // Accept or Content-Type used in Consumes() and/or Produces() + MIME_ZIP = "application/zip" // Accept or Content-Type used in Consumes() and/or Produces() MIME_OCTET = "application/octet-stream" // If Content-Type is not present in request, use the default HEADER_Allow = "Allow" HEADER_Accept = "Accept" HEADER_Origin = "Origin" HEADER_ContentType = "Content-Type" + HEADER_ContentDisposition = "Content-Disposition" HEADER_LastModified = "Last-Modified" HEADER_AcceptEncoding = "Accept-Encoding" HEADER_ContentEncoding = "Content-Encoding" diff --git a/vendor/github.com/emicklei/go-restful/v3/entity_accessors.go b/vendor/github.com/emicklei/go-restful/v3/entity_accessors.go index 66dfc824f..9808752ac 100644 --- a/vendor/github.com/emicklei/go-restful/v3/entity_accessors.go +++ b/vendor/github.com/emicklei/go-restful/v3/entity_accessors.go @@ -5,11 +5,18 @@ package restful // that can be found in the LICENSE file. import ( + "encoding/json" "encoding/xml" "strings" "sync" ) +var ( + MarshalIndent = json.MarshalIndent + NewDecoder = json.NewDecoder + NewEncoder = json.NewEncoder +) + // EntityReaderWriter can read and write values using an encoding such as JSON,XML. type EntityReaderWriter interface { // Read a serialized version of the value from the request. diff --git a/vendor/github.com/emicklei/go-restful/v3/json.go b/vendor/github.com/emicklei/go-restful/v3/json.go deleted file mode 100644 index 871165166..000000000 --- a/vendor/github.com/emicklei/go-restful/v3/json.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build !jsoniter - -package restful - -import "encoding/json" - -var ( - MarshalIndent = json.MarshalIndent - NewDecoder = json.NewDecoder - NewEncoder = json.NewEncoder -) diff --git a/vendor/github.com/emicklei/go-restful/v3/jsoniter.go b/vendor/github.com/emicklei/go-restful/v3/jsoniter.go deleted file mode 100644 index 11b8f8ae7..000000000 --- a/vendor/github.com/emicklei/go-restful/v3/jsoniter.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build jsoniter - -package restful - -import "github.com/json-iterator/go" - -var ( - json = jsoniter.ConfigCompatibleWithStandardLibrary - MarshalIndent = json.MarshalIndent - NewDecoder = json.NewDecoder - NewEncoder = json.NewEncoder -) diff --git a/vendor/github.com/emicklei/go-restful/v3/jsr311.go b/vendor/github.com/emicklei/go-restful/v3/jsr311.go index 07a0c91e9..a9b3faaa8 100644 --- a/vendor/github.com/emicklei/go-restful/v3/jsr311.go +++ b/vendor/github.com/emicklei/go-restful/v3/jsr311.go @@ -155,7 +155,7 @@ func (r RouterJSR311) detectRoute(routes []Route, httpRequest *http.Request) (*R method, length := httpRequest.Method, httpRequest.Header.Get("Content-Length") if (method == http.MethodPost || method == http.MethodPut || - method == http.MethodPatch) && length == "" { + method == http.MethodPatch) && (length == "" || length == "0") { return nil, NewError( http.StatusUnsupportedMediaType, fmt.Sprintf("415: Unsupported Media Type\n\nAvailable representations: %s", strings.Join(available, ", ")), diff --git a/vendor/github.com/emicklei/go-restful/v3/request.go b/vendor/github.com/emicklei/go-restful/v3/request.go index 5725a0759..0020095e8 100644 --- a/vendor/github.com/emicklei/go-restful/v3/request.go +++ b/vendor/github.com/emicklei/go-restful/v3/request.go @@ -31,7 +31,8 @@ func NewRequest(httpRequest *http.Request) *Request { // a "Unable to unmarshal content of type:" response is returned. // Valid values are restful.MIME_JSON and restful.MIME_XML // Example: -// restful.DefaultRequestContentType(restful.MIME_JSON) +// +// restful.DefaultRequestContentType(restful.MIME_JSON) func DefaultRequestContentType(mime string) { defaultRequestContentType = mime } @@ -48,7 +49,7 @@ func (r *Request) PathParameters() map[string]string { // QueryParameter returns the (first) Query parameter value by its name func (r *Request) QueryParameter(name string) string { - return r.Request.FormValue(name) + return r.Request.URL.Query().Get(name) } // QueryParameters returns the all the query parameters values by name diff --git a/vendor/github.com/emicklei/go-restful/v3/response.go b/vendor/github.com/emicklei/go-restful/v3/response.go index 8f0b56aa2..a41a92cc2 100644 --- a/vendor/github.com/emicklei/go-restful/v3/response.go +++ b/vendor/github.com/emicklei/go-restful/v3/response.go @@ -109,6 +109,9 @@ func (r *Response) EntityWriter() (EntityReaderWriter, bool) { if DefaultResponseMimeType == MIME_XML { return entityAccessRegistry.accessorAt(MIME_XML) } + if DefaultResponseMimeType == MIME_ZIP { + return entityAccessRegistry.accessorAt(MIME_ZIP) + } // Fallback to whatever the route says it can produce. // https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for _, each := range r.routeProduces { diff --git a/vendor/github.com/emicklei/go-restful/v3/route.go b/vendor/github.com/emicklei/go-restful/v3/route.go index 193f4a6b0..306c44be7 100644 --- a/vendor/github.com/emicklei/go-restful/v3/route.go +++ b/vendor/github.com/emicklei/go-restful/v3/route.go @@ -40,7 +40,8 @@ type Route struct { ParameterDocs []*Parameter ResponseErrors map[int]ResponseError DefaultResponse *ResponseError - ReadSample, WriteSample interface{} // structs that model an example request or response payload + ReadSample, WriteSample interface{} // structs that model an example request or response payload + WriteSamples []interface{} // if more than one return types is possible (oneof) then this will contain multiple values // Extra information used to store custom information about the route. Metadata map[string]interface{} @@ -164,7 +165,13 @@ func tokenizePath(path string) []string { if "/" == path { return nil } - return strings.Split(strings.Trim(path, "/"), "/") + if TrimRightSlashEnabled { + // 3.9.0 + return strings.Split(strings.Trim(path, "/"), "/") + } else { + // 3.10.2 + return strings.Split(strings.TrimLeft(path, "/"), "/") + } } // for debugging @@ -176,3 +183,9 @@ func (r *Route) String() string { func (r *Route) EnableContentEncoding(enabled bool) { r.contentEncodingEnabled = &enabled } + +// TrimRightSlashEnabled controls whether +// - path on route building is using path.Join +// - the path of the incoming request is trimmed of its slash suffux. +// Value of true matches the behavior of <= 3.9.0 +var TrimRightSlashEnabled = true diff --git a/vendor/github.com/emicklei/go-restful/v3/route_builder.go b/vendor/github.com/emicklei/go-restful/v3/route_builder.go index 23641b6dd..75168c12e 100644 --- a/vendor/github.com/emicklei/go-restful/v3/route_builder.go +++ b/vendor/github.com/emicklei/go-restful/v3/route_builder.go @@ -7,6 +7,7 @@ package restful import ( "fmt" "os" + "path" "reflect" "runtime" "strings" @@ -30,27 +31,29 @@ type RouteBuilder struct { typeNameHandleFunc TypeNameHandleFunction // required // documentation - doc string - notes string - operation string - readSample, writeSample interface{} - parameters []*Parameter - errorMap map[int]ResponseError - defaultResponse *ResponseError - metadata map[string]interface{} - extensions map[string]interface{} - deprecated bool - contentEncodingEnabled *bool + doc string + notes string + operation string + readSample interface{} + writeSamples []interface{} + parameters []*Parameter + errorMap map[int]ResponseError + defaultResponse *ResponseError + metadata map[string]interface{} + extensions map[string]interface{} + deprecated bool + contentEncodingEnabled *bool } // Do evaluates each argument with the RouteBuilder itself. // This allows you to follow DRY principles without breaking the fluent programming style. // Example: -// ws.Route(ws.DELETE("/{name}").To(t.deletePerson).Do(Returns200, Returns500)) // -// func Returns500(b *RouteBuilder) { -// b.Returns(500, "Internal Server Error", restful.ServiceError{}) -// } +// ws.Route(ws.DELETE("/{name}").To(t.deletePerson).Do(Returns200, Returns500)) +// +// func Returns500(b *RouteBuilder) { +// b.Returns(500, "Internal Server Error", restful.ServiceError{}) +// } func (b *RouteBuilder) Do(oneArgBlocks ...func(*RouteBuilder)) *RouteBuilder { for _, each := range oneArgBlocks { each(b) @@ -133,9 +136,9 @@ func (b RouteBuilder) ParameterNamed(name string) (p *Parameter) { return p } -// Writes tells what resource type will be written as the response payload. Optional. -func (b *RouteBuilder) Writes(sample interface{}) *RouteBuilder { - b.writeSample = sample +// Writes tells which one of the resource types will be written as the response payload. Optional. +func (b *RouteBuilder) Writes(samples ...interface{}) *RouteBuilder { + b.writeSamples = samples // oneof return b } @@ -340,19 +343,29 @@ func (b *RouteBuilder) Build() Route { ResponseErrors: b.errorMap, DefaultResponse: b.defaultResponse, ReadSample: b.readSample, - WriteSample: b.writeSample, + WriteSamples: b.writeSamples, Metadata: b.metadata, Deprecated: b.deprecated, contentEncodingEnabled: b.contentEncodingEnabled, allowedMethodsWithoutContentType: b.allowedMethodsWithoutContentType, } + // set WriteSample if one specified + if len(b.writeSamples) == 1 { + route.WriteSample = b.writeSamples[0] + } route.Extensions = b.extensions route.postBuild() return route } -func concatPath(path1, path2 string) string { - return strings.TrimRight(path1, "/") + "/" + strings.TrimLeft(path2, "/") +// merge two paths using the current (package global) merge path strategy. +func concatPath(rootPath, routePath string) string { + + if TrimRightSlashEnabled { + return strings.TrimRight(rootPath, "/") + "/" + strings.TrimLeft(routePath, "/") + } else { + return path.Join(rootPath, routePath) + } } var anonymousFuncCount int32 diff --git a/vendor/modules.txt b/vendor/modules.txt index f11c0ad79..f2c88c9d6 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -65,7 +65,7 @@ github.com/davecgh/go-spew/spew ## explicit github.com/docker/distribution/digestset github.com/docker/distribution/reference -# github.com/emicklei/go-restful/v3 v3.9.0 +# github.com/emicklei/go-restful/v3 v3.12.0 ## explicit; go 1.13 github.com/emicklei/go-restful/v3 github.com/emicklei/go-restful/v3/log