Skip to content

Commit

Permalink
Creates Delete Blob Interface (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbdubs authored Dec 6, 2023
1 parent 0d650b7 commit 46b31cf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions azure/azblob/azblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ func (c *Client) ReadBlob(ctx context.Context, uri string) (io.ReadCloser, error
return resp.Body, nil
}

func (c *Client) DeleteBlob(ctx context.Context, uri string) error {
ctr, blb, ok := blob.SplitURI(Scheme, uri)
if !ok {
return fmt.Errorf("malformed URI %q is not for Azure", uri)
}

_, err := c.client.DeleteBlob(ctx, ctr, blb, nil)
if err != nil {
return fmt.Errorf("failed to delete blob: %w", err)
}

return nil
}

// SignedUploadURL returns a URL that is allowed to upload to the given URI.
// See https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/[email protected]/sas#example-package-UserDelegationSAS
func (c *Client) SignedUploadURL(ctx context.Context, uri string) (string, error) {
Expand Down
1 change: 1 addition & 0 deletions cmd/server/pactasrv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
"initiative_user_relationship.go",
"pacta_version.go",
"pactasrv.go",
"parallel.go",
"portfolio.go",
"upload.go",
"user.go",
Expand Down
1 change: 1 addition & 0 deletions cmd/server/pactasrv/pactasrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Blob interface {
SignedUploadURL(ctx context.Context, uri string) (string, error)
// For downloading reports
SignedDownloadURL(ctx context.Context, uri string) (string, error)
DeleteBlob(ctx context.Context, uri string) error
}

type Server struct {
Expand Down
24 changes: 24 additions & 0 deletions cmd/server/pactasrv/parallel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package pactasrv

import (
"context"
"fmt"
)

type blobDeleter interface {
DeleteBlob(ctx context.Context, uri string) error
}

func deleteBlobs(ctx context.Context, bd blobDeleter, uris []string) error {
// Implement parallel delete if slow - not prematurely optimizing.
for i, uri := range uris {
if err := bd.DeleteBlob(ctx, uri); err != nil {
return fmt.Errorf("deleting blob %d/%d: %w", i, len(uris), err)
}
}
return nil
}

func (s *Server) deleteBlobs(ctx context.Context, uris []string) error {
return deleteBlobs(ctx, s.Blob, uris)
}

0 comments on commit 46b31cf

Please sign in to comment.