Skip to content

Commit

Permalink
experimental flag (#272)
Browse files Browse the repository at this point in the history
Co-authored-by: filip <[email protected]>
  • Loading branch information
SuneethaSuresh and filip-debricked authored Nov 13, 2024
1 parent cd94137 commit a480c27
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
16 changes: 16 additions & 0 deletions internal/cmd/scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var versionHint bool
var sbom string
var sbomOutput string
var tagCommitAsRelease bool
var experimental bool

const (
BranchFlag = "branch"
Expand Down Expand Up @@ -66,6 +67,7 @@ const (
SBOMOutputFlag = "sbom-output"
TagCommitAsReleaseFlag = "tag-commit-as-release"
TagCommitAsReleaseEnv = "TAG_COMMIT_AS_RELEASE"
ExperimentalFlag = "experimental"
)

var scanCmdError error
Expand All @@ -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")
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions internal/scan/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type DebrickedOptions struct {
CallGraphGenerateTimeout int
MinFingerprintContentLength int
TagCommitAsRelease bool
Experimental bool
}

func NewDebrickedScanner(
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions internal/upload/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -59,6 +60,7 @@ func newUploadBatch(
versionHint: versionHint,
debrickedConfig: debrickedConfig,
tagCommitAsRelease: tagCommitAsRelease,
experimental: experimental,
}
}

Expand Down Expand Up @@ -187,6 +189,7 @@ func (uploadBatch *uploadBatch) initAnalysis() error {
DebrickedConfig: uploadBatch.debrickedConfig,
DebrickedIntegration: "cli",
TagCommitAsRelease: uploadBatch.tagCommitAsRelease,
Experimental: uploadBatch.experimental,
})

if err != nil {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions internal/upload/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions internal/upload/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type DebrickedOptions struct {
VersionHint bool
DebrickedConfig *DebrickedConfig
TagCommitAsRelease bool
Experimental bool
}

type IUploader interface {
Expand Down Expand Up @@ -47,6 +48,7 @@ func (uploader *Uploader) Upload(o IOptions) (*UploadResult, error) {
dOptions.VersionHint,
dOptions.DebrickedConfig,
dOptions.TagCommitAsRelease,
dOptions.Experimental,
)

err := batch.upload()
Expand Down

0 comments on commit a480c27

Please sign in to comment.