Skip to content

Commit 948ae54

Browse files
authored
chore: decouple cas-client file upload (#43)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 8d36766 commit 948ae54

File tree

11 files changed

+84
-27
lines changed

11 files changed

+84
-27
lines changed

app/cli/internal/action/artifact_upload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (a *ArtifactUpload) Run(filePath string) (*CASArtifact, error) {
6363
go renderOperationStatus(context.Background(), client.ProgressStatus, info.Size())
6464
defer close(client.ProgressStatus)
6565

66-
res, err := client.Upload(context.Background(), filePath)
66+
res, err := client.UploadFile(context.Background(), filePath)
6767
if err != nil {
6868
return nil, err
6969
}

internal/attestation/crafter/materials/artifact.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func NewArtifactCrafter(schema *schemaapi.CraftingSchema_Material, uploader casc
4343

4444
// Craft will calculate the digest of the artifact, simulate an upload and return the material definition
4545
func (i *ArtifactCrafter) Craft(ctx context.Context, artifactPath string) (*api.Attestation_Material, error) {
46-
result, err := i.uploader.Upload(ctx, artifactPath)
46+
result, err := i.uploader.UploadFile(ctx, artifactPath)
4747
if err != nil {
4848
i.logger.Debug().Err(err)
4949
return nil, err

internal/attestation/crafter/materials/artifact_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestNewArtifactCrafter(t *testing.T) {
6464
}
6565
}
6666

67-
func TestArtifacftCraft(t *testing.T) {
67+
func TestArtifactCraft(t *testing.T) {
6868
assert := assert.New(t)
6969
schema := &contractAPI.CraftingSchema_Material{
7070
Name: "test",
@@ -75,7 +75,7 @@ func TestArtifacftCraft(t *testing.T) {
7575

7676
// Mock uploader
7777
uploader := mUploader.NewUploader(t)
78-
uploader.On("Upload", context.TODO(), "file.txt").
78+
uploader.On("UploadFile", context.TODO(), "file.txt").
7979
Return(&casclient.UpDownStatus{
8080
Digest: "deadbeef",
8181
Filename: "file.txt",

internal/attestation/crafter/materials/cyclonedxjson.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (i *CyclonedxJSONCrafter) Craft(ctx context.Context, filePath string) (*api
6464
return nil, fmt.Errorf("invalid cyclonedx sbom file: %w", ErrInvalidMaterialType)
6565
}
6666

67-
result, err := i.uploader.Upload(ctx, filePath)
67+
result, err := i.uploader.UploadFile(ctx, filePath)
6868
if err != nil {
6969
i.logger.Debug().Err(err)
7070
return nil, err

internal/attestation/crafter/materials/cyclonedxjson_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestCyclonedxJSONCraft(t *testing.T) {
102102
// Mock uploader
103103
uploader := mUploader.NewUploader(t)
104104
if tc.wantErr == "" {
105-
uploader.On("Upload", context.TODO(), tc.filePath).
105+
uploader.On("UploadFile", context.TODO(), tc.filePath).
106106
Return(&casclient.UpDownStatus{
107107
Digest: "deadbeef",
108108
Filename: "sbom.cyclonedx.json",

internal/attestation/crafter/materials/spdxjson.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (i *SPDXJSONCrafter) Craft(ctx context.Context, filePath string) (*api.Atte
5959
return nil, fmt.Errorf("invalid spdx sbom file: %w", ErrInvalidMaterialType)
6060
}
6161

62-
result, err := i.uploader.Upload(ctx, filePath)
62+
result, err := i.uploader.UploadFile(ctx, filePath)
6363
if err != nil {
6464
i.logger.Debug().Err(err)
6565
return nil, err

internal/attestation/crafter/materials/spdxjson_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestSPDXJSONCraft(t *testing.T) {
102102
// Mock uploader
103103
uploader := mUploader.NewUploader(t)
104104
if tc.wantErr == "" {
105-
uploader.On("Upload", context.TODO(), tc.filePath).
105+
uploader.On("UploadFile", context.TODO(), tc.filePath).
106106
Return(&casclient.UpDownStatus{
107107
Digest: "deadbeef",
108108
Filename: "sbom.spdx.json",

internal/casclient/casclient.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
)
2525

2626
type UpDownStatus struct {
27-
Filepath, Filename, Digest string
28-
ProcessedBytes int64
27+
Filename, Digest string
28+
ProcessedBytes int64
2929
}
3030

3131
type ResourceInfo struct {
@@ -35,7 +35,8 @@ type ResourceInfo struct {
3535
}
3636

3737
type Uploader interface {
38-
Upload(ctx context.Context, filepath string) (*UpDownStatus, error)
38+
UploadFile(ctx context.Context, filepath string) (*UpDownStatus, error)
39+
Upload(ctx context.Context, r io.Reader, digest, fileName string) (*UpDownStatus, error)
3940
}
4041

4142
type Downloader interface {

internal/casclient/mocks/DownloaderUploader.go

Lines changed: 28 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/casclient/mocks/Uploader.go

Lines changed: 30 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)