forked from jetstack/tarmak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3.go
46 lines (38 loc) · 938 Bytes
/
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
// Copyright Jetstack Ltd. See LICENSE for details.
package s3
import (
"fmt"
"io"
"net/url"
"github.com/Sirupsen/logrus"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
type S3 struct {
log *logrus.Entry
}
func New(log *logrus.Entry) *S3 {
return &S3{
log: log.WithField("provider", "s3"),
}
}
func (s *S3) GetManifest(manifestString string) (io.ReadCloser, error) {
manifestURL, err := url.Parse(manifestString)
if err != nil {
return nil, err
}
bucket := manifestURL.Host
key := manifestURL.Path
cfg := aws.NewConfig()
awsSession := session.New(cfg)
s3Service := s3.New(awsSession)
result, err := s3Service.GetObject(&s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
})
if err != nil {
return nil, fmt.Errorf("error getting s3 object '%s' in bucket '%s': %s", key, bucket, err)
}
return result.Body, nil
}