Skip to content

Commit a8fa1a7

Browse files
committed
Use git_source configurations for GOPRIVATE
1 parent 895399f commit a8fa1a7

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

go/extractor/util/registryproxy.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const PROXY_PORT = "CODEQL_PROXY_PORT"
1414
const PROXY_CA_CERTIFICATE = "CODEQL_PROXY_CA_CERTIFICATE"
1515
const PROXY_URLS = "CODEQL_PROXY_URLS"
1616
const GOPROXY_SERVER = "goproxy_server"
17+
const GIT_SOURCE = "git_source"
1718

1819
type RegistryConfig struct {
1920
Type string `json:"type"`
@@ -29,6 +30,9 @@ var proxy_cert_file string
2930
// An array of goproxy server URLs.
3031
var goproxy_servers []string
3132

33+
// An array of Git URLs.
34+
var git_sources []string
35+
3236
// Stores the environment variables that we wish to pass on to `go` commands.
3337
var proxy_vars []string = nil
3438

@@ -98,18 +102,29 @@ func getEnvVars() []string {
98102
if cfg.Type == GOPROXY_SERVER {
99103
goproxy_servers = append(goproxy_servers, cfg.URL)
100104
slog.Info("Found GOPROXY server", slog.String("url", cfg.URL))
105+
} else if cfg.Type == GIT_SOURCE {
106+
git_sources = append(git_sources, cfg.URL)
107+
slog.Info("Found Git source", slog.String("url", cfg.URL))
101108
}
102109
}
103110

111+
goprivate := []string{}
112+
104113
if len(goproxy_servers) > 0 {
105114
goproxy_val := "https://proxy.golang.org,direct"
106115

107116
for _, url := range goproxy_servers {
108117
goproxy_val = url + "," + goproxy_val
109118
}
110119

111-
result = append(result, fmt.Sprintf("GOPROXY=%s", goproxy_val), "GOPRIVATE=", "GONOPROXY=")
120+
result = append(result, fmt.Sprintf("GOPROXY=%s", goproxy_val), "GONOPROXY=")
112121
}
122+
123+
if len(git_sources) > 0 {
124+
goprivate = append(goprivate, git_sources...)
125+
}
126+
127+
result = append(result, fmt.Sprintf("GOPRIVATE=%s", strings.Join(goprivate, ",")))
113128
}
114129
}
115130

go/extractor/util/registryproxy_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,31 @@ func TestParseRegistryConfigs(t *testing.T) {
4747
t.Fatalf("Expected `URL` to be `https://proxy.example.com/mod`, but got `%s`", first.URL)
4848
}
4949
}
50+
51+
func TestParseRegistryConfigsMultiple(t *testing.T) {
52+
multiple := parseRegistryConfigsSuccess(t, "[{ \"type\": \"git_source\", \"url\": \"https://github.com/github\" }, { \"type\": \"goproxy_server\", \"url\": \"https://proxy.example.com/mod\" }]")
53+
54+
if len(multiple) != 2 {
55+
t.Fatalf("Expected `parseRegistryConfigs` to return two configurations, but got %d.", len(multiple))
56+
}
57+
58+
first := multiple[0]
59+
60+
if first.Type != "git_source" {
61+
t.Fatalf("Expected `Type` to be `git_source`, but got `%s`", first.Type)
62+
}
63+
64+
if first.URL != "https://github.com/github" {
65+
t.Fatalf("Expected `URL` to be `https://github.com/github`, but got `%s`", first.URL)
66+
}
67+
68+
second := multiple[1]
69+
70+
if second.Type != "goproxy_server" {
71+
t.Fatalf("Expected `Type` to be `goproxy_server`, but got `%s`", second.Type)
72+
}
73+
74+
if second.URL != "https://proxy.example.com/mod" {
75+
t.Fatalf("Expected `URL` to be `https://proxy.example.com/mod`, but got `%s`", second.URL)
76+
}
77+
}

0 commit comments

Comments
 (0)