-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass proxy env vars when using the ee-builder container (#223)
* Pass proxy env vars when using the ee-builder container * Add unit tests * Move env var logic to a better home
- Loading branch information
Showing
7 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
changelog: | ||
- type: NEW_FEATURE | ||
description: >- | ||
When using the ee-builder container, wasme will now pass in the http_proxy, | ||
https_proxy, no_proxy, and GOPROXY environment variables. | ||
issueLink: https://github.com/solo-io/wasm/issues/119 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package defaults_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestDefaults(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Defaults Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package defaults | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
var passThroughVars = []string{ | ||
"http_proxy", | ||
"https_proxy", | ||
"no_proxy", | ||
"GOPROXY", | ||
} | ||
|
||
// GetProxyEnvArgs reads several environment variables and returns | ||
// the arguments to pass them into the docker container used | ||
// during a wasme build command | ||
func GetProxyEnvArgs() []string { | ||
var proxyEnvArgs []string | ||
for _, envVar := range passThroughVars { | ||
val, isSet := os.LookupEnv(envVar) | ||
if isSet { | ||
proxyEnvArgs = append(proxyEnvArgs, "-e", fmt.Sprintf("%s=%s", envVar, val)) | ||
} | ||
} | ||
return proxyEnvArgs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package defaults_test | ||
|
||
import ( | ||
"os" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
. "github.com/solo-io/wasm/tools/wasme/cli/pkg/defaults" | ||
) | ||
|
||
var _ = Describe("Env Proxy Args Passthrough", func() { | ||
It("should not pass through any extra env vars if none are set", func() { | ||
result := GetProxyEnvArgs() | ||
Expect(result).To(HaveLen(0), "shouldn't generate extra args") | ||
}) | ||
|
||
It("should pass a single env var when set", func() { | ||
os.Setenv("http_proxy", "http://example.com") | ||
result := GetProxyEnvArgs() | ||
Expect(result).To(HaveLen(2)) | ||
Expect(result[0]).To(Equal("-e")) | ||
Expect(result[1]).To(Equal("http_proxy=http://example.com")) | ||
}) | ||
|
||
It("should pass multiple env vars when set", func() { | ||
os.Setenv("http_proxy", "http://example.com") | ||
os.Setenv("https_proxy", "https://example.com") | ||
os.Setenv("no_proxy", "https://example.com/foo") | ||
os.Setenv("GOPROXY", "https://example.com/bar") | ||
result := GetProxyEnvArgs() | ||
Expect(result).To(HaveLen(8)) | ||
Expect(result[0]).To(Equal("-e")) | ||
Expect(result[1]).To(Equal("http_proxy=http://example.com")) | ||
Expect(result[2]).To(Equal("-e")) | ||
Expect(result[3]).To(Equal("https_proxy=https://example.com")) | ||
Expect(result[4]).To(Equal("-e")) | ||
Expect(result[5]).To(Equal("no_proxy=https://example.com/foo")) | ||
Expect(result[6]).To(Equal("-e")) | ||
Expect(result[7]).To(Equal("GOPROXY=https://example.com/bar")) | ||
}) | ||
}) |