-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support repository and filesystem scan (#503)
* refactor: embed config * refactor: replace image and layer with artifact and blob * feat(config): add ArtifactConfig * fix(scanner): use Artifact * test(scanner): update mocks * feat: add repo and fs subcommands * chore(mod): update * refactor: fix warn message * feat(cli): add --no-progress to repo and fs * mod: Update fanal dependency Signed-off-by: Simarpreet Singh <[email protected]> Co-authored-by: Simarpreet Singh <[email protected]>
- Loading branch information
Showing
47 changed files
with
1,482 additions
and
1,025 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package artifact | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/urfave/cli/v2" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/aquasecurity/fanal/cache" | ||
"github.com/aquasecurity/trivy/internal/artifact/config" | ||
"github.com/aquasecurity/trivy/pkg/scanner" | ||
) | ||
|
||
func filesystemScanner(ctx context.Context, dir string, ac cache.ArtifactCache, lac cache.LocalArtifactCache, timeout time.Duration) ( | ||
scanner.Scanner, func(), error) { | ||
s, cleanup, err := initializeFilesystemScanner(ctx, dir, ac, lac) | ||
if err != nil { | ||
return scanner.Scanner{}, func() {}, xerrors.Errorf("unable to initialize a filesystem scanner: %w", err) | ||
} | ||
return s, cleanup, nil | ||
} | ||
|
||
func FilesystemRun(cliCtx *cli.Context) error { | ||
c, err := config.New(cliCtx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// initialize config | ||
if err = c.Init(false); err != nil { | ||
return xerrors.Errorf("failed to initialize options: %w", err) | ||
} | ||
|
||
return run(c, filesystemScanner) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package artifact | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/urfave/cli/v2" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/aquasecurity/fanal/cache" | ||
"github.com/aquasecurity/trivy/internal/artifact/config" | ||
"github.com/aquasecurity/trivy/pkg/scanner" | ||
) | ||
|
||
func archiveScanner(ctx context.Context, input string, ac cache.ArtifactCache, lac cache.LocalArtifactCache, timeout time.Duration) ( | ||
scanner.Scanner, func(), error) { | ||
s, err := initializeArchiveScanner(ctx, input, ac, lac, timeout) | ||
if err != nil { | ||
return scanner.Scanner{}, func() {}, xerrors.Errorf("unable to initialize the archive scanner: %w", err) | ||
} | ||
return s, func() {}, nil | ||
} | ||
|
||
func dockerScanner(ctx context.Context, imageName string, ac cache.ArtifactCache, lac cache.LocalArtifactCache, timeout time.Duration) ( | ||
scanner.Scanner, func(), error) { | ||
s, cleanup, err := initializeDockerScanner(ctx, imageName, ac, lac, timeout) | ||
if err != nil { | ||
return scanner.Scanner{}, func() {}, xerrors.Errorf("unable to initialize a docker scanner: %w", err) | ||
} | ||
return s, cleanup, nil | ||
} | ||
|
||
func ImageRun(cliCtx *cli.Context) error { | ||
c, err := config.New(cliCtx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// initialize config | ||
if err = c.Init(true); err != nil { | ||
return xerrors.Errorf("failed to initialize options: %w", err) | ||
} | ||
|
||
if c.Input != "" { | ||
// scan tar file | ||
return run(c, archiveScanner) | ||
} | ||
|
||
return run(c, dockerScanner) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.