-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (48 loc) · 1.22 KB
/
main.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
package main
import (
"os"
log "github.com/Sirupsen/logrus"
"github.com/sendwithus/cloudwatch-cleaner/change"
"github.com/sendwithus/cloudwatch-cleaner/config"
)
func main() {
client := change.New()
err := run(client)
if err != nil {
log.WithError(err).Error("Run returned:")
}
}
func run(client change.Client) error {
client.SetRegion("us-west-2")
regions, err := client.ListRegions()
if err != nil {
return err
}
for _, region := range regions {
client.SetRegion(region)
groups, _ := client.ListGroups()
for _, group := range groups {
for _, blockList := range config.BlockList {
if blockList == group {
log.Info("Group in blocklist, skipping.")
} else {
retention, err := client.GetRetentionPolicy(group)
if err != nil {
log.WithError(err).Error("GetRetentionPolicy returned:")
}
retentionDays, err := client.ConvertToInt64(os.Getenv("RETENTION_DAYS"))
if err != nil {
log.WithError(err).Error("ConvertToInt64 returned:")
}
if retention != retentionDays {
err := client.SetRetentionPolicy(retentionDays, group)
if err != nil {
log.WithError(err).Error("SetRetentionPolicy returned:")
}
}
}
}
}
}
return nil
}