From a38ae11fe6420e2b65dbdb4f4582306e7374913a Mon Sep 17 00:00:00 2001 From: Nick Cabatoff Date: Thu, 10 Dec 2020 10:09:21 -0500 Subject: [PATCH] Fail build if go mod vendor changes anything. (#10524) --- .circleci/config.yml | 39 +++++++++++++++ .circleci/config/jobs/go-mod-vendor.yml | 11 ++++ .circleci/config/workflows/ci.yml | 3 ++ go.mod | 1 + .../hashicorp/vault/api/sys_config_cors.go | 50 ++++--------------- 5 files changed, 63 insertions(+), 41 deletions(-) create mode 100644 .circleci/config/jobs/go-mod-vendor.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index 07f76fa7ef..b570b8392a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1988,6 +1988,42 @@ jobs: name: Install CircleCI CLI - run: command: make ci-verify + go-mod-vendor: + machine: true + shell: /usr/bin/env bash -euo pipefail -c + working_directory: /go/src/github.com/hashicorp/vault + steps: + - run: + command: | + [ -n "$GO_VERSION" ] || { echo "You must set GO_VERSION"; exit 1; } + # Install Go + curl -sSLO "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" + sudo rm -rf /usr/local/go + sudo tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz" + rm -f "go${GO_VERSION}.linux-amd64.tar.gz" + GOPATH="/go" + mkdir $GOPATH 2>/dev/null || { sudo mkdir $GOPATH && sudo chmod 777 $GOPATH; } + echo "export GOPATH='$GOPATH'" >> "$BASH_ENV" + echo "export PATH='$PATH:$GOPATH/bin:/usr/local/go/bin'" >> "$BASH_ENV" + + echo "$ go version" + go version + name: Setup Go + working_directory: ~/ + - checkout + - attach_workspace: + at: . + - run: + command: | + GO111MODULE=on go mod vendor + git diff --exit-code + name: Run go mod vendor + environment: + - CIRCLECI_CLI_VERSION: 0.1.5546 + - GO_TAGS: '' + - GO_VERSION: 1.15.3 + - GO111MODULE: 'off' + - GOTESTSUM_VERSION: 0.5.2 test-go-race-remote-docker: docker: - image: docker.mirror.hashicorp.services/circleci/golang:1.15.3-buster @@ -2194,6 +2230,9 @@ workflows: - build-go-dev: requires: - pre-flight-checks + - go-mod-vendor: + requires: + - pre-flight-checks - test-ui: requires: - install-ui-dependencies diff --git a/.circleci/config/jobs/go-mod-vendor.yml b/.circleci/config/jobs/go-mod-vendor.yml new file mode 100644 index 0000000000..ee51bee37a --- /dev/null +++ b/.circleci/config/jobs/go-mod-vendor.yml @@ -0,0 +1,11 @@ +executor: go-machine +steps: + - setup-go + - checkout + - attach_workspace: + at: . + - run: + name: Run go mod vendor + command: | + GO111MODULE=on go mod vendor + git diff --exit-code diff --git a/.circleci/config/workflows/ci.yml b/.circleci/config/workflows/ci.yml index 30c4231bc9..c9d8238efa 100644 --- a/.circleci/config/workflows/ci.yml +++ b/.circleci/config/workflows/ci.yml @@ -6,6 +6,9 @@ jobs: - build-go-dev: requires: - pre-flight-checks + - go-mod-vendor: + requires: + - pre-flight-checks - test-ui: requires: - install-ui-dependencies diff --git a/go.mod b/go.mod index 3466efe059..a6092a9875 100644 --- a/go.mod +++ b/go.mod @@ -122,6 +122,7 @@ require ( github.com/oklog/run v1.0.0 github.com/okta/okta-sdk-golang/v2 v2.0.0 github.com/oracle/oci-go-sdk v12.5.0+incompatible + github.com/ory/dockertest v3.3.5+incompatible github.com/ory/dockertest/v3 v3.6.2 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect diff --git a/vendor/github.com/hashicorp/vault/api/sys_config_cors.go b/vendor/github.com/hashicorp/vault/api/sys_config_cors.go index cf0c8d8b5e..ef136dcbb6 100644 --- a/vendor/github.com/hashicorp/vault/api/sys_config_cors.go +++ b/vendor/github.com/hashicorp/vault/api/sys_config_cors.go @@ -35,63 +35,31 @@ func (c *Sys) CORSStatus() (*CORSResponse, error) { return &result, err } -func (c *Sys) ConfigureCORS(req *CORSRequest) (*CORSResponse, error) { +func (c *Sys) ConfigureCORS(req *CORSRequest) error { r := c.c.NewRequest("PUT", "/v1/sys/config/cors") if err := r.SetJSONBody(req); err != nil { - return nil, err + return err } ctx, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() resp, err := c.c.RawRequestWithContext(ctx, r) - if err != nil { - return nil, err + if err == nil { + defer resp.Body.Close() } - defer resp.Body.Close() - - secret, err := ParseSecret(resp.Body) - if err != nil { - return nil, err - } - if secret == nil || secret.Data == nil { - return nil, errors.New("data from server response is empty") - } - - var result CORSResponse - err = mapstructure.Decode(secret.Data, &result) - if err != nil { - return nil, err - } - - return &result, err + return err } -func (c *Sys) DisableCORS() (*CORSResponse, error) { +func (c *Sys) DisableCORS() error { r := c.c.NewRequest("DELETE", "/v1/sys/config/cors") ctx, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() resp, err := c.c.RawRequestWithContext(ctx, r) - if err != nil { - return nil, err + if err == nil { + defer resp.Body.Close() } - defer resp.Body.Close() - - secret, err := ParseSecret(resp.Body) - if err != nil { - return nil, err - } - if secret == nil || secret.Data == nil { - return nil, errors.New("data from server response is empty") - } - - var result CORSResponse - err = mapstructure.Decode(secret.Data, &result) - if err != nil { - return nil, err - } - - return &result, err + return err } type CORSRequest struct {