Skip to content

Commit c1ea59a

Browse files
committed
chore(cli): pr comment updates
Updates to logging and tests based on the PR comments
1 parent 952ca4a commit c1ea59a

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

pkg/cloud/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func GetConfigs(ctx context.Context, opts *flag.Options, accessToken string) err
4646

4747
if opts.CloudOptions.SecretConfig && opts.Scanners.Enabled(types.SecretScanner) {
4848
if opts.SecretOptions.SecretConfigPath != "" {
49-
logger.Warn("Secret config path already set", log.String("configPath", opts.SecretOptions.SecretConfigPath))
49+
logger.Warn("Secret config path already set", log.FilePath(opts.SecretOptions.SecretConfigPath))
5050
return nil
5151
}
5252

@@ -64,7 +64,7 @@ func GetConfigs(ctx context.Context, opts *flag.Options, accessToken string) err
6464
// getConfigFromTrivyCloud downloads a config from Trivy Cloud and saves it to a file
6565
// it returns the path to the config file if it was downloaded successfully, otherwise it returns an error
6666
func getConfigFromTrivyCloud(ctx context.Context, client *http.Client, opts *flag.Options, accessToken string, configType ConfigType) (string, error) {
67-
logger := log.WithPrefix(log.PrefixCloud)
67+
logger := log.WithPrefix(log.PrefixCloud).With("configType", configType)
6868
configTypeStr := string(configType)
6969
configDir := filepath.Join(fsutils.TrivyHomeDir(), "cloud", configTypeStr)
7070
if err := os.MkdirAll(configDir, os.ModePerm); err != nil {
@@ -74,11 +74,11 @@ func getConfigFromTrivyCloud(ctx context.Context, client *http.Client, opts *fla
7474
configFilename := filepath.Join(configDir, "config.yaml")
7575
// Return cached config if it was updated within the last hour
7676
if stat, err := os.Stat(configFilename); err == nil && stat.ModTime().After(time.Now().Add(-configCacheTTL)) {
77-
logger.Debug("Config found in cache", log.String("configType", string(configType)), log.String("configPath", configFilename))
77+
logger.Debug("Config found in cache", log.FilePath(configFilename))
7878
return configFilename, nil
7979
}
8080

81-
logger.Debug("Config not found in cache", log.String("configType", string(configType)), log.String("configPath", configFilename))
81+
logger.Debug("Config not found in cache", log.FilePath(configFilename))
8282
configPath, ok := configPaths[configType]
8383
if !ok {
8484
return "", xerrors.Errorf("unknown config type: %s", configType)

pkg/commands/cloud/run_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cloud
22

33
import (
4-
"context"
54
"net/http"
65
"net/http/httptest"
76
"testing"
@@ -129,7 +128,7 @@ func TestUpdateOptsForCloudIntegration(t *testing.T) {
129128
t.Setenv("XDG_DATA_HOME", tempDir)
130129
mockServer.configAvailable = tt.configAvailable
131130

132-
err := UpdateOptsForCloudIntegration(context.Background(), tt.opts)
131+
err := UpdateOptsForCloudIntegration(t.Context(), tt.opts)
133132

134133
if tt.errorContains != "" {
135134
require.ErrorContains(t, err, tt.errorContains)

0 commit comments

Comments
 (0)