1- package util
1+ package registries
22
33import (
44 "encoding/json"
88 "os"
99 "os/exec"
1010 "strings"
11+
12+ "github.com/github/codeql-go/extractor/diagnostics"
1113)
1214
1315const PROXY_HOST = "CODEQL_PROXY_HOST"
@@ -22,6 +24,19 @@ type RegistryConfig struct {
2224 URL string `json:"url"`
2325}
2426
27+ func (config * RegistryConfig ) Pretty () string {
28+ pretty_type := "other"
29+
30+ switch config .Type {
31+ case GIT_SOURCE :
32+ pretty_type = "Git Source"
33+ case GOPROXY_SERVER :
34+ pretty_type = "GOPROXY Server"
35+ }
36+
37+ return fmt .Sprintf ("`%s` (%s)" , config .URL , pretty_type )
38+ }
39+
2540// The address of the proxy including protocol and port (e.g. http://localhost:1234)
2641var proxy_address string
2742
@@ -97,24 +112,40 @@ func getEnvVars() []string {
97112 if err != nil {
98113 slog .Error ("Unable to parse proxy configurations" , slog .String ("error" , err .Error ()))
99114 } else {
115+ activeConfigs := make ([]RegistryConfig , 0 , len (val ))
116+
100117 // We only care about private registry configurations that are relevant to Go and
101118 // filter others out at this point.
102119 for _ , cfg := range val {
103120 if cfg .Type == GOPROXY_SERVER {
104121 goproxy_servers = append (goproxy_servers , cfg .URL )
105122 slog .Info ("Found GOPROXY server" , slog .String ("url" , cfg .URL ))
123+ activeConfigs = append (activeConfigs , cfg )
106124 } else if cfg .Type == GIT_SOURCE {
107125 parsed , err := url .Parse (cfg .URL )
108126 if err == nil && parsed .Hostname () != "" {
109127 git_source := parsed .Hostname () + parsed .Path + "*"
110128 git_sources = append (git_sources , git_source )
111129 slog .Info ("Found Git source" , slog .String ("source" , git_source ))
130+ activeConfigs = append (activeConfigs , cfg )
112131 } else {
113132 slog .Warn ("Not a valid URL for Git source" , slog .String ("url" , cfg .URL ))
114133 }
115134 }
116135 }
117136
137+ // Emit a diagnostic to make it easy for users to see that private registry
138+ // configurations were picked up by the Go analysis.
139+ if len (activeConfigs ) > 0 {
140+ prettyConfigs := []string {}
141+ for i := range activeConfigs {
142+ prettyConfigs = append (prettyConfigs , activeConfigs [i ].Pretty ())
143+ }
144+
145+ diagnostics .EmitPrivateRegistryUsed (diagnostics .DefaultWriter , prettyConfigs )
146+ }
147+
148+ // Assemble environment variables for Go.
118149 goprivate := []string {}
119150
120151 if len (goproxy_servers ) > 0 {
0 commit comments