This repository has been archived by the owner on May 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
s3.go
58 lines (45 loc) · 1.43 KB
/
s3.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
/******************************************************************************
Cloud Resource Counter
File: s3.go
Summary: Provides a count of all S3 buckets.
******************************************************************************/
package main
import (
"github.com/aws/aws-sdk-go/service/s3"
color "github.com/logrusorgru/aurora"
)
// S3Buckets retrieves the count of all S3 buckets in ALL REGIONS.
// This behavior is unlike other AWS Services (e.g., EC2, Spot, RDS,
// etc).
//
// AS SUCH, THIS COUNT WILL BE INCORRECT WHEN A SINGLE REGION IS SPECIFIED.
//
// It is unclear if displaying counts of distinct regions will be part
// of the final CLI.
//
// This method gives status back to the user via the supplied
// ActivityMonitor instance.
func S3Buckets(sf ServiceFactory, am ActivityMonitor, allRegions bool) int {
// Create a new instance of the S3 (abstract) service
svc := sf.GetS3Service()
// Construct our input to find all S3 buckets
input := &s3.ListBucketsInput{}
// Indicate activity
am.StartAction("Retrieving S3 bucket counts")
// Invoke our service
result, err := svc.ListBuckets(input)
// Check for error
if am.CheckError(err) {
return 0
}
// Get our count of buckets
count := len(result.Buckets)
// Should we "qualify" our count?
var qualify string
if !allRegions && count > 0 {
qualify = "*"
}
// Indicate end of activity
am.EndAction("OK (%d%s)", color.Bold(count), qualify)
return count
}