-
Notifications
You must be signed in to change notification settings - Fork 183
/
push.go
64 lines (55 loc) · 1.17 KB
/
push.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
// Copyright 2024 Jetify Inc. and contributors. All rights reserved.
// Use of this source code is governed by the license in the LICENSE file.
package s3
import (
"context"
"fmt"
"io"
"os"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
"github.com/aws/aws-sdk-go-v2/service/s3"
"go.jetpack.io/devbox/internal/devbox/devopt"
"go.jetpack.io/devbox/internal/pullbox/tar"
"go.jetpack.io/devbox/internal/ux"
)
func Push(
ctx context.Context,
creds *devopt.Credentials,
dir, profile string,
) error {
archivePath, err := tar.Compress(dir)
if err != nil {
return err
}
config, err := assumeRole(ctx, creds)
if err != nil {
return err
}
s3Client := manager.NewUploader(s3.NewFromConfig(*config))
file, err := os.Open(archivePath)
if err != nil {
return err
}
defer file.Close()
_, err = s3Client.Upload(ctx, &s3.PutObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(
fmt.Sprintf(
"profiles/%s/%s.tar.gz",
creds.Sub,
profile,
),
),
Body: io.Reader(file),
})
if err != nil {
return err
}
ux.Fsuccess(
os.Stderr,
"Profile successfully pushed (profile: %s)\n",
profile,
)
return nil
}