Skip to content

Commit 0e87c7e

Browse files
committed
Creates Delete Blob Interface
1 parent 1672438 commit 0e87c7e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

azure/azblob/azblob.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,30 @@ 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+
104+
func (c *Client) DeleteBlobs(ctx context.Context, uris []string) error {
105+
// Implement parallel delete if slow - not prematurely optimizing.
106+
for i, uri := range uris {
107+
if err := c.DeleteBlob(ctx, uri); err != nil {
108+
return fmt.Errorf("deleting blob %d/%d: %w", i, len(uris), err)
109+
}
110+
}
111+
return nil
112+
}
113+
90114
// SignedUploadURL returns a URL that is allowed to upload to the given URI.
91115
// See https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0/sas#example-package-UserDelegationSAS
92116
func (c *Client) SignedUploadURL(ctx context.Context, uri string) (string, error) {

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+
DeleteBlobs(ctx context.Context, uris []string) error
9091
}
9192

9293
type Server struct {

0 commit comments

Comments
 (0)