-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathproxy.go
47 lines (38 loc) · 1.02 KB
/
proxy.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
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
type S3Proxy interface {
Get(key string) (*s3.GetObjectOutput, error)
GetWebsiteConfig() (*s3.GetBucketWebsiteOutput, error)
}
type RealS3Proxy struct {
bucket string
s3 *s3.S3
}
func NewS3Proxy(key, secret, region, bucket string) S3Proxy {
sess := session.Must(session.NewSession(&aws.Config{
Region: aws.String(region),
Credentials: credentials.NewStaticCredentials(key, secret, ""),
}))
return &RealS3Proxy{
bucket: bucket,
s3: s3.New(sess),
}
}
func (p *RealS3Proxy) Get(key string) (*s3.GetObjectOutput, error) {
req := &s3.GetObjectInput{
Bucket: aws.String(p.bucket),
Key: aws.String(key),
}
return p.s3.GetObject(req)
}
func (p *RealS3Proxy) GetWebsiteConfig() (*s3.GetBucketWebsiteOutput, error) {
req := &s3.GetBucketWebsiteInput{
Bucket: aws.String(p.bucket),
}
return p.s3.GetBucketWebsite(req)
}