diff --git a/internal/cmd/scan/scan.go b/internal/cmd/scan/scan.go index 736fd846..722e9c2f 100644 --- a/internal/cmd/scan/scan.go +++ b/internal/cmd/scan/scan.go @@ -23,6 +23,7 @@ var jsonFilePath string var exclusions = file.Exclusions() var verbose bool var regenerate int +var versionHint bool var noResolve bool var noFingerprint bool var passOnDowntime bool @@ -40,6 +41,7 @@ const ( IntegrationFlag = "integration" ExclusionFlag = "exclusion" VerboseFlag = "verbose" + VersionHintFlag = "version-hint" RegenerateFlag = "regenerate" NoResolveFlag = "no-resolve" FingerprintFlag = "fingerprint" @@ -110,6 +112,12 @@ $ debricked scan . `+exampleFlags) "\nExample:\n$ debricked resolve . --regenerate=1", }, "\n") cmd.Flags().IntVar(®enerate, RegenerateFlag, 0, regenerateDoc) + versionHintDoc := strings.Join( + []string{ + "Toggles version hinting, i.e using manifest versions to help manifestless resolution.\n", + "\nExample:\n$ debricked scan . --version-hint=false", + }, "\n") + cmd.Flags().BoolVar(&versionHint, VersionHintFlag, true, versionHintDoc) verboseDoc := strings.Join( []string{ "This flag allows you to reduce error output for resolution.", @@ -156,6 +164,7 @@ func RunE(s *scan.IScanner) func(_ *cobra.Command, args []string) error { Exclusions: viper.GetStringSlice(ExclusionFlag), Verbose: viper.GetBool(VerboseFlag), Regenerate: viper.GetInt(RegenerateFlag), + VersionHint: viper.GetBool(VersionHintFlag), RepositoryName: viper.GetString(RepositoryFlag), CommitName: viper.GetString(CommitFlag), BranchName: viper.GetString(BranchFlag), diff --git a/internal/scan/scanner.go b/internal/scan/scanner.go index e6555dba..c649a002 100644 --- a/internal/scan/scanner.go +++ b/internal/scan/scanner.go @@ -50,6 +50,7 @@ type DebrickedOptions struct { Exclusions []string Verbose bool Regenerate int + VersionHint bool RepositoryName string CommitName string BranchName string @@ -206,6 +207,7 @@ func (dScanner *DebrickedScanner) scan(options DebrickedOptions, gitMetaObject g GitMetaObject: gitMetaObject, IntegrationsName: options.IntegrationName, CallGraphUploadTimeout: options.CallGraphUploadTimeout, + VersionHint: options.VersionHint, } result, err := (*dScanner.uploader).Upload(uploaderOptions) if err != nil { diff --git a/internal/upload/batch.go b/internal/upload/batch.go index 2663e47b..ca17b7e2 100644 --- a/internal/upload/batch.go +++ b/internal/upload/batch.go @@ -38,10 +38,11 @@ type uploadBatch struct { integrationName string ciUploadId int callGraphTimeout int + versionHint bool } -func newUploadBatch(client *client.IDebClient, fileGroups file.Groups, gitMetaObject *git.MetaObject, integrationName string, callGraphTimeout int) *uploadBatch { - return &uploadBatch{client: client, fileGroups: fileGroups, gitMetaObject: gitMetaObject, integrationName: integrationName, ciUploadId: 0, callGraphTimeout: callGraphTimeout} +func newUploadBatch(client *client.IDebClient, fileGroups file.Groups, gitMetaObject *git.MetaObject, integrationName string, callGraphTimeout int, versionHint bool) *uploadBatch { + return &uploadBatch{client: client, fileGroups: fileGroups, gitMetaObject: gitMetaObject, integrationName: integrationName, ciUploadId: 0, callGraphTimeout: callGraphTimeout, versionHint: versionHint} } // upload concurrently posts all file groups to Debricked @@ -126,7 +127,6 @@ func (uploadBatch *uploadBatch) uploadFile(filePath string, timeout int) error { if uploadBatch.initialized() { _ = writer.WriteField("ciUploadId", strconv.Itoa(uploadBatch.ciUploadId)) } - response, err := (*uploadBatch.client).Post( "/api/1.0/open/uploads/dependencies/files", writer.FormDataContentType(), @@ -136,11 +136,9 @@ func (uploadBatch *uploadBatch) uploadFile(filePath string, timeout int) error { if err != nil { return err } - if !uploadBatch.initialized() { data, _ := io.ReadAll(response.Body) defer response.Body.Close() - uFile := uploadedFile{} _ = json.Unmarshal(data, &uFile) if uFile.CiUploadId == 0 { @@ -163,6 +161,7 @@ func (uploadBatch *uploadBatch) initAnalysis() error { IntegrationName: uploadBatch.integrationName, CommitName: uploadBatch.gitMetaObject.CommitName, Author: uploadBatch.gitMetaObject.Author, + VersionHint: uploadBatch.versionHint, DebrickedIntegration: "cli", }) @@ -277,6 +276,7 @@ type uploadFinish struct { CommitName string `json:"commitName"` Author string `json:"author"` DebrickedIntegration string `json:"debrickedIntegration"` + VersionHint bool `json:"versionHint"` } func getRelativeFilePath(filePath string) string { diff --git a/internal/upload/batch_test.go b/internal/upload/batch_test.go index 62af0fc8..3d8f1174 100644 --- a/internal/upload/batch_test.go +++ b/internal/upload/batch_test.go @@ -36,7 +36,7 @@ func TestUploadWithBadFiles(t *testing.T) { clientMock.AddMockResponse(mockRes) clientMock.AddMockResponse(mockRes) c = clientMock - batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60) + batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true) var buf bytes.Buffer log.SetOutput(&buf) err = batch.upload() @@ -48,7 +48,7 @@ func TestUploadWithBadFiles(t *testing.T) { } func TestInitAnalysisWithoutAnyFiles(t *testing.T) { - batch := newUploadBatch(nil, file.Groups{}, nil, "CLI", 10*60) + batch := newUploadBatch(nil, file.Groups{}, nil, "CLI", 10*60, true) err := batch.initAnalysis() assert.ErrorContains(t, err, "failed to find dependency files") @@ -71,7 +71,7 @@ func TestWaitWithPollingTerminatedError(t *testing.T) { } clientMock.AddMockResponse(mockRes) c = clientMock - batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60) + batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true) uploadResult, err := batch.wait() @@ -96,7 +96,7 @@ func TestInitUploadBadFile(t *testing.T) { clientMock.AddMockResponse(mockRes) var c client.IDebClient = clientMock - batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60) + batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true) files, err := batch.initUpload() @@ -123,7 +123,7 @@ func TestInitUpload(t *testing.T) { clientMock.AddMockResponse(mockRes) var c client.IDebClient = clientMock - batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60) + batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true) files, err := batch.initUpload() diff --git a/internal/upload/uploader.go b/internal/upload/uploader.go index 90203944..60745f88 100644 --- a/internal/upload/uploader.go +++ b/internal/upload/uploader.go @@ -15,6 +15,7 @@ type DebrickedOptions struct { GitMetaObject git.MetaObject IntegrationsName string CallGraphUploadTimeout int + VersionHint bool } type IUploader interface { @@ -35,7 +36,7 @@ func NewUploader(c client.IDebClient) (*Uploader, error) { func (uploader *Uploader) Upload(o IOptions) (*UploadResult, error) { dOptions := o.(DebrickedOptions) - batch := newUploadBatch(uploader.client, dOptions.FileGroups, &dOptions.GitMetaObject, dOptions.IntegrationsName, dOptions.CallGraphUploadTimeout) + batch := newUploadBatch(uploader.client, dOptions.FileGroups, &dOptions.GitMetaObject, dOptions.IntegrationsName, dOptions.CallGraphUploadTimeout, dOptions.VersionHint) err := batch.upload() if err != nil {