Skip to content

Commit a4de039

Browse files
Merge pull request #52 from snyk/fix(bundlestore)/use-local-target-for-code-upload
fix(bundlestore): use local target for code upload
2 parents 51ec409 + a775731 commit a4de039

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

internal/bundlestore/client.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/google/uuid"
1313
"github.com/rs/zerolog"
1414
codeclient "github.com/snyk/code-client-go"
15-
codeclientscan "github.com/snyk/code-client-go/scan"
1615

1716
listsources "github.com/snyk/cli-extension-os-flows/internal/files"
1817
)
@@ -205,17 +204,12 @@ func (c *HTTPClient) UploadSourceCode(ctx context.Context, sourceCodePath string
205204
numThreads := runtime.NumCPU()
206205
filesChan, err := listsources.ForPath(sourceCodePath, c.logger, numThreads)
207206
if err != nil {
208-
c.logger.Error().Err(err).Str("sourceCodePath", sourceCodePath).Msg("failed to list files in directory") //nolint:goconst // repeated sourceCodePath is fine
207+
c.logger.Error().Err(err).Str("sourceCodePath", sourceCodePath).Msg("failed to list files in directory")
209208
return "", fmt.Errorf("failed to list files in directory")
210209
}
211210

212-
target, err := codeclientscan.NewRepositoryTarget(sourceCodePath)
213-
if err != nil {
214-
c.logger.Error().Err(err).Str("sourceCodePath", sourceCodePath).Msg("failed to initialize target")
215-
return "", fmt.Errorf("failed to initialize target")
216-
}
217-
218211
requestID := uuid.New().String()
212+
target := LocalTarget{sourceCodePath}
219213
bundle, err := c.codeScanner.Upload(ctx, requestID, target, filesChan, make(map[string]bool))
220214
if err != nil {
221215
c.logger.Error().Err(err).Str("sourceCodePath", sourceCodePath).Msg("failed to upload source code")

internal/bundlestore/localtarget.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package bundlestore
2+
3+
// LocalTarget satisfies the scan.Target interface required for uploading source code.
4+
type LocalTarget struct {
5+
path string
6+
}
7+
8+
// GetPath returns the path of the LocalTarget.
9+
func (lt LocalTarget) GetPath() string {
10+
return lt.path
11+
}

0 commit comments

Comments
 (0)