func (c *cfS3BucketCleanup) removeUnusedCFBuckets() []*s3.Error { var ( errors = []*s3.Error{} objects []*s3.Object ) resp, err := c.s3SVC.ListBuckets(&s3.ListBucketsInput{}) easylogger.LogFatal(err) for _, bucket := range resp.Buckets { if isCloudformationBucket(*bucket.Name, c.bucketFilter) && c.isBucketDeletable(bucket) { easylogger.Log("This bucket is to be deleted: ", *bucket.Name) objects = c.getBucketContents(bucket) if !isBucketEmpty(objects) { errs := c.emptyBucket(bucket, objects) if len(errs) > 0 { errors = append(errors, errs...) continue } } _, err := c.s3SVC.DeleteBucket( &s3.DeleteBucketInput{ Bucket: bucket.Name, }, ) easylogger.LogFatal(err) } } return errors }
func (c *cfS3BucketCleanup) getBucketContents(bucket *s3.Bucket) []*s3.Object { resp, err := c.s3SVC.ListObjects( &s3.ListObjectsInput{ Bucket: bucket.Name, }, ) easylogger.LogFatal(err) return resp.Contents }
func (c *cfS3BucketCleanup) getAllCfStackNames() { params := &cloudformation.ListStacksInput{ StackStatusFilter: []*string{ aws.String(cloudformation.StackStatusCreateComplete), }, } resp, err := c.cfSVC.ListStacks(params) easylogger.LogFatal(err) c.stacks = resp.StackSummaries }
func (c *cfS3BucketCleanup) emptyBucket( bucket *s3.Bucket, objects []*s3.Object, ) []*s3.Error { resp, err := c.s3SVC.DeleteObjects( &s3.DeleteObjectsInput{ Bucket: bucket.Name, Delete: &s3.Delete{ Objects: getObjectIDStruct(objects), }, }, ) easylogger.LogFatal(err) if resp.Errors == nil { return []*s3.Error{} } return resp.Errors }