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

add set layer limit #3464

Merged
merged 2 commits into from
Dec 2, 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
14 changes: 13 additions & 1 deletion cmd/syft/internal/options/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"sort"
"strings"

stereoscopeFile "github.com/anchore/stereoscope/pkg/file"
"github.com/dustin/go-humanize"
"github.com/scylladb/go-set/strset"

"github.com/anchore/clio"
Expand All @@ -27,6 +29,8 @@ var _ interface {
clio.FieldDescriber
} = (*sourceConfig)(nil)

var _ clio.PostLoader = (*imageSource)(nil)

func (o *sourceConfig) DescribeFields(descriptions clio.FieldDescriptionSet) {
descriptions.Add(&o.File.Digests, `the file digest algorithms to use on the scanned file (options: "md5", "sha1", "sha224", "sha256", "sha384", "sha512")`)
descriptions.Add(&o.Image.DefaultPullSource, `allows users to specify which image source should be used to generate the sbom
Expand All @@ -35,6 +39,7 @@ valid values are: registry, docker, podman`)

type imageSource struct {
DefaultPullSource string `json:"default-pull-source" yaml:"default-pull-source" mapstructure:"default-pull-source"`
MaxLayerSize string `json:"max-layer-size" yaml:"max-layer-size" mapstructure:"max-layer-size"`
}

func defaultSourceConfig() sourceConfig {
Expand All @@ -56,7 +61,14 @@ func (c *fileSource) PostLoad() error {
return nil
}

func (c imageSource) PostLoad() error {
func (c *imageSource) PostLoad() error {
if c.MaxLayerSize != "" {
perFileReadLimit, err := humanize.ParseBytes(c.MaxLayerSize)
if err != nil {
return err
}
stereoscopeFile.SetPerFileReadLimit(int64(perFileReadLimit))
}
return checkDefaultSourceValues(c.DefaultPullSource)
}

Expand Down
Loading