From 04382037b9ecab2c70ae8b695b67e05d82af697c Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Wed, 22 Nov 2023 15:41:35 -0800 Subject: [PATCH] few misc things --- zipserver/copy_handler.go | 4 ++-- zipserver/mem_storage.go | 4 ++++ zipserver/s3_storage.go | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/zipserver/copy_handler.go b/zipserver/copy_handler.go index b6d69d6..c81955c 100644 --- a/zipserver/copy_handler.go +++ b/zipserver/copy_handler.go @@ -87,13 +87,13 @@ func copyHandler(w http.ResponseWriter, r *http.Request) error { storage, err := NewGcsStorage(config) if storage == nil { - log.Fatal("Failed to create storage: ", err) + log.Fatal("Failed to create source (GCS) storage: ", err) } targetStorage, err := NewS3Storage(config) if storage == nil { - log.Fatal("Failed to create storage: ", err) + log.Fatal("Failed to create target (S3) storage: ", err) } startTime := time.Now() diff --git a/zipserver/mem_storage.go b/zipserver/mem_storage.go index 671a933..f089e4a 100644 --- a/zipserver/mem_storage.go +++ b/zipserver/mem_storage.go @@ -1,5 +1,9 @@ package zipserver +// MemStorage implements Storage interface in memory, storing objects in a map. +// This is used for the serving of a zip file over http. Keep in mind extracted +// zips are stored forever, this should only be used for testing or one-off use + import ( "bytes" "context" diff --git a/zipserver/s3_storage.go b/zipserver/s3_storage.go index 86b15da..d3afb4f 100644 --- a/zipserver/s3_storage.go +++ b/zipserver/s3_storage.go @@ -102,3 +102,18 @@ func (c *S3Storage) HeadFile(ctx context.Context, bucket, key string) (url.Value return out, nil } + +func (c *S3Storage) DeleteFile(ctx context.Context, bucket, key string) error { + svc := s3.New(c.Session) + input := &s3.DeleteObjectInput{ + Bucket: aws.String(bucket), + Key: aws.String(key), + } + + _, err := svc.DeleteObjectWithContext(ctx, input) + if err != nil { + return err + } + + return nil +}