Skip to content

Commit

Permalink
refactor: rename DebugLogger to Logger
Browse files Browse the repository at this point in the history
Signed-off-by: nikpivkin <[email protected]>
  • Loading branch information
nikpivkin committed Aug 20, 2024
1 parent 1cb0263 commit b2cdb99
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pkg/iac/scanners/terraform/parser/load_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/iac/scanners/terraform/parser/module_retrieval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/iac/scanners/terraform/parser/resolvers/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/iac/scanners/terraform/parser/resolvers/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/iac/scanners/terraform/parser/resolvers/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pkg/iac/scanners/terraform/parser/resolvers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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 {
Expand All @@ -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))
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/iac/scanners/terraform/parser/resolvers/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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),
)
Expand All @@ -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{
Expand Down

0 comments on commit b2cdb99

Please sign in to comment.