From ba30a5e433c11f33ff026790e5358bc667fe8346 Mon Sep 17 00:00:00 2001 From: Alex Collins Date: Fri, 22 Apr 2022 08:45:01 -0700 Subject: [PATCH] feat: Add S3 `Delete` func (#71) Signed-off-by: Alex Collins --- s3/s3.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/s3/s3.go b/s3/s3.go index 6b606077..c5ad59ba 100644 --- a/s3/s3.go +++ b/s3/s3.go @@ -37,6 +37,8 @@ type S3Client interface { // OpenFile opens a file for much lower disk and memory usage that GetFile OpenFile(bucket, key string) (io.ReadCloser, error) + Delete(bucket, key string) error + // GetDirectory downloads a directory to a local file path GetDirectory(bucket, key, path string) error @@ -272,6 +274,11 @@ func (s *s3client) OpenFile(bucket, key string) (io.ReadCloser, error) { return f, nil } +func (s *s3client) Delete(bucket, key string) error { + log.WithFields(log.Fields{"endpoint": s.Endpoint, "bucket": bucket, "key": key}).Info("Deleting object from s3") + return s.minioClient.RemoveObject(s.ctx, bucket, key, minio.RemoveObjectOptions{}) +} + // GetDirectory downloads a s3 directory to a local path func (s *s3client) GetDirectory(bucket, keyPrefix, path string) error { log.WithFields(log.Fields{"endpoint": s.Endpoint, "bucket": bucket, "key": keyPrefix, "path": path}).Info("Getting directory from s3")