Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 0d53038

Browse files
committed
Add offline mode
1 parent 97956e0 commit 0d53038

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

sbom/syft.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/anchore/syft/syft/pkg/cataloger/deb"
3232
"github.com/anchore/syft/syft/pkg/cataloger/rpm"
3333
"github.com/anchore/syft/syft/source"
34+
"github.com/atomist-skills/go-skill"
3435
"github.com/pkg/errors"
3536

3637
"github.com/docker/index-cli-plugin/registry"
@@ -49,15 +50,14 @@ func syftSbom(cache *registry.ImageCache, lm *types.LayerMapping, resultChan cha
4950
}
5051

5152
defer close(resultChan)
52-
5353
packageCatalog, packageRelationships, distro, err := syft.CatalogPackages(cache.Source, cataloger.DefaultConfig())
5454
if err != nil {
5555
result.Status = types.Failed
5656
result.Error = errors.Wrap(err, "failed to index image")
5757
resultChan <- result
5858
return
5959
}
60-
60+
6161
d, qualifiers := osQualifiers(distro)
6262
result.Distro = d
6363

@@ -111,15 +111,15 @@ func syftSbom(cache *registry.ImageCache, lm *types.LayerMapping, resultChan cha
111111
}
112112
}
113113
}
114-
114+
115115
result.Packages = make([]types.Package, 0)
116116
packages := packageCatalog.Sorted()
117117
for _, p := range packages {
118118
pkg := toPackage(p, packageRelationships, qualifiers, lm, pm)
119119
result.Packages = append(result.Packages, pkg...)
120120
}
121-
122121
result.Packages = append(result.Packages, detect.AdditionalPackages(result.Packages, cache.Source, lm)...)
122+
skill.Log.Debug("syft indexing completed")
123123
resultChan <- result
124124
}
125125

sbom/trivy.go

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package sbom
1919
import (
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

218220
func 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

225236
func convertSecretFindings(s stypes.Secret, source types.SecretSource) types.Secret {

0 commit comments

Comments
 (0)