forked from jhunt/go-s3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (55 loc) · 1.12 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
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"os"
"github.com/jhunt/go-s3"
)
func main() {
aki := os.Getenv("S3_AKI")
if aki == "" {
fmt.Fprintf(os.Stderr, "!!! no S3_AKI env var set...\n")
os.Exit(1)
}
key := os.Getenv("S3_KEY")
if key == "" {
fmt.Fprintf(os.Stderr, "!!! no S3_KEY env var set...\n")
os.Exit(1)
}
bkt := os.Getenv("S3_BUCKET")
if bkt == "" {
fmt.Fprintf(os.Stderr, "!!! no S3_BUCKET env var set...\n")
os.Exit(1)
}
reg := os.Getenv("S3_REGION")
if reg == "" {
reg = "us-east-1"
}
sigv := 4
if os.Getenv("S3_SIGV2") != "" {
sigv = 2
}
if len(os.Args) != 1 {
fmt.Fprintf(os.Stderr, "USAGE: list\n")
os.Exit(1)
}
c, err := s3.NewClient(&s3.Client{
AccessKeyID: aki,
SecretAccessKey: key,
Bucket: bkt,
Region: reg,
SignatureVersion: sigv,
})
if err != nil {
fmt.Fprintf(os.Stderr, "!!! unable to configure s3 client: %s\n", err)
os.Exit(1)
}
files, err := c.List()
if err != nil {
fmt.Fprintf(os.Stderr, "!!! unable to list files in bucket '%s': %s\n", bkt, err)
os.Exit(1)
}
for _, f := range files {
fmt.Printf("- %s\n", f.Key)
}
os.Exit(0)
}