mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Use git_source configurations for GOPRIVATE
This commit is contained in:
@@ -14,6 +14,7 @@ const PROXY_PORT = "CODEQL_PROXY_PORT"
|
||||
const PROXY_CA_CERTIFICATE = "CODEQL_PROXY_CA_CERTIFICATE"
|
||||
const PROXY_URLS = "CODEQL_PROXY_URLS"
|
||||
const GOPROXY_SERVER = "goproxy_server"
|
||||
const GIT_SOURCE = "git_source"
|
||||
|
||||
type RegistryConfig struct {
|
||||
Type string `json:"type"`
|
||||
@@ -29,6 +30,9 @@ var proxy_cert_file string
|
||||
// An array of goproxy server URLs.
|
||||
var goproxy_servers []string
|
||||
|
||||
// An array of Git URLs.
|
||||
var git_sources []string
|
||||
|
||||
// Stores the environment variables that we wish to pass on to `go` commands.
|
||||
var proxy_vars []string = nil
|
||||
|
||||
@@ -98,9 +102,14 @@ func getEnvVars() []string {
|
||||
if cfg.Type == GOPROXY_SERVER {
|
||||
goproxy_servers = append(goproxy_servers, cfg.URL)
|
||||
slog.Info("Found GOPROXY server", slog.String("url", cfg.URL))
|
||||
} else if cfg.Type == GIT_SOURCE {
|
||||
git_sources = append(git_sources, cfg.URL)
|
||||
slog.Info("Found Git source", slog.String("url", cfg.URL))
|
||||
}
|
||||
}
|
||||
|
||||
goprivate := []string{}
|
||||
|
||||
if len(goproxy_servers) > 0 {
|
||||
goproxy_val := "https://proxy.golang.org,direct"
|
||||
|
||||
@@ -108,8 +117,14 @@ func getEnvVars() []string {
|
||||
goproxy_val = url + "," + goproxy_val
|
||||
}
|
||||
|
||||
result = append(result, fmt.Sprintf("GOPROXY=%s", goproxy_val), "GOPRIVATE=", "GONOPROXY=")
|
||||
result = append(result, fmt.Sprintf("GOPROXY=%s", goproxy_val), "GONOPROXY=")
|
||||
}
|
||||
|
||||
if len(git_sources) > 0 {
|
||||
goprivate = append(goprivate, git_sources...)
|
||||
}
|
||||
|
||||
result = append(result, fmt.Sprintf("GOPRIVATE=%s", strings.Join(goprivate, ",")))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,3 +47,31 @@ func TestParseRegistryConfigs(t *testing.T) {
|
||||
t.Fatalf("Expected `URL` to be `https://proxy.example.com/mod`, but got `%s`", first.URL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRegistryConfigsMultiple(t *testing.T) {
|
||||
multiple := parseRegistryConfigsSuccess(t, "[{ \"type\": \"git_source\", \"url\": \"https://github.com/github\" }, { \"type\": \"goproxy_server\", \"url\": \"https://proxy.example.com/mod\" }]")
|
||||
|
||||
if len(multiple) != 2 {
|
||||
t.Fatalf("Expected `parseRegistryConfigs` to return two configurations, but got %d.", len(multiple))
|
||||
}
|
||||
|
||||
first := multiple[0]
|
||||
|
||||
if first.Type != "git_source" {
|
||||
t.Fatalf("Expected `Type` to be `git_source`, but got `%s`", first.Type)
|
||||
}
|
||||
|
||||
if first.URL != "https://github.com/github" {
|
||||
t.Fatalf("Expected `URL` to be `https://github.com/github`, but got `%s`", first.URL)
|
||||
}
|
||||
|
||||
second := multiple[1]
|
||||
|
||||
if second.Type != "goproxy_server" {
|
||||
t.Fatalf("Expected `Type` to be `goproxy_server`, but got `%s`", second.Type)
|
||||
}
|
||||
|
||||
if second.URL != "https://proxy.example.com/mod" {
|
||||
t.Fatalf("Expected `URL` to be `https://proxy.example.com/mod`, but got `%s`", second.URL)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user