Skip to content

Commit

Permalink
implement remove
Browse files Browse the repository at this point in the history
  • Loading branch information
jpicht committed Mar 14, 2022
1 parent 9b5e98d commit ea726af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
21 changes: 21 additions & 0 deletions pkg/azcat/remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package azcat

import (
"context"

"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/sirupsen/logrus"
)

func Remove(containerName, blobName string, client *azblob.ServiceClient) {
log.WithFields(logrus.Fields{
"container": containerName,
"blob": blobName,
}).Debug("remove")
containerClient := client.NewContainerClient(containerName)
blobClient := containerClient.NewBlobClient(blobName)
_, err := blobClient.Delete(context.TODO(), nil)
if err != nil {
log.WithError(err).Fatal("Delete failed")
}
}
2 changes: 2 additions & 0 deletions pkg/azcat/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ func Run(mode Mode, bloburl azblob.BlobURLParts, client *azblob.ServiceClient) {
Read(bloburl.ContainerName, bloburl.BlobName, client)
case EMode.Write():
Write(bloburl.ContainerName, bloburl.BlobName, client)
case EMode.Remove():
Remove(bloburl.ContainerName, bloburl.BlobName, client)
default:
log.WithField("mode", mode.String()).Fatal("Not implemented")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/azcat/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func Write(containerName, blobName string, client *azblob.ServiceClient) {
}).Debug("write")
containerClient := client.NewContainerClient(containerName)
blobClient := containerClient.NewBlockBlobClient(blobName)
_, err := blobClient.UploadStreamToBlockBlob(context.TODO(), os.Stdin, azblob.UploadStreamToBlockBlobOptions{})

_, err := blobClient.UploadStreamToBlockBlob(context.TODO(), os.Stdin, azblob.UploadStreamToBlockBlobOptions{})
if err != nil {
log.WithError(err).Fatal("Download failed")
log.WithError(err).Fatal("Write failed")
}
}

0 comments on commit ea726af

Please sign in to comment.