-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
s3_types.go
87 lines (71 loc) · 2.35 KB
/
s3_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package resources
import (
"context"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3iface"
"github.com/gruntwork-io/cloud-nuke/config"
"github.com/gruntwork-io/cloud-nuke/logging"
"github.com/gruntwork-io/go-commons/errors"
)
// S3Buckets - represents all S3 Buckets
type S3Buckets struct {
BaseAwsResource
Client s3iface.S3API
Region string
Names []string
}
func (bucket *S3Buckets) Init(session *session.Session) {
bucket.Client = s3.New(session)
}
// ResourceName - the simple name of the aws resource
func (bucket *S3Buckets) ResourceName() string {
return "s3"
}
// MaxBatchSize decides how many S3 buckets to delete in one call.
func (bucket *S3Buckets) MaxBatchSize() int {
// Tentative batch size to ensure AWS doesn't throttle
return 500
}
// MaxConcurrentGetSize decides how many S3 buckets to fetch in one call.
func (bucket *S3Buckets) MaxConcurrentGetSize() int {
// To speed up bucket fetch part.
return 100
}
// ObjectMaxBatchSize decides how many unique objects of an S3 bucket (object + version = unique object) to delete in one call.
func (bucket *S3Buckets) ObjectMaxBatchSize() int {
// Tentative batch size to ensure AWS doesn't throttle
return 1000
}
// ResourceIdentifiers - The names of the S3 buckets
func (bucket *S3Buckets) ResourceIdentifiers() []string {
return bucket.Names
}
// To get the resource configuration
func (bucket *S3Buckets) GetAndSetResourceConfig(configObj config.Config) config.ResourceType {
return configObj.S3
}
func (bucket *S3Buckets) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) {
identifiers, err := bucket.getAll(c, configObj)
if err != nil {
return nil, err
}
bucket.Names = aws.StringValueSlice(identifiers)
return bucket.Names, nil
}
// Nuke - nuke 'em all!!!
func (bucket *S3Buckets) Nuke(identifiers []string) error {
delCount, err := bucket.nukeAll(aws.StringSlice(identifiers))
totalCount := len(identifiers)
if delCount > 0 {
logging.Debugf("[OK] - %d/%d - S3 bucket(s) deleted in %s", delCount, totalCount, bucket.Region)
}
if delCount != totalCount {
logging.Debugf("[Failed] - %d/%d - S3 bucket(s) failed deletion in %s", totalCount-delCount, totalCount, bucket.Region)
}
if err != nil {
return errors.WithStackTrace(err)
}
return nil
}