Skip to content

Commit

Permalink
fix: logging for remote network calls (#3140)
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <[email protected]>
  • Loading branch information
kzantow authored Aug 20, 2024
1 parent 511cc9c commit 95b4a88
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
15 changes: 13 additions & 2 deletions internal/spdxlicense/license_list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions syft/pkg/cataloger/golang/licenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func getModule(proxies []string, moduleName, moduleVersion string) (urlPrefix st
case "file":
p := filepath.Join(u.Path, moduleName, "@v", moduleVersion)
urlPrefix = path.Join("file://", p) + "/"
log.WithFields("path", p).Info("looking for go module in filesystem")
fsys = os.DirFS(p)
}
if fsys != nil {
Expand All @@ -264,6 +265,7 @@ func getModuleProxy(proxy string, moduleName string, moduleVersion string) (modu
u := fmt.Sprintf("%s/%s/@v/%s.zip", proxy, moduleName, moduleVersion)

// get the module zip
log.WithFields("url", u).Info("downloading go module from proxy")
resp, err := http.Get(u) //nolint:gosec
if err != nil {
return "", nil, err
Expand Down Expand Up @@ -334,6 +336,8 @@ func getModuleRepository(moduleName string, moduleVersion string) (string, fs.FS
f := memfs.New()
buf := &bytes.Buffer{}
repoURL := fmt.Sprintf("https://%s", repoName)

log.WithFields("repoURL", repoURL, "ref", cloneRefName).Info("cloning go module repository")
r, err := git.Clone(memory.NewStorage(), f, &git.CloneOptions{
URL: repoURL,
ReferenceName: cloneRefName,
Expand Down
6 changes: 3 additions & 3 deletions syft/pkg/cataloger/javascript/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ func formatNpmRegistryURL(baseURL, packageName, version string) (requestURL stri
return requestURL, nil
}

func getLicenseFromNpmRegistry(basURL, packageName, version string) (string, error) {
func getLicenseFromNpmRegistry(baseURL, packageName, version string) (string, error) {
// "https://registry.npmjs.org/%s/%s", packageName, version
requestURL, err := formatNpmRegistryURL(basURL, packageName, version)
requestURL, err := formatNpmRegistryURL(baseURL, packageName, version)
if err != nil {
return "", fmt.Errorf("unable to format npm request for pkg:version %s%s; %w", packageName, version, err)
}
log.Tracef("trying to fetch remote package %s", requestURL)
log.WithFields("url", requestURL).Info("downloading javascript package from npm")

npmRequest, err := http.NewRequest(http.MethodGet, requestURL, nil)
if err != nil {
Expand Down

0 comments on commit 95b4a88

Please sign in to comment.