From b2cdb991691a5f544bcda9232eced6b2385c0f24 Mon Sep 17 00:00:00 2001 From: nikpivkin Date: Tue, 20 Aug 2024 11:21:42 +0600 Subject: [PATCH] refactor: rename DebugLogger to Logger Signed-off-by: nikpivkin --- pkg/iac/scanners/terraform/parser/load_module.go | 2 +- .../scanners/terraform/parser/module_retrieval.go | 4 ++-- pkg/iac/scanners/terraform/parser/resolvers/cache.go | 8 ++++---- pkg/iac/scanners/terraform/parser/resolvers/local.go | 4 ++-- .../scanners/terraform/parser/resolvers/options.go | 2 +- .../scanners/terraform/parser/resolvers/registry.go | 12 ++++++------ .../scanners/terraform/parser/resolvers/remote.go | 8 ++++---- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pkg/iac/scanners/terraform/parser/load_module.go b/pkg/iac/scanners/terraform/parser/load_module.go index e23af72b6f19..78ebe3430b4e 100644 --- a/pkg/iac/scanners/terraform/parser/load_module.go +++ b/pkg/iac/scanners/terraform/parser/load_module.go @@ -142,7 +142,7 @@ func (e *evaluator) loadExternalModule(ctx context.Context, b *terraform.Block, WorkingDir: e.projectRootPath, Name: b.FullName(), ModulePath: e.modulePath, - DebugLogger: log.WithPrefix("module resolver"), + Logger: log.WithPrefix("module resolver"), AllowDownloads: e.allowDownloads, SkipCache: e.skipCachedModules, } diff --git a/pkg/iac/scanners/terraform/parser/module_retrieval.go b/pkg/iac/scanners/terraform/parser/module_retrieval.go index d6ac0e02d26d..cc374b68eeb7 100644 --- a/pkg/iac/scanners/terraform/parser/module_retrieval.go +++ b/pkg/iac/scanners/terraform/parser/module_retrieval.go @@ -21,13 +21,13 @@ var defaultResolvers = []ModuleResolver{ } func resolveModule(ctx context.Context, current fs.FS, opt resolvers.Options) (filesystem fs.FS, sourcePrefix, downloadPath string, err error) { - opt.DebugLogger.Debug("Resolving module", + opt.Logger.Debug("Resolving module", log.String("name", opt.Name), log.String("source", opt.Source)) for _, resolver := range defaultResolvers { if filesystem, prefix, path, applies, err := resolver.Resolve(ctx, current, opt); err != nil { return nil, "", "", err } else if applies { - opt.DebugLogger.Debug("Module resolved", log.FilePath(path)) + opt.Logger.Debug("Module resolved", log.FilePath(path)) return filesystem, prefix, path, nil } } diff --git a/pkg/iac/scanners/terraform/parser/resolvers/cache.go b/pkg/iac/scanners/terraform/parser/resolvers/cache.go index f2d1ed8c737e..24f803f60139 100644 --- a/pkg/iac/scanners/terraform/parser/resolvers/cache.go +++ b/pkg/iac/scanners/terraform/parser/resolvers/cache.go @@ -44,21 +44,21 @@ func locateCacheDir(cacheDir string) (string, error) { func (r *cacheResolver) Resolve(_ context.Context, _ fs.FS, opt Options) (filesystem fs.FS, prefix, downloadPath string, applies bool, err error) { if opt.SkipCache { - opt.DebugLogger.Debug("Module caching is disabled") + opt.Logger.Debug("Module caching is disabled") return nil, "", "", false, nil } cacheFS, err := locateCacheFS(opt.CacheDir) if err != nil { - opt.DebugLogger.Debug("No cache filesystem is available on this machine.", log.Err(err)) + opt.Logger.Debug("No cache filesystem is available on this machine.", log.Err(err)) return nil, "", "", false, nil } src, subdir := splitPackageSubdirRaw(opt.Source) key := cacheKey(src, opt.Version) - opt.DebugLogger.Debug("Trying to resolve module via cache", log.String("key", key)) + opt.Logger.Debug("Trying to resolve module via cache", log.String("key", key)) if info, err := fs.Stat(cacheFS, filepath.ToSlash(key)); err == nil && info.IsDir() { - opt.DebugLogger.Debug("Module resolved from cache", log.String("key", key)) + opt.Logger.Debug("Module resolved from cache", log.String("key", key)) cacheDir, err := locateCacheDir(opt.CacheDir) if err != nil { return nil, "", "", true, err diff --git a/pkg/iac/scanners/terraform/parser/resolvers/local.go b/pkg/iac/scanners/terraform/parser/resolvers/local.go index 4fe10efaa688..a11a294edcfb 100644 --- a/pkg/iac/scanners/terraform/parser/resolvers/local.go +++ b/pkg/iac/scanners/terraform/parser/resolvers/local.go @@ -19,14 +19,14 @@ func (r *localResolver) Resolve(_ context.Context, target fs.FS, opt Options) (f } joined := path.Clean(path.Join(opt.ModulePath, opt.Source)) if _, err := fs.Stat(target, filepath.ToSlash(joined)); err == nil { - opt.DebugLogger.Debug("Module resolved locally", + opt.Logger.Debug("Module resolved locally", log.String("name", opt.Name), log.FilePath(joined), ) return target, "", joined, true, nil } clean := path.Clean(opt.Source) - opt.DebugLogger.Debug("Module resolved locally", + opt.Logger.Debug("Module resolved locally", log.String("name", opt.Name), log.FilePath(clean), ) return target, "", clean, true, nil diff --git a/pkg/iac/scanners/terraform/parser/resolvers/options.go b/pkg/iac/scanners/terraform/parser/resolvers/options.go index 2a23a1b8ae7a..73fd39689e84 100644 --- a/pkg/iac/scanners/terraform/parser/resolvers/options.go +++ b/pkg/iac/scanners/terraform/parser/resolvers/options.go @@ -8,7 +8,7 @@ import ( type Options struct { Source, OriginalSource, Version, OriginalVersion, WorkingDir, Name, ModulePath string - DebugLogger *log.Logger + Logger *log.Logger AllowDownloads bool SkipCache bool RelativePath string diff --git a/pkg/iac/scanners/terraform/parser/resolvers/registry.go b/pkg/iac/scanners/terraform/parser/resolvers/registry.go index 188fadb38a15..471416463cad 100644 --- a/pkg/iac/scanners/terraform/parser/resolvers/registry.go +++ b/pkg/iac/scanners/terraform/parser/resolvers/registry.go @@ -60,9 +60,9 @@ func (r *registryResolver) Resolve(ctx context.Context, target fs.FS, opt Option token, err = getPrivateRegistryTokenFromEnvVars(hostname) if err == nil { - opt.DebugLogger.Debug("Found a token for the registry", log.String("hostname", hostname)) + opt.Logger.Debug("Found a token for the registry", log.String("hostname", hostname)) } else { - opt.DebugLogger.Error( + opt.Logger.Error( "Failed to find a token for the registry", log.String("hostname", hostname), log.Err(err)) } @@ -72,7 +72,7 @@ func (r *registryResolver) Resolve(ctx context.Context, target fs.FS, opt Option if opt.Version != "" { versionUrl := fmt.Sprintf("https://%s/v1/modules/%s/versions", hostname, moduleName) - opt.DebugLogger.Debug("Requesting module versions from registry using", + opt.Logger.Debug("Requesting module versions from registry using", log.String("url", versionUrl)) req, err := http.NewRequestWithContext(ctx, http.MethodGet, versionUrl, nil) if err != nil { @@ -98,7 +98,7 @@ func (r *registryResolver) Resolve(ctx context.Context, target fs.FS, opt Option if err != nil { return nil, "", "", true, err } - opt.DebugLogger.Debug("Found module version", + opt.Logger.Debug("Found module version", log.String("version", opt.Version), log.String("constraint", inputVersion)) } @@ -109,7 +109,7 @@ func (r *registryResolver) Resolve(ctx context.Context, target fs.FS, opt Option url = fmt.Sprintf("https://%s/v1/modules/%s/%s/download", hostname, moduleName, opt.Version) } - opt.DebugLogger.Debug("Requesting module source from registry", log.String("url", url)) + opt.Logger.Debug("Requesting module source from registry", log.String("url", url)) req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { @@ -150,7 +150,7 @@ func (r *registryResolver) Resolve(ctx context.Context, target fs.FS, opt Option return nil, "", "", true, fmt.Errorf("no source was found for the registry at %s", hostname) } - opt.DebugLogger.Debug("Module resolved via registry to new source", + opt.Logger.Debug("Module resolved via registry to new source", log.String("source", opt.Source), log.String("name", moduleName)) filesystem, prefix, downloadPath, _, err = Remote.Resolve(ctx, target, opt) diff --git a/pkg/iac/scanners/terraform/parser/resolvers/remote.go b/pkg/iac/scanners/terraform/parser/resolvers/remote.go index 0c3e69f0aadb..467f2cee6970 100644 --- a/pkg/iac/scanners/terraform/parser/resolvers/remote.go +++ b/pkg/iac/scanners/terraform/parser/resolvers/remote.go @@ -24,7 +24,7 @@ var Remote = &remoteResolver{ func (r *remoteResolver) incrementCount(o Options) { atomic.CompareAndSwapInt32(&r.count, r.count, r.count+1) - o.DebugLogger.Debug("Incrementing the download counter", log.Int("count", int(r.count))) + o.Logger.Debug("Incrementing the download counter", log.Int("count", int(r.count))) } func (r *remoteResolver) GetDownloadCount() int { @@ -42,7 +42,7 @@ func (r *remoteResolver) Resolve(ctx context.Context, _ fs.FS, opt Options) (fil src, subdir := splitPackageSubdirRaw(opt.OriginalSource) key := cacheKey(src, opt.OriginalVersion) - opt.DebugLogger.Debug("Caching module", log.String("key", key)) + opt.Logger.Debug("Caching module", log.String("key", key)) baseCacheDir, err := locateCacheDir(opt.CacheDir) if err != nil { @@ -54,7 +54,7 @@ func (r *remoteResolver) Resolve(ctx context.Context, _ fs.FS, opt Options) (fil } r.incrementCount(opt) - opt.DebugLogger.Debug("Successfully resolve module via remote download", + opt.Logger.Debug("Successfully resolve module via remote download", log.String("name", opt.Name), log.String("source", opt.Source), ) @@ -72,7 +72,7 @@ func (r *remoteResolver) download(ctx context.Context, opt Options, dst string) // Overwrite the file getter so that a file will be copied getter.Getters["file"] = &getter.FileGetter{Copy: true} - opt.DebugLogger.Debug("Downloading module", log.String("source", opt.Source)) + opt.Logger.Debug("Downloading module", log.String("source", opt.Source)) // Build the client client := &getter.Client{