-
-
Notifications
You must be signed in to change notification settings - Fork 354
/
s3_access_point.go
77 lines (64 loc) · 2.12 KB
/
s3_access_point.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
package resources
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3control"
"github.com/gruntwork-io/cloud-nuke/config"
"github.com/gruntwork-io/cloud-nuke/logging"
"github.com/gruntwork-io/cloud-nuke/report"
"github.com/gruntwork-io/cloud-nuke/util"
"github.com/gruntwork-io/go-commons/errors"
)
func (ap *S3AccessPoint) getAll(c context.Context, configObj config.Config) ([]*string, error) {
accountID, ok := c.Value(util.AccountIdKey).(string)
if !ok {
logging.Errorf("unable to read the account-id from context")
return nil, errors.WithStackTrace(fmt.Errorf("unable to lookup the account id"))
}
// set the account id in object as this is mandatory to nuke an access point
ap.AccountID = aws.String(accountID)
var accessPoints []*string
err := ap.Client.ListAccessPointsPages(&s3control.ListAccessPointsInput{
AccountId: ap.AccountID,
}, func(lapo *s3control.ListAccessPointsOutput, lastPage bool) bool {
for _, accessPoint := range lapo.AccessPointList {
if configObj.S3AccessPoint.ShouldInclude(config.ResourceValue{
Name: accessPoint.Name,
}) {
accessPoints = append(accessPoints, accessPoint.Name)
}
}
return !lastPage
})
return accessPoints, errors.WithStackTrace(err)
}
func (ap *S3AccessPoint) nukeAll(identifiers []*string) error {
if len(identifiers) == 0 {
logging.Debugf("No Access point(s) to nuke in region %s", ap.Region)
return nil
}
logging.Debugf("Deleting all Access points in region %s", ap.Region)
var deleted []*string
for _, id := range identifiers {
_, err := ap.Client.DeleteAccessPoint(&s3control.DeleteAccessPointInput{
AccountId: ap.AccountID,
Name: id,
})
// Record status of this resource
e := report.Entry{
Identifier: aws.StringValue(id),
ResourceType: "S3 Access point",
Error: err,
}
report.Record(e)
if err != nil {
logging.Debugf("[Failed] %s", err)
} else {
deleted = append(deleted, id)
logging.Debugf("Deleted S3 access point: %s", aws.StringValue(id))
}
}
logging.Debugf("[OK] %d S3 Access point(s) deleted in %s", len(deleted), ap.Region)
return nil
}