Skip to content
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.

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

fix: logging for remote network calls #3140

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading