@@ -49,36 +49,41 @@ var (
49
49
)
50
50
51
51
type Artifact struct {
52
- image types.Image
53
- cache cache.ArtifactCache
54
- analyzer analyzer.Analyzer
55
- hookManager hook.Manager
56
- scanner scanner.Scanner
52
+ image types.Image
53
+ cache cache.ArtifactCache
54
+ walker walker.LayerTar
55
+ analyzer analyzer.Analyzer
56
+ hookManager hook.Manager
57
+ scanner scanner.Scanner
58
+
59
+ artifactOption artifact.Option
57
60
configScannerOption config.ScannerOption
58
61
}
59
62
60
- func NewArtifact (img types.Image , c cache.ArtifactCache , disabledAnalyzers []analyzer.Type , disabledHooks []hook.Type ,
61
- opt config.ScannerOption ) (artifact.Artifact , error ) {
63
+ func NewArtifact (img types.Image , c cache.ArtifactCache , artifactOpt artifact.Option , scannerOpt config.ScannerOption ) (artifact.Artifact , error ) {
62
64
// Register config analyzers
63
- if err := config .RegisterConfigAnalyzers (opt .FilePatterns ); err != nil {
65
+ if err := config .RegisterConfigAnalyzers (scannerOpt .FilePatterns ); err != nil {
64
66
return nil , xerrors .Errorf ("config scanner error: %w" , err )
65
67
}
66
68
67
- s , err := scanner .New ("" , opt .Namespaces , opt .PolicyPaths , opt .DataPaths , opt .Trace )
69
+ s , err := scanner .New ("" , scannerOpt .Namespaces , scannerOpt .PolicyPaths , scannerOpt .DataPaths , scannerOpt .Trace )
68
70
if err != nil {
69
71
return nil , xerrors .Errorf ("scanner error: %w" , err )
70
72
}
71
73
72
- disabledAnalyzers = append (disabledAnalyzers , defaultDisabledAnalyzers ... )
73
- disabledHooks = append (disabledHooks , defaultDisabledHooks ... )
74
+ disabledAnalyzers : = append (artifactOpt . DisabledAnalyzers , defaultDisabledAnalyzers ... )
75
+ disabledHooks : = append (artifactOpt . DisabledHooks , defaultDisabledHooks ... )
74
76
75
77
return Artifact {
76
- image : img ,
77
- cache : c ,
78
- analyzer : analyzer .NewAnalyzer (disabledAnalyzers ),
79
- hookManager : hook .NewManager (disabledHooks ),
80
- scanner : s ,
81
- configScannerOption : opt ,
78
+ image : img ,
79
+ cache : c ,
80
+ walker : walker .NewLayerTar (artifactOpt .SkipFiles , artifactOpt .SkipDirs ),
81
+ analyzer : analyzer .NewAnalyzer (disabledAnalyzers ),
82
+ hookManager : hook .NewManager (disabledHooks ),
83
+ scanner : s ,
84
+
85
+ artifactOption : artifactOpt ,
86
+ configScannerOption : scannerOpt ,
82
87
}, nil
83
88
}
84
89
@@ -142,7 +147,7 @@ func (a Artifact) Inspect(ctx context.Context) (types.ArtifactReference, error)
142
147
func (a Artifact ) calcCacheKeys (imageID string , diffIDs []string ) (string , []string , map [string ]string , error ) {
143
148
144
149
// Pass an empty config scanner option so that the cache key can be the same, even when policies are updated.
145
- imageKey , err := cache .CalcKey (imageID , a .analyzer .ImageConfigAnalyzerVersions (), nil , & config.ScannerOption {})
150
+ imageKey , err := cache .CalcKey (imageID , a .analyzer .ImageConfigAnalyzerVersions (), nil , artifact. Option {}, config.ScannerOption {})
146
151
if err != nil {
147
152
return "" , nil , nil , err
148
153
}
@@ -151,7 +156,7 @@ func (a Artifact) calcCacheKeys(imageID string, diffIDs []string) (string, []str
151
156
hookVersions := a .hookManager .Versions ()
152
157
var layerKeys []string
153
158
for _ , diffID := range diffIDs {
154
- blobKey , err := cache .CalcKey (diffID , a .analyzer .AnalyzerVersions (), hookVersions , & a .configScannerOption )
159
+ blobKey , err := cache .CalcKey (diffID , a .analyzer .AnalyzerVersions (), hookVersions , a . artifactOption , a .configScannerOption )
155
160
if err != nil {
156
161
return "" , nil , nil , err
157
162
}
@@ -218,7 +223,7 @@ func (a Artifact) inspectLayer(ctx context.Context, diffID string) (types.BlobIn
218
223
result := new (analyzer.AnalysisResult )
219
224
limit := semaphore .NewWeighted (parallel )
220
225
221
- opqDirs , whFiles , err := walker .WalkLayerTar (r , func (filePath string , info os.FileInfo , opener analyzer.Opener ) error {
226
+ opqDirs , whFiles , err := a . walker .Walk (r , func (filePath string , info os.FileInfo , opener analyzer.Opener ) error {
222
227
if err = a .analyzer .AnalyzeFile (ctx , & wg , limit , result , "" , filePath , info , opener ); err != nil {
223
228
return xerrors .Errorf ("failed to analyze %s: %w" , filePath , err )
224
229
}
0 commit comments