-
Notifications
You must be signed in to change notification settings - Fork 178
/
s3.go
52 lines (42 loc) · 1.12 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
package uploader
import (
"bytes"
"context"
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/rs/zerolog"
"github.com/onflow/flow-go/engine/execution"
)
var _ Uploader = (*S3Uploader)(nil)
// S3Uploader is a S3 implementation of the uploader interface.
type S3Uploader struct {
ctx context.Context
log zerolog.Logger
client *s3.Client
bucket string
}
// NewS3Uploader returns a new S3 uploader instance.
func NewS3Uploader(ctx context.Context, client *s3.Client, bucket string, log zerolog.Logger) *S3Uploader {
return &S3Uploader{
ctx: ctx,
log: log,
client: client,
bucket: bucket,
}
}
// Upload uploads the given computation result to the configured S3 bucket.
func (u *S3Uploader) Upload(result *execution.ComputationResult) error {
uploader := manager.NewUploader(u.client)
key := GCPBlockDataObjectName(result)
buf := &bytes.Buffer{}
err := WriteComputationResultsTo(result, buf)
if err != nil {
return err
}
_, err = uploader.Upload(u.ctx, &s3.PutObjectInput{
Bucket: &u.bucket,
Key: &key,
Body: buf,
})
return err
}