Skip to content

Commit

Permalink
Upload object based on AWS_UPLOAD_TEST_FILES flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikkumar-mohite committed Aug 31, 2024
1 parent ab09272 commit 1038b48
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
12 changes: 10 additions & 2 deletions cmd/s3-cleanup/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ func setup() aws.S3Client {
config := aws.AWSConnection(getFromEnv("AWS_PROFILE"))
client := aws.S3Connection(config)
client.Bucket = getFromEnv("AWS_DELETE_S3_BUCKET")
_ = getFromEnv("AWS_REGION")
return client
}

func s3Cleanup() {
s3Client := setup()
func s3Upload(s3Client aws.S3Client) {
object1 := s3Client.UploadS3BucketObjects("test/files/file1.txt")
s3Client.UploadS3BucketObjects("test/files/file2.txt")
s3Client.UploadS3BucketObjects("test/files/file1.txt")
s3Client.UploadS3BucketObjects("test/files/file2.txt")
s3Client.DeleteS3BucketObjectVersion("file1.txt", object1)
}

func s3Cleanup() {
s3Client := setup()

if getFromEnv("AWS_UPLOAD_TEST_FILES") == "true" {
s3Upload(s3Client)
}

startTime := time.Now()

Expand Down
2 changes: 1 addition & 1 deletion cmd/s3-cleanup/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func getFromEnv(env string) string {
variable := os.Getenv(env)
if variable == "" {
log.Fatalf("Environment variable %s is not set", env)
log.Errorf("Environment variable %s is not set", env)
}
return variable
}
5 changes: 5 additions & 0 deletions pkg/aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func (c *S3Client) listObjectVersions(bucket *string) []S3BucketObject {
objects = append(objects, *object)
}

if len(objects) == 0 {
log.Infof("No objects found in bucket %s\n", *bucket)
return objects
}

return objects
}

Expand Down

0 comments on commit 1038b48

Please sign in to comment.