From 4f111b93421556b269c62aa569518f3f97b1eb11 Mon Sep 17 00:00:00 2001 From: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com> Date: Wed, 25 Dec 2024 12:17:08 +0600 Subject: [PATCH] refactor(python): use once + debug for `License acquired from METADATA...` logs (#8175) --- pkg/dependency/parser/python/packaging/parse.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/dependency/parser/python/packaging/parse.go b/pkg/dependency/parser/python/packaging/parse.go index 58ecac200db5..c7bb54fe9680 100644 --- a/pkg/dependency/parser/python/packaging/parse.go +++ b/pkg/dependency/parser/python/packaging/parse.go @@ -6,6 +6,7 @@ import ( "io" "net/textproto" "strings" + "sync" "golang.org/x/xerrors" @@ -15,6 +16,8 @@ import ( xio "github.com/aquasecurity/trivy/pkg/x/io" ) +var licenseMetadataInfoOnce sync.Once + type Parser struct { logger *log.Logger } @@ -70,7 +73,10 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc if l := h.Get("License"); l != "" { if len(licenses) != 0 { - p.logger.Info("License acquired from METADATA classifiers may be subject to additional terms", + licenseMetadataInfoOnce.Do(func() { + p.logger.Info("Licenses acquired from one or more METADATA files may be subject to additional terms. Use `--debug` flag to see all affected packages.") + }) + p.logger.Debug("License acquired from METADATA classifiers may be subject to additional terms", log.String("name", name), log.String("version", version)) } else { license = l