GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Go: Support `git_source` by mbg · Pull Request #20368 · github/codeql

Go: Support git_source #20368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
mbg merged 7 commits into main from mbg/go/support-git-source
Sep 24, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

Go: Support git_source #20368

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
7 commits
Select commit Hold shift + click to select a range
711d497
Improve logging to include proxy vars
mbg Sep 5, 2025
23a0461
Set lower-case variants of `HTTP_PROXY` and `HTTPS_PROXY`
mbg Sep 4, 2025
895399f
Rename `proxy_configs` to `goproxy_servers` and only store URLs
mbg Sep 4, 2025
a8fa1a7
Use `git_source` configurations for `GOPRIVATE`
mbg Sep 4, 2025
4ef8ff9
Append `*` to `git_source` URL if not present
mbg Sep 5, 2025
bc38b79
Convert URLs to expected format
mbg Sep 5, 2025
8c84992
Configure `git` to use the certificate, if needed
mbg Sep 4, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

68 changes: 54 additions & 14 deletions 68 go/extractor/util/registryproxy.go
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"log/slog"
"net/url"
"os"
"os/exec"
"strings"
Expand All @@ -14,6 +15,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"`
Expand All @@ -26,9 +28,11 @@ var proxy_address string
// The path to the temporary file that stores the proxy certificate, if any.
var proxy_cert_file string

// An array of registry configurations that are relevant to Go.
// This excludes other registry configurations that may be available, but are not relevant to Go.
var proxy_configs []RegistryConfig
// 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
Expand All @@ -53,7 +57,13 @@ func getEnvVars() []string {
if proxy_host, proxy_host_set := os.LookupEnv(PROXY_HOST); proxy_host_set && proxy_host != "" {
if proxy_port, proxy_port_set := os.LookupEnv(PROXY_PORT); proxy_port_set && proxy_port != "" {
proxy_address = fmt.Sprintf("http://%s:%s", proxy_host, proxy_port)
result = append(result, fmt.Sprintf("HTTP_PROXY=%s", proxy_address), fmt.Sprintf("HTTPS_PROXY=%s", proxy_address))
result = append(
result,
fmt.Sprintf("HTTP_PROXY=%s", proxy_address),
fmt.Sprintf("HTTPS_PROXY=%s", proxy_address),
fmt.Sprintf("http_proxy=%s", proxy_address),
fmt.Sprintf("https_proxy=%s", proxy_address),
)

slog.Info("Found private registry proxy", slog.String("proxy_address", proxy_address))
}
Expand Down Expand Up @@ -91,20 +101,49 @@ func getEnvVars() []string {
// filter others out at this point.
for _, cfg := range val {
if cfg.Type == GOPROXY_SERVER {
proxy_configs = append(proxy_configs, cfg)
goproxy_servers = append(goproxy_servers, cfg.URL)
slog.Info("Found GOPROXY server", slog.String("url", cfg.URL))
} else if cfg.Type == GIT_SOURCE {
parsed, err := url.Parse(cfg.URL)
if err == nil && parsed.Hostname() != "" {
git_source := parsed.Hostname() + parsed.Path + "*"
git_sources = append(git_sources, git_source)
slog.Info("Found Git source", slog.String("source", git_source))
} else {
slog.Warn("Not a valid URL for Git source", slog.String("url", cfg.URL))
}
}
}

if len(proxy_configs) > 0 {
goprivate := []string{}

if len(goproxy_servers) > 0 {
goproxy_val := "https://proxy.golang.org,direct"

for _, cfg := range proxy_configs {
goproxy_val = cfg.URL + "," + goproxy_val
for _, url := range goproxy_servers {
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...)

if proxy_cert_file != "" {
slog.Info("Configuring `git` to use proxy certificate", slog.String("path", proxy_cert_file))
cmd := exec.Command("git", "config", "--global", "http.sslCAInfo", proxy_cert_file)

out, cmdErr := cmd.CombinedOutput()
slog.Info(string(out))

if cmdErr != nil {
slog.Error("Failed to configure `git` to accept the certificate file", slog.String("error", cmdErr.Error()))
}
}
}

result = append(result, fmt.Sprintf("GOPRIVATE=%s", strings.Join(goprivate, ",")))
}
}

Expand All @@ -113,11 +152,6 @@ func getEnvVars() []string {

// Applies private package proxy related environment variables to `cmd`.
func ApplyProxyEnvVars(cmd *exec.Cmd) {
slog.Debug(
"Applying private registry proxy environment variables",
slog.String("cmd_args", strings.Join(cmd.Args, " ")),
)

// If we haven't done so yet, check whether the proxy environment variables are set
// and extract information from them.
if !proxy_vars_checked {
Expand All @@ -131,4 +165,10 @@ func ApplyProxyEnvVars(cmd *exec.Cmd) {
if proxy_vars != nil {
cmd.Env = append(os.Environ(), proxy_vars...)
}

slog.Debug(
"Applying private registry proxy environment variables",
slog.String("cmd_args", strings.Join(cmd.Args, " ")),
slog.String("proxy_vars", strings.Join(proxy_vars, ",")),
)
}
28 changes: 28 additions & 0 deletions 28 go/extractor/util/registryproxy_test.go
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.