-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths3_client.go
More file actions
51 lines (38 loc) · 1.1 KB
/
s3_client.go
File metadata and controls
51 lines (38 loc) · 1.1 KB
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
package backend
import (
"context"
"fmt"
s3Config "github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
type S3Client interface {
GetObject(ctx context.Context, bucket string, key string, versionId string) (*s3.GetObjectOutput, error)
}
type S3BackendClient struct {
s3Client *s3.Client
}
func (c *S3BackendClient) GetObject(ctx context.Context, bucket string, key string, versionId string) (*s3.GetObjectOutput, error) {
objectInput := &s3.GetObjectInput{
Bucket: &bucket,
Key: &key,
}
if versionId != "" {
objectInput.VersionId = &versionId
}
return c.s3Client.GetObject(ctx, objectInput)
}
func NewS3Client(ctx context.Context, profile string) (S3Client, error) {
opts := []func(*s3Config.LoadOptions) error{}
if profile != "" {
opts = append(opts, s3Config.WithSharedConfigProfile(profile))
}
cfg, err := s3Config.LoadDefaultConfig(ctx, opts...)
if err != nil {
return nil, fmt.Errorf("failed to load SDK configuration: %w", err)
}
client := s3.NewFromConfig(cfg)
backendClient := S3BackendClient{
s3Client: client,
}
return &backendClient, nil
}