update go-getter
This commit is contained in:
parent
fe4cfd03b5
commit
e39da6e1c9
|
@ -21,8 +21,7 @@ URLs. For example: "github.com/hashicorp/go-getter" would turn into a
|
||||||
Git URL. Or "./foo" would turn into a file URL. These are extensible.
|
Git URL. Or "./foo" would turn into a file URL. These are extensible.
|
||||||
|
|
||||||
This library is used by [Terraform](https://terraform.io) for
|
This library is used by [Terraform](https://terraform.io) for
|
||||||
downloading modules, [Otto](https://ottoproject.io) for dependencies and
|
downloading modules and [Nomad](https://nomadproject.io) for downloading
|
||||||
Appfile imports, and [Nomad](https://nomadproject.io) for downloading
|
|
||||||
binaries.
|
binaries.
|
||||||
|
|
||||||
## Installation and Usage
|
## Installation and Usage
|
||||||
|
|
|
@ -32,7 +32,7 @@ func (d *FileDetector) Detect(src, pwd string) (string, bool, error) {
|
||||||
return "", true, err
|
return "", true, err
|
||||||
}
|
}
|
||||||
if fi.Mode()&os.ModeSymlink != 0 {
|
if fi.Mode()&os.ModeSymlink != 0 {
|
||||||
pwd, err = os.Readlink(pwd)
|
pwd, err = filepath.EvalSymlinks(pwd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", true, err
|
return "", true, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
cleanhttp "github.com/hashicorp/go-cleanhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Getter defines the interface that schemes must implement to download
|
// Getter defines the interface that schemes must implement to download
|
||||||
|
@ -49,8 +51,13 @@ var Getters map[string]Getter
|
||||||
// syntax is schema::url, example: git::https://foo.com
|
// syntax is schema::url, example: git::https://foo.com
|
||||||
var forcedRegexp = regexp.MustCompile(`^([A-Za-z0-9]+)::(.+)$`)
|
var forcedRegexp = regexp.MustCompile(`^([A-Za-z0-9]+)::(.+)$`)
|
||||||
|
|
||||||
|
// httpClient is the default client to be used by HttpGetters.
|
||||||
|
var httpClient = cleanhttp.DefaultClient()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
httpGetter := &HttpGetter{Netrc: true}
|
httpGetter := &HttpGetter{
|
||||||
|
Netrc: true,
|
||||||
|
}
|
||||||
|
|
||||||
Getters = map[string]Getter{
|
Getters = map[string]Getter{
|
||||||
"file": new(FileGetter),
|
"file": new(FileGetter),
|
||||||
|
|
|
@ -180,17 +180,34 @@ func (g *GitGetter) fetchSubmodules(dst, sshKeyFile string) error {
|
||||||
// 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) {
|
||||||
var sshOpts []string
|
const gitSSHCommand = "GIT_SSH_COMMAND="
|
||||||
|
var sshCmd []string
|
||||||
|
|
||||||
|
// If we have an existing GIT_SSH_COMMAND, we need to append our options.
|
||||||
|
// We will also remove our old entry to make sure the behavior is the same
|
||||||
|
// with versions of Go < 1.9.
|
||||||
|
env := os.Environ()
|
||||||
|
for i, v := range env {
|
||||||
|
if strings.HasPrefix(v, gitSSHCommand) {
|
||||||
|
sshCmd = []string{v}
|
||||||
|
|
||||||
|
env[i], env[len(env)-1] = env[len(env)-1], env[i]
|
||||||
|
env = env[:len(env)-1]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(sshCmd) == 0 {
|
||||||
|
sshCmd = []string{gitSSHCommand + "ssh"}
|
||||||
|
}
|
||||||
|
|
||||||
if sshKeyFile != "" {
|
if sshKeyFile != "" {
|
||||||
// We have an SSH key temp file configured, tell ssh about this.
|
// We have an SSH key temp file configured, tell ssh about this.
|
||||||
sshOpts = append(sshOpts, "-i", sshKeyFile)
|
sshCmd = append(sshCmd, "-i", sshKeyFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Env = append(os.Environ(),
|
env = append(env, strings.Join(sshCmd, " "))
|
||||||
// Set the ssh command to use for clones.
|
cmd.Env = env
|
||||||
"GIT_SSH_COMMAND=ssh "+strings.Join(sshOpts, " "),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkGitVersion is used to check the version of git installed on the system
|
// checkGitVersion is used to check the version of git installed on the system
|
||||||
|
|
|
@ -36,6 +36,10 @@ type HttpGetter struct {
|
||||||
// Netrc, if true, will lookup and use auth information found
|
// Netrc, if true, will lookup and use auth information found
|
||||||
// in the user's netrc file if available.
|
// in the user's netrc file if available.
|
||||||
Netrc bool
|
Netrc bool
|
||||||
|
|
||||||
|
// Client is the http.Client to use for Get requests.
|
||||||
|
// This defaults to a cleanhttp.DefaultClient if left unset.
|
||||||
|
Client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *HttpGetter) ClientMode(u *url.URL) (ClientMode, error) {
|
func (g *HttpGetter) ClientMode(u *url.URL) (ClientMode, error) {
|
||||||
|
@ -57,13 +61,17 @@ func (g *HttpGetter) Get(dst string, u *url.URL) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if g.Client == nil {
|
||||||
|
g.Client = httpClient
|
||||||
|
}
|
||||||
|
|
||||||
// Add terraform-get to the parameter.
|
// Add terraform-get to the parameter.
|
||||||
q := u.Query()
|
q := u.Query()
|
||||||
q.Add("terraform-get", "1")
|
q.Add("terraform-get", "1")
|
||||||
u.RawQuery = q.Encode()
|
u.RawQuery = q.Encode()
|
||||||
|
|
||||||
// Get the URL
|
// Get the URL
|
||||||
resp, err := http.Get(u.String())
|
resp, err := g.Client.Get(u.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -105,7 +113,11 @@ func (g *HttpGetter) GetFile(dst string, u *url.URL) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.Get(u.String())
|
if g.Client == nil {
|
||||||
|
g.Client = httpClient
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := g.Client.Get(u.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1366,16 +1366,20 @@
|
||||||
"revisionTime": "2017-02-11T01:34:15Z"
|
"revisionTime": "2017-02-11T01:34:15Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "cw5fzHNCbc3zVjNRnP1pm5tt5rk=",
|
"checksumSHA1": "7SY5eTKPGF0BjyByXfKhZAAqnKc=",
|
||||||
"path": "github.com/hashicorp/go-getter",
|
"path": "github.com/hashicorp/go-getter",
|
||||||
"revision": "ee320eed76420de7fa4395de568552c63fe9115e",
|
"revision": "56c651a79a6eec93e6ef074fe9e57fefb26b8b85",
|
||||||
"revisionTime": "2017-09-05T20:45:58Z"
|
"revisionTime": "2017-09-14T15:44:44Z",
|
||||||
|
"version": "master",
|
||||||
|
"versionExact": "master"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "9J+kDr29yDrwsdu2ULzewmqGjpA=",
|
"checksumSHA1": "9J+kDr29yDrwsdu2ULzewmqGjpA=",
|
||||||
"path": "github.com/hashicorp/go-getter/helper/url",
|
"path": "github.com/hashicorp/go-getter/helper/url",
|
||||||
"revision": "6aae8e4e2dee8131187c6a54b52664796e5a02b0",
|
"revision": "56c651a79a6eec93e6ef074fe9e57fefb26b8b85",
|
||||||
"revisionTime": "2017-07-13T01:23:01Z"
|
"revisionTime": "2017-09-14T15:44:44Z",
|
||||||
|
"version": "master",
|
||||||
|
"versionExact": "master"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "miVF4/7JP0lRwZvFJGKwZWk7aAQ=",
|
"checksumSHA1": "miVF4/7JP0lRwZvFJGKwZWk7aAQ=",
|
||||||
|
|
Loading…
Reference in New Issue