Merge pull request #23792 from hashicorp/jbardin/update-go-getter
update go-getter
This commit is contained in:
commit
c5300dc46d
2
go.mod
2
go.mod
|
@ -55,7 +55,7 @@ require (
|
||||||
github.com/hashicorp/go-azure-helpers v0.10.0
|
github.com/hashicorp/go-azure-helpers v0.10.0
|
||||||
github.com/hashicorp/go-checkpoint v0.5.0
|
github.com/hashicorp/go-checkpoint v0.5.0
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.1
|
github.com/hashicorp/go-cleanhttp v0.5.1
|
||||||
github.com/hashicorp/go-getter v1.4.0
|
github.com/hashicorp/go-getter v1.4.2-0.20200106182914-9813cbd4eb02
|
||||||
github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f
|
github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f
|
||||||
github.com/hashicorp/go-immutable-radix v0.0.0-20180129170900-7f3cd4390caa // indirect
|
github.com/hashicorp/go-immutable-radix v0.0.0-20180129170900-7f3cd4390caa // indirect
|
||||||
github.com/hashicorp/go-msgpack v0.5.4 // indirect
|
github.com/hashicorp/go-msgpack v0.5.4 // indirect
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -201,8 +201,8 @@ github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6K
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
|
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||||
github.com/hashicorp/go-getter v1.4.0 h1:ENHNi8494porjD0ZhIrjlAHnveSFhY7hvOJrV/fsKkw=
|
github.com/hashicorp/go-getter v1.4.2-0.20200106182914-9813cbd4eb02 h1:l1KB3bHVdvegcIf5upQ5mjcHjs2qsWnKh4Yr9xgIuu8=
|
||||||
github.com/hashicorp/go-getter v1.4.0/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY=
|
github.com/hashicorp/go-getter v1.4.2-0.20200106182914-9813cbd4eb02/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY=
|
||||||
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
|
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
|
||||||
github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f h1:Yv9YzBlAETjy6AOX9eLBZ3nshNVRREgerT/3nvxlGho=
|
github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f h1:Yv9YzBlAETjy6AOX9eLBZ3nshNVRREgerT/3nvxlGho=
|
||||||
github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
|
github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
sudo: false
|
|
||||||
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
sources:
|
|
||||||
- sourceline: 'ppa:git-core/ppa'
|
|
||||||
packages:
|
|
||||||
- git
|
|
||||||
|
|
||||||
language: go
|
|
||||||
|
|
||||||
os:
|
|
||||||
- linux
|
|
||||||
- osx
|
|
||||||
|
|
||||||
go:
|
|
||||||
- "1.11.x"
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- go build ./cmd/go-getter
|
|
||||||
|
|
||||||
branches:
|
|
||||||
only:
|
|
||||||
- master
|
|
|
@ -1,10 +1,10 @@
|
||||||
# go-getter
|
# go-getter
|
||||||
|
|
||||||
[![Build Status](http://img.shields.io/travis/hashicorp/go-getter.svg?style=flat-square)][travis]
|
[![CircleCI](https://circleci.com/gh/hashicorp/go-getter/tree/master.svg?style=svg)][circleci]
|
||||||
[![Build status](https://ci.appveyor.com/api/projects/status/ulq3qr43n62croyq/branch/master?svg=true)][appveyor]
|
[![Build status](https://ci.appveyor.com/api/projects/status/ulq3qr43n62croyq/branch/master?svg=true)][appveyor]
|
||||||
[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs]
|
[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs]
|
||||||
|
|
||||||
[travis]: http://travis-ci.org/hashicorp/go-getter
|
[circleci]: https://circleci.com/gh/hashicorp/go-getter/tree/master
|
||||||
[godocs]: http://godoc.org/github.com/hashicorp/go-getter
|
[godocs]: http://godoc.org/github.com/hashicorp/go-getter
|
||||||
[appveyor]: https://ci.appveyor.com/project/hashicorp/go-getter/branch/master
|
[appveyor]: https://ci.appveyor.com/project/hashicorp/go-getter/branch/master
|
||||||
|
|
||||||
|
@ -356,3 +356,7 @@ In order to access to GCS, authentication credentials should be provided. More i
|
||||||
- gcs::https://www.googleapis.com/storage/v1/bucket
|
- gcs::https://www.googleapis.com/storage/v1/bucket
|
||||||
- gcs::https://www.googleapis.com/storage/v1/bucket/foo.zip
|
- gcs::https://www.googleapis.com/storage/v1/bucket/foo.zip
|
||||||
- www.googleapis.com/storage/v1/bucket/foo
|
- www.googleapis.com/storage/v1/bucket/foo
|
||||||
|
|
||||||
|
#### GCS Testing
|
||||||
|
|
||||||
|
The tests for `get_gcs.go` require you to have GCP credentials set in your environment. These credentials can have any level of permissions to any project, they just need to exist. This means setting `GOOGLE_APPLICATION_CREDENTIALS="~/path/to/credentials.json"` or `GOOGLE_CREDENTIALS="{stringified-credentials-json}"`. Due to this configuration, `get_gcs_test.go` will fail for external contributors in CircleCI.
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
// Using a client directly allows more fine-grained control over how downloading
|
// Using a client directly allows more fine-grained control over how downloading
|
||||||
// is done, as well as customizing the protocols supported.
|
// is done, as well as customizing the protocols supported.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
// Ctx for cancellation
|
// Ctx for cancellation
|
||||||
Ctx context.Context
|
Ctx context.Context
|
||||||
|
|
||||||
// Src is the source URL to get.
|
// Src is the source URL to get.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package getter
|
package getter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -9,6 +10,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -24,6 +26,8 @@ type GitGetter struct {
|
||||||
getter
|
getter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var defaultBranchRegexp = regexp.MustCompile(`\s->\sorigin/(.*)`)
|
||||||
|
|
||||||
func (g *GitGetter) ClientMode(_ *url.URL) (ClientMode, error) {
|
func (g *GitGetter) ClientMode(_ *url.URL) (ClientMode, error) {
|
||||||
return ClientModeDir, nil
|
return ClientModeDir, nil
|
||||||
}
|
}
|
||||||
|
@ -182,10 +186,10 @@ func (g *GitGetter) update(ctx context.Context, dst, sshKeyFile, ref string, dep
|
||||||
cmd.Dir = dst
|
cmd.Dir = dst
|
||||||
|
|
||||||
if getRunCommand(cmd) != nil {
|
if getRunCommand(cmd) != nil {
|
||||||
// Not a branch, switch to master. This will also catch non-existent
|
// Not a branch, switch to default branch. This will also catch
|
||||||
// branches, in which case we want to switch to master and then
|
// non-existent branches, in which case we want to switch to default
|
||||||
// checkout the proper branch later.
|
// and then checkout the proper branch later.
|
||||||
ref = "master"
|
ref = findDefaultBranch(dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have to be on a branch to pull
|
// We have to be on a branch to pull
|
||||||
|
@ -216,6 +220,22 @@ func (g *GitGetter) fetchSubmodules(ctx context.Context, dst, sshKeyFile string,
|
||||||
return getRunCommand(cmd)
|
return getRunCommand(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// findDefaultBranch checks the repo's origin remote for its default branch
|
||||||
|
// (generally "master"). "master" is returned if an origin default branch
|
||||||
|
// can't be determined.
|
||||||
|
func findDefaultBranch(dst string) string {
|
||||||
|
var stdoutbuf bytes.Buffer
|
||||||
|
cmd := exec.Command("git", "branch", "-r", "--points-at", "refs/remotes/origin/HEAD")
|
||||||
|
cmd.Dir = dst
|
||||||
|
cmd.Stdout = &stdoutbuf
|
||||||
|
err := cmd.Run()
|
||||||
|
matches := defaultBranchRegexp.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
|
// 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.
|
// pass configuration data to git and ssh and enables advanced cloning methods.
|
||||||
func setupGitEnv(cmd *exec.Cmd, sshKeyFile string) {
|
func setupGitEnv(cmd *exec.Cmd, sshKeyFile string) {
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
safetemp "github.com/hashicorp/go-safetemp"
|
safetemp "github.com/hashicorp/go-safetemp"
|
||||||
|
@ -88,7 +87,10 @@ func (g *HttpGetter) Get(dst string, u *url.URL) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header = g.Header
|
if g.Header != nil {
|
||||||
|
req.Header = g.Header
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := g.Client.Do(req)
|
resp, err := g.Client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -128,6 +130,12 @@ func (g *HttpGetter) Get(dst string, u *url.URL) error {
|
||||||
return g.getSubdir(ctx, dst, source, subDir)
|
return g.getSubdir(ctx, dst, source, subDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetFile fetches the file from src and stores it at dst.
|
||||||
|
// If the server supports Accept-Range, HttpGetter will attempt a range
|
||||||
|
// request. This means it is the caller's responsibility to ensure that an
|
||||||
|
// older version of the destination file does not exist, else it will be either
|
||||||
|
// falsely identified as being replaced, or corrupted with extra bytes
|
||||||
|
// appended.
|
||||||
func (g *HttpGetter) GetFile(dst string, src *url.URL) error {
|
func (g *HttpGetter) GetFile(dst string, src *url.URL) error {
|
||||||
ctx := g.Context()
|
ctx := g.Context()
|
||||||
if g.Netrc {
|
if g.Netrc {
|
||||||
|
@ -136,7 +144,6 @@ func (g *HttpGetter) GetFile(dst string, src *url.URL) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create all the parent directories if needed
|
// Create all the parent directories if needed
|
||||||
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
|
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -165,18 +172,17 @@ func (g *HttpGetter) GetFile(dst string, src *url.URL) error {
|
||||||
req.Header = g.Header
|
req.Header = g.Header
|
||||||
}
|
}
|
||||||
headResp, err := g.Client.Do(req)
|
headResp, err := g.Client.Do(req)
|
||||||
if err == nil && headResp != nil {
|
if err == nil {
|
||||||
headResp.Body.Close()
|
headResp.Body.Close()
|
||||||
if headResp.StatusCode == 200 {
|
if headResp.StatusCode == 200 {
|
||||||
// If the HEAD request succeeded, then attempt to set the range
|
// If the HEAD request succeeded, then attempt to set the range
|
||||||
// query if we can.
|
// query if we can.
|
||||||
if headResp.Header.Get("Accept-Ranges") == "bytes" {
|
if headResp.Header.Get("Accept-Ranges") == "bytes" && headResp.ContentLength >= 0 {
|
||||||
if fi, err := f.Stat(); err == nil {
|
if fi, err := f.Stat(); err == nil {
|
||||||
if _, err = f.Seek(0, os.SEEK_END); err == nil {
|
if _, err = f.Seek(0, io.SeekEnd); err == nil {
|
||||||
req.Header.Set("Range", fmt.Sprintf("bytes=%d-", fi.Size()))
|
|
||||||
currentFileSize = fi.Size()
|
currentFileSize = fi.Size()
|
||||||
totalFileSize, _ := strconv.ParseInt(headResp.Header.Get("Content-Length"), 10, 64)
|
req.Header.Set("Range", fmt.Sprintf("bytes=%d-", currentFileSize))
|
||||||
if currentFileSize >= totalFileSize {
|
if currentFileSize >= headResp.ContentLength {
|
||||||
// file already present
|
// file already present
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,7 +309,7 @@ github.com/hashicorp/go-azure-helpers/storage
|
||||||
github.com/hashicorp/go-checkpoint
|
github.com/hashicorp/go-checkpoint
|
||||||
# github.com/hashicorp/go-cleanhttp v0.5.1
|
# github.com/hashicorp/go-cleanhttp v0.5.1
|
||||||
github.com/hashicorp/go-cleanhttp
|
github.com/hashicorp/go-cleanhttp
|
||||||
# github.com/hashicorp/go-getter v1.4.0
|
# github.com/hashicorp/go-getter v1.4.2-0.20200106182914-9813cbd4eb02
|
||||||
github.com/hashicorp/go-getter
|
github.com/hashicorp/go-getter
|
||||||
github.com/hashicorp/go-getter/helper/url
|
github.com/hashicorp/go-getter/helper/url
|
||||||
# github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f
|
# github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f
|
||||||
|
|
Loading…
Reference in New Issue