Skip to content

Commit 46b31cf

Browse files
authored
Creates Delete Blob Interface (#69)
1 parent 0d650b7 commit 46b31cf

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

azure/azblob/azblob.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ func (c *Client) ReadBlob(ctx context.Context, uri string) (io.ReadCloser, error
8787
return resp.Body, nil
8888
}
8989

90+
func (c *Client) DeleteBlob(ctx context.Context, uri string) error {
91+
ctr, blb, ok := blob.SplitURI(Scheme, uri)
92+
if !ok {
93+
return fmt.Errorf("malformed URI %q is not for Azure", uri)
94+
}
95+
96+
_, err := c.client.DeleteBlob(ctx, ctr, blb, nil)
97+
if err != nil {
98+
return fmt.Errorf("failed to delete blob: %w", err)
99+
}
100+
101+
return nil
102+
}
103+
90104
// SignedUploadURL returns a URL that is allowed to upload to the given URI.
91105
// See https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0/sas#example-package-UserDelegationSAS
92106
func (c *Client) SignedUploadURL(ctx context.Context, uri string) (string, error) {

cmd/server/pactasrv/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ go_library(
88
"initiative_user_relationship.go",
99
"pacta_version.go",
1010
"pactasrv.go",
11+
"parallel.go",
1112
"portfolio.go",
1213
"upload.go",
1314
"user.go",

cmd/server/pactasrv/pactasrv.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type Blob interface {
8787
SignedUploadURL(ctx context.Context, uri string) (string, error)
8888
// For downloading reports
8989
SignedDownloadURL(ctx context.Context, uri string) (string, error)
90+
DeleteBlob(ctx context.Context, uri string) error
9091
}
9192

9293
type Server struct {

cmd/server/pactasrv/parallel.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package pactasrv
2+
3+
import (
4+
"context"
5+
"fmt"
6+
)
7+
8+
type blobDeleter interface {
9+
DeleteBlob(ctx context.Context, uri string) error
10+
}
11+
12+
func deleteBlobs(ctx context.Context, bd blobDeleter, uris []string) error {
13+
// Implement parallel delete if slow - not prematurely optimizing.
14+
for i, uri := range uris {
15+
if err := bd.DeleteBlob(ctx, uri); err != nil {
16+
return fmt.Errorf("deleting blob %d/%d: %w", i, len(uris), err)
17+
}
18+
}
19+
return nil
20+
}
21+
22+
func (s *Server) deleteBlobs(ctx context.Context, uris []string) error {
23+
return deleteBlobs(ctx, s.Blob, uris)
24+
}

0 commit comments

Comments
 (0)