Skip to content

Commit

Permalink
chore(misconfig): add prefixes
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 committed Oct 2, 2024
1 parent 1c0f8c2 commit 6d648a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (c *Client) LoadBuiltinChecks() ([]string, error) {

// NeedsUpdate returns if the default check should be updated
func (c *Client) NeedsUpdate(ctx context.Context, registryOpts types.RegistryOptions) (bool, error) {
meta, err := c.GetMetadata()
meta, err := c.GetMetadata(ctx)
if err != nil {
return true, nil
}
Expand Down Expand Up @@ -213,17 +213,17 @@ func (c *Client) updateMetadata(digest string, now time.Time) error {
return nil
}

func (c *Client) GetMetadata() (*Metadata, error) {
func (c *Client) GetMetadata(ctx context.Context) (*Metadata, error) {
f, err := os.Open(c.metadataPath())
if err != nil {
log.Debug("Failed to open the check metadata", log.Err(err))
log.DebugContext(ctx, "Failed to open the check metadata", log.Err(err))
return nil, err
}
defer f.Close()

var meta Metadata
if err = json.NewDecoder(f).Decode(&meta); err != nil {
log.Warn("Check metadata decode error", log.Err(err))
log.WarnContext(ctx, "Check metadata decode error", log.Err(err))
return nil, err
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package version

import (
"context"
"fmt"
"path/filepath"

Expand Down Expand Up @@ -80,7 +81,8 @@ func NewVersionInfo(cacheDir string) VersionInfo {
log.Debug("Failed to instantiate policy client", log.Err(err))
}
if pc != nil && err == nil {
pbMetaRaw, err := pc.GetMetadata()
ctx := log.WithContextPrefix(context.TODO(), log.PrefixChecksBundle)
pbMetaRaw, err := pc.GetMetadata(ctx)

if err != nil {
log.Debug("Failed to get policy metadata", log.Err(err))
Expand Down

0 comments on commit 6d648a8

Please sign in to comment.