diff --git a/forge.go b/forge.go index a1672d0..ca0db63 100644 --- a/forge.go +++ b/forge.go @@ -200,7 +200,7 @@ func queryForgeAPI(fm ForgeModule) ForgeResult { mutex.Unlock() defer resp.Body.Close() - if strings.TrimSpace(resp.Status) == "200 OK" { + if resp.StatusCode == http.StatusOK { // need to get latest version body, err := ioutil.ReadAll(resp.Body) if err != nil { @@ -218,10 +218,10 @@ func queryForgeAPI(fm ForgeModule) ForgeResult { return ForgeResult{true, fr.versionNumber, fr.md5sum, fr.fileSize} - } else if strings.TrimSpace(resp.Status) == "304 Not Modified" { + } else if resp.StatusCode == http.StatusNotModified { Debugf("Got 304 nothing to do for module " + fm.author + "-" + fm.name) return ForgeResult{false, "", "", 0} - } else if strings.TrimSpace(resp.Status) == "404 Not Found" { + } else if resp.StatusCode == http.StatusNotFound { Fatalf("Received 404 from Forge for module " + fm.author + "-" + fm.name + " using URL " + url + " Does the module really exist and is it correctly named?") return ForgeResult{false, "", "", 0} } @@ -305,7 +305,7 @@ func getMetadataForgeModule(fm ForgeModule) ForgeModule { } defer resp.Body.Close() - if strings.TrimSpace(resp.Status) == "200 OK" { + if resp.StatusCode == http.StatusOK { body, err := ioutil.ReadAll(resp.Body) if err != nil { @@ -390,7 +390,7 @@ func downloadForgeModule(name string, version string, fm ForgeModule, retryCount } defer resp.Body.Close() - if strings.TrimSpace(resp.Status) == "200 OK" { + if resp.StatusCode == http.StatusOK { wgForgeModule.Add(1) go func() { defer wgForgeModule.Done() @@ -424,7 +424,7 @@ func downloadForgeModule(name string, version string, fm ForgeModule, retryCount Fatalf("Error while writing to MultiWriter " + err.Error()) } }() - } else if strings.TrimSpace(resp.Status) == "404 Not Found" { + } else if resp.StatusCode == http.StatusNotFound { Fatalf("Received 404 from Forge using URL " + url + "\nCheck if the module name '" + fm.author + "-" + fm.name + "' and version '" + version + "' really exist" + "\nUsed in Puppet environment '" + fm.sourceBranch + "'") diff --git a/g10k_test.go b/g10k_test.go index b7db24a..e85b068 100755 --- a/g10k_test.go +++ b/g10k_test.go @@ -3254,7 +3254,7 @@ func TestNoProxy(t *testing.T) { // fmt.Println(string(out)) expectedLines := []string{ - "found matching NO_PROXY URL, trying to disable http_proxy for git clone --mirror https://localgit.domain.tld/foo/bar.git /tmp/g10k/modules/https-__localgit.domain.tld_foo_bar.git", + "found matching NO_PROXY URL, trying to disable http_proxy and https_proxy env variables for git clone --mirror https://localgit.domain.tld/foo/bar.git /tmp/g10k/modules/https-__localgit.domain.tld_foo_bar.git", } for _, expectedLine := range expectedLines { if !strings.Contains(string(out), expectedLine) { diff --git a/git.go b/git.go index 595e206..72a5c5c 100644 --- a/git.go +++ b/git.go @@ -100,7 +100,7 @@ func doMirrorOrUpdate(gitModule GitModule, workDir string, retryCount int) bool isInModulesCacheDir := strings.HasPrefix(workDir, config.ModulesCacheDir) explicitlyLoadSSHKey := true - if len(gitModule.privateKey) == 0 || strings.Contains(gitModule.git, "github.com") || gitModule.useSSHAgent { + if len(gitModule.privateKey) == 0 || strings.Contains(gitModule.git, "github.com") || gitModule.useSSHAgent || strings.HasPrefix(gitModule.git, "https://") { if gitModule.useSSHAgent || len(gitModule.privateKey) == 0 { explicitlyLoadSSHKey = false } else if isControlRepo { diff --git a/helper.go b/helper.go index 712e643..a4189cb 100644 --- a/helper.go +++ b/helper.go @@ -194,9 +194,18 @@ func executeCommand(command string, commandDir string, timeout int, allowFail bo execCommand.Dir = commandDir } if disableHttpProxy { - Debugf("found matching NO_PROXY URL, trying to disable http_proxy for " + command) - execCommand.Env = append(os.Environ(), "http_proxy=") - execCommand.Env = append(os.Environ(), "https_proxy=") + Debugf("found matching NO_PROXY URL, trying to disable http_proxy and https_proxy env variables for " + command) + // execCommand.Env = append(os.Environ(), "http_proxy=") + // execCommand.Env = append(os.Environ(), "https_proxy=") + os.Unsetenv("http_proxy") + os.Unsetenv("https_proxy") + os.Unsetenv("HTTP_PROXY") + os.Unsetenv("HTTPS_PROXY") + execCommand.Env = os.Environ() + Debugf("exec OS env:" + strings.Join(execCommand.Env, ",") + " for command " + command) + } else { + execCommand.Env = os.Environ() + Debugf("exec OS env:" + strings.Join(execCommand.Env, ",") + " for command " + command) } out, err := execCommand.CombinedOutput() duration := time.Since(before).Seconds() @@ -350,9 +359,8 @@ func matchGitRemoteURLNoProxy(url string) bool { noProxy := os.Getenv("NO_PROXY") for _, np := range strings.Split(noProxy, ",") { if len(np) > 0 { - Debugf("found NO_PROXY setting: " + np) if strings.Contains(url, np) { - // fmt.Println("found matching", np, "for", url) + Debugf("found NO_PROXY setting: " + np + " matching " + url) return true } } @@ -362,7 +370,7 @@ func matchGitRemoteURLNoProxy(url string) bool { for _, np := range strings.Split(noProxyL, ",") { if len(np) > 0 { if strings.Contains(url, np) { - // fmt.Println("found matching", np, "for", url) + Debugf("found no_proxy setting: " + np + " matching " + url) return true } } diff --git a/puppetfile.go b/puppetfile.go index 778b8f1..7cd14d8 100644 --- a/puppetfile.go +++ b/puppetfile.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -317,10 +316,10 @@ func resolvePuppetfile(allPuppetfiles map[string]Puppetfile) { for _, moduleDir := range pf.moduleDirs { moduleDir = normalizeDir(filepath.Join(pf.workDir, moduleDir)) - exisitingModuleDirsFI, _ := ioutil.ReadDir(moduleDir) + exisitingModuleDirsFI, _ := os.ReadDir(moduleDir) mutex.Lock() for _, exisitingModuleDir := range exisitingModuleDirsFI { - //fmt.Println("adding dir: ", moduleDir+exisitingModuleDir.Name()) + // fmt.Println("adding dir: ", filepath.Join(moduleDir, exisitingModuleDir.Name())) exisitingModuleDirs[filepath.Join(moduleDir, exisitingModuleDir.Name())] = empty } mutex.Unlock()