forked from koblas/s3-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_info.go
86 lines (73 loc) · 2.73 KB
/
cmd_info.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
package main
import (
"fmt"
"strings"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/aws"
"github.com/urfave/cli"
)
func GetInfo(config *Config, c *cli.Context) error {
args := c.Args()
svc := SessionNew(config)
// If we're not passed any args, we're going to do all S3 buckets
if len(args) == 0 {
return fmt.Errorf("Not enough parameters for command 'info'")
}
// Get the usage for the buckets
for _, arg := range args {
// Only do usage on S3 buckets
u, err := FileURINew(arg)
if err != nil || u.Scheme != "s3" {
continue
}
bsvc, err := SessionForBucket(svc, u.Bucket)
if err != nil {
return err
}
if u.Path == "" || u.Path == "/" {
bucket := aws.String(u.Bucket)
fmt.Printf("%s (bucket):\n", u.String())
if info, err := bsvc.GetBucketLocation(&s3.GetBucketLocationInput{ Bucket: bucket }); err == nil {
if info.LocationConstraint != nil {
fmt.Printf(" Location: %s\n", *info.LocationConstraint)
} else {
fmt.Printf(" Location: %s\n", "none")
}
}
if info, err := bsvc.GetBucketRequestPayment(&s3.GetBucketRequestPaymentInput{ Bucket: bucket }); err == nil {
if info.Payer != nil {
fmt.Printf(" Payer: %s\n", *info.Payer)
} else {
fmt.Printf(" Payer: %s\n", "none")
}
}
} else {
params := &s3.HeadObjectInput {
Bucket: aws.String(u.Bucket),
Key: u.Key(),
}
info, err := bsvc.HeadObject(params)
if err != nil {
fmt.Printf("Error fetching info for %s\n", u.String())
continue
}
fmt.Printf("%s (object):\n", u.String())
fmt.Printf(" File size: %d\n", *info.ContentLength)
fmt.Printf(" Last mod: %s\n", info.LastModified.Format(DATE_FMT))
fmt.Printf(" MIME type: %s\n", *info.ContentType)
fmt.Printf(" MD5 sum: %s\n", strings.Trim(*info.ETag, "\""))
if info.ServerSideEncryption != nil {
fmt.Printf(" SSE: %s\n", *info.ServerSideEncryption)
} else {
fmt.Printf(" SSE: %s\n", "none")
}
// fmt.Printf(" policy: %d\n", *info.ContentLength)
// fmt.Printf(" cors: %d\n", *info.ContentLength)
// fmt.Printf(" ACL: %d\n", *info.)
for k, v := range info.Metadata {
fmt.Printf(" x-az-meta-%s: %s\n", k, *v)
}
}
}
return nil
}