-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cli): project delete empty s3 buckets before deleting #714
fix(cli): project delete empty s3 buckets before deleting #714
Conversation
c8514cc
to
e0bcecb
Compare
e0bcecb
to
c221c19
Compare
@@ -52,3 +60,46 @@ func (s *Service) PutArtifact(bucket, fileName string, data io.Reader) (string, | |||
|
|||
return resp.Location, nil | |||
} | |||
|
|||
// EmptyBucket deletes all objects within the bucket. | |||
func (s *Service) EmptyBucket(bucket string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks tricky, thanks for tackling this.
Have you looked at using the BatchDelete of the s3Manager?
Here's a blog post on how it might help simplify things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried that method before. Ugh it is helpful when using non-versioning bucket. However, when it comes to "versioning bucket", things can be very complicated and "s3manager" they don't support versioning bucket very well, and BatchDelete
cannot delete all the other versioning for the objects nor the "delete marker" for that.
Had a discussion with Efe yesterday on those resolved comments above on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry then!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol no problem!
@iamhopaul123 this looks so much neater and also correct :P thanks for looking into it
c221c19
to
db50373
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀 with a question below and small nit
_, err = s.s3Svc.DeleteObjects(&s3.DeleteObjectsInput{ | ||
Bucket: aws.String(bucket), | ||
Delete: &s3.Delete{ | ||
Objects: objectsToDelete, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
listResp.DeleteMarkers
+ listResp.Versions
can not be more than 1000 objects right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but objectsToDelete
shall not exceed 1000 either, because the list
return values limit already includes both version
and delete marker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok perfect!
@@ -52,3 +60,46 @@ func (s *Service) PutArtifact(bucket, fileName string, data io.Reader) (string, | |||
|
|||
return resp.Location, nil | |||
} | |||
|
|||
// EmptyBucket deletes all objects within the bucket. | |||
func (s *Service) EmptyBucket(bucket string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol no problem!
@iamhopaul123 this looks so much neater and also correct :P thanks for looking into it
@@ -143,3 +143,7 @@ type wsProjectManager interface { | |||
type artifactPutter interface { | |||
PutArtifact(bucket, fileName string, data io.Reader) (string, error) | |||
} | |||
|
|||
type bucketEmptier interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💩
db50373
to
d2e595a
Compare
fix #700, with minor refactoring.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.