Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide more context to artifact inspect errors #40

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ import (
"io"
"os"
"reflect"
"slices"
"strings"
"sync"

"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
_ "github.com/aquasecurity/trivy/pkg/fanal/analyzer/all"
"github.com/aquasecurity/trivy/pkg/fanal/artifact"
"github.com/aquasecurity/trivy/pkg/fanal/handler"
"github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/aquasecurity/trivy/pkg/fanal/walker"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/samber/lo"
"github.com/sirupsen/logrus"
"slices"
"golang.org/x/sync/semaphore"

_ "github.com/aquasecurity/trivy/pkg/fanal/analyzer/all"

_ "github.com/castai/image-analyzer/apk"
_ "github.com/castai/image-analyzer/dpkg"
_ "github.com/castai/image-analyzer/rpm"
Expand Down Expand Up @@ -128,12 +127,16 @@ func (a Artifact) Inspect(ctx context.Context) (*ArtifactReference, error) {

// Convert image ID and layer IDs to cache keys
imageKey, layerKeys, layerKeyMap := a.calcCacheKeys(imageID, diffIDs)
a.log.Debugf("image key: %s", imageKey)
a.log.Debugf("layer keys: %v", layerKeys)
a.log.Debugf("layer key map: %v", layerKeyMap)

// Check if image artifact info already cached.
cachedArtifactInfo, err := a.getCachedArtifactInfo(ctx, imageKey)
if err != nil && !errors.Is(err, ErrCacheNotFound) {
return nil, err
return nil, fmt.Errorf("unable to access artifact cache: %w", err)
}

var missingImageKey string
if cachedArtifactInfo == nil {
missingImageKey = imageKey
Expand All @@ -142,7 +145,7 @@ func (a Artifact) Inspect(ctx context.Context) (*ArtifactReference, error) {
// Find cached layers
cachedLayers, err := a.getCachedLayers(ctx, layerKeys)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to access layers cache: %w", err)
}
missingLayersKeys := lo.Filter(layerKeys, func(v string, _ int) bool {
_, ok := cachedLayers[v]
Expand Down