From 394a1be2b47128e56702978962f03d1f2ff0f5e6 Mon Sep 17 00:00:00 2001 From: filip Date: Mon, 11 Nov 2024 14:19:09 +0100 Subject: [PATCH] experimental flag --- internal/cmd/scan/scan.go | 16 ++++++++++++++++ internal/scan/scanner.go | 2 ++ internal/upload/batch.go | 8 ++++++-- internal/upload/batch_test.go | 12 ++++++------ internal/upload/uploader.go | 2 ++ 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/internal/cmd/scan/scan.go b/internal/cmd/scan/scan.go index ed5777c5..6127c1ac 100644 --- a/internal/cmd/scan/scan.go +++ b/internal/cmd/scan/scan.go @@ -39,6 +39,7 @@ var versionHint bool var sbom string var sbomOutput string var tagCommitAsRelease bool +var experimental bool const ( BranchFlag = "branch" @@ -66,6 +67,7 @@ const ( SBOMOutputFlag = "sbom-output" TagCommitAsReleaseFlag = "tag-commit-as-release" TagCommitAsReleaseEnv = "TAG_COMMIT_AS_RELEASE" + ExperimentalFlag = "experimental" ) var scanCmdError error @@ -83,6 +85,7 @@ If the given path contains a git repository all flags but "integration" will be return RunE(&scanner)(cmd, args) }, } + cmd.Flags().StringVarP(&repositoryName, RepositoryFlag, "r", "", "repository name") cmd.Flags().StringVarP(&commitName, CommitFlag, "c", "", "commit hash") cmd.Flags().StringVarP(&branchName, BranchFlag, "b", "", "branch name") @@ -141,6 +144,12 @@ $ debricked scan . --include '**/node_modules/**'`) "\nExample:\n$ debricked scan . --version-hint=false", }, "\n") cmd.Flags().BoolVar(&versionHint, VersionHintFlag, true, versionHintDoc) + experimentalFlagDoc := strings.Join( + []string{ + "This flag allows inclusion of repository matches", + "\nExample:\n$ debricked scan . --experimental=false", + }, "\n") + cmd.Flags().BoolVar(&experimental, ExperimentalFlag, false, experimentalFlagDoc) verboseDoc := strings.Join( []string{ "This flag allows you to reduce error output for resolution.", @@ -186,6 +195,12 @@ Leaving the field empty results in no SBOM generation.`, viper.MustBindEnv(SBOMOutputFlag) viper.MustBindEnv(TagCommitAsReleaseFlag) + // Hide experimental flag + err := cmd.Flags().MarkHidden(ExperimentalFlag) + if err != nil { // This should not be reachable + fmt.Println("Trying to hide non-existing flag") + } + return cmd } @@ -236,6 +251,7 @@ func RunE(s *scan.IScanner) func(_ *cobra.Command, args []string) error { CallGraphGenerateTimeout: viper.GetInt(CallGraphGenerateTimeoutFlag), MinFingerprintContentLength: viper.GetInt(MinFingerprintContentLengthFlag), TagCommitAsRelease: tagCommitAsRelease, + Experimental: viper.GetBool(ExperimentalFlag), } if s != nil { scanCmdError = (*s).Scan(options) diff --git a/internal/scan/scanner.go b/internal/scan/scanner.go index 2afc19f4..5567ac19 100644 --- a/internal/scan/scanner.go +++ b/internal/scan/scanner.go @@ -71,6 +71,7 @@ type DebrickedOptions struct { CallGraphGenerateTimeout int MinFingerprintContentLength int TagCommitAsRelease bool + Experimental bool } func NewDebrickedScanner( @@ -282,6 +283,7 @@ func (dScanner *DebrickedScanner) scan(options DebrickedOptions, gitMetaObject g VersionHint: options.VersionHint, DebrickedConfig: dScanner.getDebrickedConfig(options.Path, options.Exclusions, options.Inclusions), TagCommitAsRelease: options.TagCommitAsRelease, + Experimental: options.Experimental, } result, err := (*dScanner.uploader).Upload(uploaderOptions) if err != nil { diff --git a/internal/upload/batch.go b/internal/upload/batch.go index 5cb5fc1b..c95a8bd9 100644 --- a/internal/upload/batch.go +++ b/internal/upload/batch.go @@ -42,12 +42,13 @@ type uploadBatch struct { versionHint bool debrickedConfig *DebrickedConfig // JSON Config tagCommitAsRelease bool + experimental bool } func newUploadBatch( client *client.IDebClient, fileGroups file.Groups, gitMetaObject *git.MetaObject, - integrationName string, callGraphTimeout int, versionHint bool, debrickedConfig *DebrickedConfig, - tagCommitAsRelease bool, + integrationName string, callGraphTimeout int, versionHint bool, + debrickedConfig *DebrickedConfig, tagCommitAsRelease bool, experimental bool, ) *uploadBatch { return &uploadBatch{ client: client, @@ -59,6 +60,7 @@ func newUploadBatch( versionHint: versionHint, debrickedConfig: debrickedConfig, tagCommitAsRelease: tagCommitAsRelease, + experimental: experimental, } } @@ -187,6 +189,7 @@ func (uploadBatch *uploadBatch) initAnalysis() error { DebrickedConfig: uploadBatch.debrickedConfig, DebrickedIntegration: "cli", TagCommitAsRelease: uploadBatch.tagCommitAsRelease, + Experimental: uploadBatch.experimental, }) if err != nil { @@ -332,6 +335,7 @@ type uploadFinish struct { VersionHint bool `json:"versionHint"` DebrickedConfig *DebrickedConfig `json:"debrickedConfig"` TagCommitAsRelease bool `json:"isRelease"` + Experimental bool `json:"experimental"` } func getRelativeFilePath(filePath string) string { diff --git a/internal/upload/batch_test.go b/internal/upload/batch_test.go index a9b60c30..73fafe47 100644 --- a/internal/upload/batch_test.go +++ b/internal/upload/batch_test.go @@ -38,7 +38,7 @@ func TestUploadWithBadFiles(t *testing.T) { clientMock.AddMockResponse(mockRes) clientMock.AddMockResponse(mockRes) c = clientMock - batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, false) + batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false) var buf bytes.Buffer log.SetOutput(&buf) err = batch.upload() @@ -50,7 +50,7 @@ func TestUploadWithBadFiles(t *testing.T) { } func TestInitAnalysisWithoutAnyFiles(t *testing.T) { - batch := newUploadBatch(nil, file.Groups{}, nil, "CLI", 10*60, true, &DebrickedConfig{}, false) + batch := newUploadBatch(nil, file.Groups{}, nil, "CLI", 10*60, true, &DebrickedConfig{}, true, false) err := batch.initAnalysis() assert.ErrorContains(t, err, "failed to find dependency files") @@ -73,7 +73,7 @@ func TestWaitWithPollingTerminatedError(t *testing.T) { } clientMock.AddMockResponse(mockRes) c = clientMock - batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, false) + batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false) uploadResult, err := batch.wait() @@ -98,7 +98,7 @@ func TestInitUploadBadFile(t *testing.T) { clientMock.AddMockResponse(mockRes) var c client.IDebClient = clientMock - batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, false) + batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false) files, err := batch.initUpload() @@ -120,7 +120,7 @@ func TestInitUploadFingerprintsFree(t *testing.T) { clientMock := testdata.NewDebClientMock() clientMock.SetEnterpriseCustomer(false) var c client.IDebClient = clientMock - batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, false) + batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false) files, err := batch.initUpload() @@ -145,7 +145,7 @@ func TestInitUpload(t *testing.T) { clientMock.AddMockResponse(mockRes) var c client.IDebClient = clientMock - batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true) + batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false) files, err := batch.initUpload() diff --git a/internal/upload/uploader.go b/internal/upload/uploader.go index b1ce696f..a8dfb4f4 100644 --- a/internal/upload/uploader.go +++ b/internal/upload/uploader.go @@ -18,6 +18,7 @@ type DebrickedOptions struct { VersionHint bool DebrickedConfig *DebrickedConfig TagCommitAsRelease bool + Experimental bool } type IUploader interface { @@ -47,6 +48,7 @@ func (uploader *Uploader) Upload(o IOptions) (*UploadResult, error) { dOptions.VersionHint, dOptions.DebrickedConfig, dOptions.TagCommitAsRelease, + dOptions.Experimental, ) err := batch.upload()