@@ -19,6 +19,8 @@ package sbom
1919import (
2020 "context"
2121 "fmt"
22+ "os"
23+ "strconv"
2224 "strings"
2325
2426 "github.com/aquasecurity/trivy/pkg/fanal/analyzer"
@@ -31,9 +33,9 @@ import (
3133 aimage "github.com/aquasecurity/trivy/pkg/fanal/artifact/image"
3234 "github.com/aquasecurity/trivy/pkg/fanal/cache"
3335 "github.com/aquasecurity/trivy/pkg/fanal/image"
34- "github.com/aquasecurity/trivy/pkg/fanal/secret"
3536 stypes "github.com/aquasecurity/trivy/pkg/fanal/types"
3637 "github.com/aquasecurity/trivy/pkg/fanal/utils"
38+ "github.com/atomist-skills/go-skill"
3739 "github.com/pkg/errors"
3840
3941 "github.com/docker/index-cli-plugin/registry"
@@ -47,7 +49,6 @@ func trivySbom(cache *registry.ImageCache, lm *types.LayerMapping, resultChan ch
4749 Packages : make ([]types.Package , 0 ),
4850 Secrets : make ([]types.Secret , 0 ),
4951 }
50-
5152 defer close (resultChan )
5253
5354 cacheClient , err := initializeCache ()
@@ -66,8 +67,8 @@ func trivySbom(cache *registry.ImageCache, lm *types.LayerMapping, resultChan ch
6667 resultChan <- result
6768 return
6869 }
69-
70- art , err := aimage .NewArtifact (img , cacheClient , artifact. Option {} )
70+
71+ art , err := aimage .NewArtifact (img , cacheClient , configOptions () )
7172 if err != nil {
7273 result .Status = types .Failed
7374 result .Error = errors .Wrap (err , "failed to create new artifact" )
@@ -84,14 +85,15 @@ func trivySbom(cache *registry.ImageCache, lm *types.LayerMapping, resultChan ch
8485 }
8586
8687 a := applier .NewApplier (cacheClient )
87- scanner , err := secret .NewScanner ("" )
88+ /* scanner, err := secret.NewScanner("")
8889 if err != nil {
8990 result.Status = types.Failed
9091 result.Error = errors.Wrap(err, "failed to create secret scanner")
9192 resultChan <- result
9293 return
93- }
94- config := & cache .Source .Image .Metadata .Config
94+ }*/
95+
96+ /*config := &cache.Source.Image.Metadata.Config
9597 for o, h := range config.History {
9698 secrets := scanner.Scan(secret.ScanArgs{
9799 FilePath: "history",
@@ -129,7 +131,7 @@ func trivySbom(cache *registry.ImageCache, lm *types.LayerMapping, resultChan ch
129131 Type: "env",
130132 }))
131133 }
132- }
134+ }*/
133135 for v := range imageInfo .BlobIDs {
134136 mergedLayer , err := a .ApplyLayers (imageInfo .ID , []string {imageInfo .BlobIDs [v ]})
135137 if err != nil {
@@ -211,15 +213,24 @@ func trivySbom(cache *registry.ImageCache, lm *types.LayerMapping, resultChan ch
211213 }
212214 }
213215 }
214-
216+ skill . Log . Debug ( "trivy indexing completed" )
215217 resultChan <- result
216218}
217219
218220func initializeCache () (cache.Cache , error ) {
219- var cacheClient cache.Cache
220- var err error
221- cacheClient , err = cache .NewFSCache (utils .CacheDir ())
222- return cacheClient , err
221+ return cache .NewFSCache (utils .CacheDir ())
222+ }
223+
224+ func configOptions () artifact.Option {
225+ opts := artifact.Option {
226+ DisabledAnalyzers : []analyzer.Type {analyzer .TypeDockerfile , analyzer .TypeSecret , analyzer .TypeHelm , analyzer .TypeTerraform , analyzer .TypeJSON , analyzer .TypeYaml },
227+ }
228+ if v , ok := os .LookupEnv ("ATOMIST_OFFLINE" ); ok {
229+ if o , err := strconv .ParseBool (v ); err == nil && o {
230+ opts .Offline = true
231+ }
232+ }
233+ return opts
223234}
224235
225236func convertSecretFindings (s stypes.Secret , source types.SecretSource ) types.Secret {
0 commit comments