From a7df948f10e3b0530298a3c7598b4d940680152c Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Wed, 12 Jan 2022 16:42:55 -0800 Subject: [PATCH] Merge pull request #11833 from hashicorp/deps-go-getter-v1.5.11 deps: update go-getter to v1.5.11 --- go.mod | 2 +- go.sum | 4 +- .../github.com/hashicorp/go-getter/.gitignore | 1 + .../hashicorp/go-getter/.goreleaser.yml | 10 ++- .../github.com/hashicorp/go-getter/client.go | 2 +- .../hashicorp/go-getter/decompress.go | 2 + .../hashicorp/go-getter/decompress_tar.go | 6 +- .../github.com/hashicorp/go-getter/get_gcs.go | 25 +++++++- .../github.com/hashicorp/go-getter/get_git.go | 61 +++++++++++++++++-- .../github.com/hashicorp/go-getter/get_s3.go | 10 ++- vendor/github.com/hashicorp/go-getter/go.mod | 1 + vendor/github.com/hashicorp/go-getter/go.sum | 4 -- vendor/github.com/hashicorp/go-getter/url.go | 25 ++++++++ vendor/modules.txt | 2 +- 14 files changed, 133 insertions(+), 22 deletions(-) create mode 100644 vendor/github.com/hashicorp/go-getter/.gitignore create mode 100644 vendor/github.com/hashicorp/go-getter/url.go diff --git a/go.mod b/go.mod index 5d05ac4c3fc..00519355e21 100644 --- a/go.mod +++ b/go.mod @@ -61,7 +61,7 @@ require ( github.com/hashicorp/go-cty-funcs v0.0.0-20200930094925-2721b1e36840 github.com/hashicorp/go-discover v0.0.0-20200812215701-c4b85f6ed31f github.com/hashicorp/go-envparse v0.0.0-20180119215841-310ca1881b22 - github.com/hashicorp/go-getter v1.5.4 + github.com/hashicorp/go-getter v1.5.11 github.com/hashicorp/go-hclog v0.14.1 github.com/hashicorp/go-immutable-radix v1.3.0 github.com/hashicorp/go-memdb v1.3.2 diff --git a/go.sum b/go.sum index 4756c79dfa9..45d964bab40 100644 --- a/go.sum +++ b/go.sum @@ -363,8 +363,8 @@ github.com/hashicorp/go-envparse v0.0.0-20180119215841-310ca1881b22 h1:HTmDIaSN9 github.com/hashicorp/go-envparse v0.0.0-20180119215841-310ca1881b22/go.mod h1:/NlxCzN2D4C4L2uDE6ux/h6jM+n98VFQM14nnCIfHJU= github.com/hashicorp/go-gatedio v0.5.0 h1:Jm1X5yP4yCqqWj5L1TgW7iZwCVPGtVc+mro5r/XX7Tg= github.com/hashicorp/go-gatedio v0.5.0/go.mod h1:Lr3t8L6IyxD3DAeaUxGcgl2JnRUpWMCsmBl4Omu/2t4= -github.com/hashicorp/go-getter v1.5.4 h1:/A0xlardcuhx8SEe1rh1371xV7Yi4j3xeluu53VXeyg= -github.com/hashicorp/go-getter v1.5.4/go.mod h1:BrrV/1clo8cCYu6mxvboYg+KutTiFnXjMEgDD8+i7ZI= +github.com/hashicorp/go-getter v1.5.11 h1:wioTuNmaBU3IE9vdFtFMcmZWj0QzLc6DYaP6sNe5onY= +github.com/hashicorp/go-getter v1.5.11/go.mod h1:9i48BP6wpWweI/0/+FBjqLrp9S8XtwUGjiu0QkWHEaY= github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= github.com/hashicorp/go-hclog v0.8.0/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= diff --git a/vendor/github.com/hashicorp/go-getter/.gitignore b/vendor/github.com/hashicorp/go-getter/.gitignore new file mode 100644 index 00000000000..511ca2675b1 --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/.gitignore @@ -0,0 +1 @@ +cmd/go-getter/go-getter diff --git a/vendor/github.com/hashicorp/go-getter/.goreleaser.yml b/vendor/github.com/hashicorp/go-getter/.goreleaser.yml index e23ee051fb6..975b5f697c7 100644 --- a/vendor/github.com/hashicorp/go-getter/.goreleaser.yml +++ b/vendor/github.com/hashicorp/go-getter/.goreleaser.yml @@ -43,7 +43,15 @@ checksum: algorithm: sha256 signs: - - args: ["-u", "{{ .Env.PGP_KEY_ID }}", "--output", "${signature}", "--detach-sign", "${artifact}"] + - signature: ${artifact}.sig + cmd: sh + args: + - -c + - >- + signore + sign + --file ${artifact} + --out ${signature} artifacts: checksum changelog: diff --git a/vendor/github.com/hashicorp/go-getter/client.go b/vendor/github.com/hashicorp/go-getter/client.go index d531c2a772d..5817d73844e 100644 --- a/vendor/github.com/hashicorp/go-getter/client.go +++ b/vendor/github.com/hashicorp/go-getter/client.go @@ -298,7 +298,7 @@ func (c *Client) Get() error { // if we're specifying a subdir. err := g.Get(dst, u) if err != nil { - err = fmt.Errorf("error downloading '%s': %s", u.Redacted(), err) + err = fmt.Errorf("error downloading '%s': %s", RedactURL(u), err) return err } } diff --git a/vendor/github.com/hashicorp/go-getter/decompress.go b/vendor/github.com/hashicorp/go-getter/decompress.go index d0ad4390036..9db9e15c081 100644 --- a/vendor/github.com/hashicorp/go-getter/decompress.go +++ b/vendor/github.com/hashicorp/go-getter/decompress.go @@ -23,6 +23,7 @@ type Decompressor interface { var Decompressors map[string]Decompressor func init() { + tarDecompressor := new(TarDecompressor) tbzDecompressor := new(TarBzip2Decompressor) tgzDecompressor := new(TarGzipDecompressor) txzDecompressor := new(TarXzDecompressor) @@ -32,6 +33,7 @@ func init() { "bz2": new(Bzip2Decompressor), "gz": new(GzipDecompressor), "xz": new(XzDecompressor), + "tar": tarDecompressor, "tar.bz2": tbzDecompressor, "tar.gz": tgzDecompressor, "tar.xz": txzDecompressor, diff --git a/vendor/github.com/hashicorp/go-getter/decompress_tar.go b/vendor/github.com/hashicorp/go-getter/decompress_tar.go index 4b58b036a16..ee1d29ca960 100644 --- a/vendor/github.com/hashicorp/go-getter/decompress_tar.go +++ b/vendor/github.com/hashicorp/go-getter/decompress_tar.go @@ -125,11 +125,11 @@ func untar(input io.Reader, dst, src string, dir bool, umask os.FileMode) error return nil } -// tarDecompressor is an implementation of Decompressor that can +// TarDecompressor is an implementation of Decompressor that can // unpack tar files. -type tarDecompressor struct{} +type TarDecompressor struct{} -func (d *tarDecompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error { +func (d *TarDecompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error { // If we're going into a directory we should make that first mkdir := dst if !dir { diff --git a/vendor/github.com/hashicorp/go-getter/get_gcs.go b/vendor/github.com/hashicorp/go-getter/get_gcs.go index 4f2172b24cc..678f9e68584 100644 --- a/vendor/github.com/hashicorp/go-getter/get_gcs.go +++ b/vendor/github.com/hashicorp/go-getter/get_gcs.go @@ -3,6 +3,8 @@ package getter import ( "context" "fmt" + "golang.org/x/oauth2" + "google.golang.org/api/option" "net/url" "os" "path/filepath" @@ -28,7 +30,7 @@ func (g *GCSGetter) ClientMode(u *url.URL) (ClientMode, error) { return 0, err } - client, err := storage.NewClient(ctx) + client, err := g.getClient(ctx) if err != nil { return 0, err } @@ -82,7 +84,7 @@ func (g *GCSGetter) Get(dst string, u *url.URL) error { return err } - client, err := storage.NewClient(ctx) + client, err := g.getClient(ctx) if err != nil { return err } @@ -124,7 +126,7 @@ func (g *GCSGetter) GetFile(dst string, u *url.URL) error { return err } - client, err := storage.NewClient(ctx) + client, err := g.getClient(ctx) if err != nil { return err } @@ -175,3 +177,20 @@ func (g *GCSGetter) parseURL(u *url.URL) (bucket, path, fragment string, err err } return } + +func (g *GCSGetter) getClient(ctx context.Context) (client *storage.Client, err error) { + var opts []option.ClientOption + + if v, ok := os.LookupEnv("GOOGLE_OAUTH_ACCESS_TOKEN"); ok { + tokenSource := oauth2.StaticTokenSource(&oauth2.Token{ + AccessToken: v, + }) + opts = append(opts, option.WithTokenSource(tokenSource)) + } + + newClient, err := storage.NewClient(ctx, opts...) + if err != nil { + return nil, err + } + return newClient, nil +} diff --git a/vendor/github.com/hashicorp/go-getter/get_git.go b/vendor/github.com/hashicorp/go-getter/get_git.go index 1b9f4be8195..119fa6a3be0 100644 --- a/vendor/github.com/hashicorp/go-getter/get_git.go +++ b/vendor/github.com/hashicorp/go-getter/get_git.go @@ -27,6 +27,7 @@ type GitGetter struct { } var defaultBranchRegexp = regexp.MustCompile(`\s->\sorigin/(.*)`) +var lsRemoteSymRefRegexp = regexp.MustCompile(`ref: refs/heads/([^\s]+).*`) func (g *GitGetter) ClientMode(_ *url.URL) (ClientMode, error) { return ClientModeDir, nil @@ -52,7 +53,7 @@ func (g *GitGetter) Get(dst string, u *url.URL) error { // Extract some query parameters we use var ref, sshKey string - var depth int + depth := 0 // 0 means "don't use shallow clone" q := u.Query() if len(q) > 0 { ref = q.Get("ref") @@ -114,7 +115,7 @@ func (g *GitGetter) Get(dst string, u *url.URL) error { if err == nil { err = g.update(ctx, dst, sshKeyFile, ref, depth) } else { - err = g.clone(ctx, dst, sshKeyFile, u, depth) + err = g.clone(ctx, dst, sshKeyFile, u, ref, depth) } if err != nil { return err @@ -166,17 +167,53 @@ func (g *GitGetter) checkout(dst string, ref string) error { return getRunCommand(cmd) } -func (g *GitGetter) clone(ctx context.Context, dst, sshKeyFile string, u *url.URL, depth int) error { +// gitCommitIDRegex is a pattern intended to match strings that seem +// "likely to be" git commit IDs, rather than named refs. This cannot be +// an exact decision because it's valid to name a branch or tag after a series +// of hexadecimal digits too. +// +// We require at least 7 digits here because that's the smallest size git +// itself will typically generate, and so it'll reduce the risk of false +// positives on short branch names that happen to also be "hex words". +var gitCommitIDRegex = regexp.MustCompile("^[0-9a-fA-F]{7,40}$") + +func (g *GitGetter) clone(ctx context.Context, dst, sshKeyFile string, u *url.URL, ref string, depth int) error { args := []string{"clone"} + originalRef := ref // we handle an unspecified ref differently than explicitly selecting the default branch below + if ref == "" { + ref = findRemoteDefaultBranch(u) + } if depth > 0 { args = append(args, "--depth", strconv.Itoa(depth)) + args = append(args, "--branch", ref) } - args = append(args, u.String(), dst) + cmd := exec.CommandContext(ctx, "git", args...) setupGitEnv(cmd, sshKeyFile) - return getRunCommand(cmd) + err := getRunCommand(cmd) + if err != nil { + if depth > 0 && originalRef != "" { + // If we're creating a shallow clone then the given ref must be + // a named ref (branch or tag) rather than a commit directly. + // We can't accurately recognize the resulting error here without + // hard-coding assumptions about git's human-readable output, but + // we can at least try a heuristic. + if gitCommitIDRegex.MatchString(originalRef) { + return fmt.Errorf("%w (note that setting 'depth' requires 'ref' to be a branch or tag name)", err) + } + } + return err + } + + if depth < 1 && originalRef != "" { + // If we didn't add --depth and --branch above then we will now be + // on the remote repository's default branch, rather than the selected + // ref, so we'll need to fix that before we return. + return g.checkout(dst, originalRef) + } + return nil } func (g *GitGetter) update(ctx context.Context, dst, sshKeyFile, ref string, depth int) error { @@ -236,6 +273,20 @@ func findDefaultBranch(dst string) string { return matches[len(matches)-1] } +// findRemoteDefaultBranch checks the remote repo's HEAD symref to return the remote repo's +// default branch. "master" is returned if no HEAD symref exists. +func findRemoteDefaultBranch(u *url.URL) string { + var stdoutbuf bytes.Buffer + cmd := exec.Command("git", "ls-remote", "--symref", u.String(), "HEAD") + cmd.Stdout = &stdoutbuf + err := cmd.Run() + matches := lsRemoteSymRefRegexp.FindStringSubmatch(stdoutbuf.String()) + if err != nil || matches == nil { + return "master" + } + return matches[len(matches)-1] +} + // setupGitEnv sets up the environment for the given command. This is used to // pass configuration data to git and ssh and enables advanced cloning methods. func setupGitEnv(cmd *exec.Cmd, sshKeyFile string) { diff --git a/vendor/github.com/hashicorp/go-getter/get_s3.go b/vendor/github.com/hashicorp/go-getter/get_s3.go index d897ab50c76..ec864428e89 100644 --- a/vendor/github.com/hashicorp/go-getter/get_s3.go +++ b/vendor/github.com/hashicorp/go-getter/get_s3.go @@ -173,7 +173,15 @@ func (g *S3Getter) getObject(ctx context.Context, client *s3.S3, dst, bucket, ke return err } - return copyReader(dst, resp.Body, 0666, g.client.umask()) + body := resp.Body + + if g.client != nil && g.client.ProgressListener != nil { + fn := filepath.Base(key) + body = g.client.ProgressListener.TrackProgress(fn, 0, *resp.ContentLength, resp.Body) + } + defer body.Close() + + return copyReader(dst, body, 0666, g.client.umask()) } func (g *S3Getter) getAWSConfig(region string, url *url.URL, creds *credentials.Credentials) *aws.Config { diff --git a/vendor/github.com/hashicorp/go-getter/go.mod b/vendor/github.com/hashicorp/go-getter/go.mod index b89a575b12b..5bd97136929 100644 --- a/vendor/github.com/hashicorp/go-getter/go.mod +++ b/vendor/github.com/hashicorp/go-getter/go.mod @@ -19,6 +19,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stretchr/testify v1.2.2 // indirect github.com/ulikunitz/xz v0.5.8 + golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 google.golang.org/api v0.9.0 gopkg.in/cheggaaa/pb.v1 v1.0.27 // indirect ) diff --git a/vendor/github.com/hashicorp/go-getter/go.sum b/vendor/github.com/hashicorp/go-getter/go.sum index 8aeb2b9c328..992b8b9b0e6 100644 --- a/vendor/github.com/hashicorp/go-getter/go.sum +++ b/vendor/github.com/hashicorp/go-getter/go.sum @@ -25,7 +25,6 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= @@ -102,7 +101,6 @@ golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4Iltr golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -116,9 +114,7 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 h1:HyfiK1WMnHj5FXFXatD+Qs1A/xC2Run6RzeW1SyHxpc= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= diff --git a/vendor/github.com/hashicorp/go-getter/url.go b/vendor/github.com/hashicorp/go-getter/url.go new file mode 100644 index 00000000000..a9aed7f5081 --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/url.go @@ -0,0 +1,25 @@ +package getter + +import "net/url" + +// RedactURL is a port of url.Redacted from the standard library, +// which is like url.String but replaces any password with "redacted". +// Only the password in u.URL is redacted. This allows the library +// to maintain compatibility with go1.14. +// This port was also extended to redact SSH key from URL query parameter. +func RedactURL(u *url.URL) string { + if u == nil { + return "" + } + + ru := *u + if _, has := ru.User.Password(); has { + ru.User = url.UserPassword(ru.User.Username(), "redacted") + } + q := ru.Query() + if q.Get("sshkey") != "" { + q.Set("sshkey", "redacted") + ru.RawQuery = q.Encode() + } + return ru.String() +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 4d26366088a..7ca698d045c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -413,7 +413,7 @@ github.com/hashicorp/go-discover/provider/vsphere # github.com/hashicorp/go-envparse v0.0.0-20180119215841-310ca1881b22 ## explicit github.com/hashicorp/go-envparse -# github.com/hashicorp/go-getter v1.5.4 +# github.com/hashicorp/go-getter v1.5.11 ## explicit github.com/hashicorp/go-getter github.com/hashicorp/go-getter/helper/url