-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3.go
51 lines (47 loc) · 1.06 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
package storage
import (
"fmt"
"github.com/dictyBase-docker/github-actions/internal/logger"
"github.com/minio/minio-go"
"github.com/urfave/cli"
)
func getS3Host(c *cli.Context) string {
if len(c.String("s3-server-port")) > 0 {
return fmt.Sprintf("%s:%s", c.String("s3-server"), c.String("s3-server-port"))
}
return c.String("s3-server")
}
func SaveInS3(c *cli.Context) error {
s3Client, err := minio.New(
getS3Host(c),
c.String("access-key"),
c.String("secret-key"),
true,
)
if err != nil {
return cli.NewExitError(
fmt.Sprintf("error in getting minio client %s", err),
2,
)
}
l := logger.GetLogger(c)
path := c.String("upload-path")
if len(path) == 0 {
path = c.String("input")
}
l.Debugf("upload path %s", path)
_, err = s3Client.FPutObject(
c.String("s3-bucket"),
path,
c.String("input"),
minio.PutObjectOptions{ContentType: "application/text"},
)
if err != nil {
return cli.NewExitError(
fmt.Sprintf("unable to upload file %s", err),
2,
)
}
l.Infof("save file %s to s3 storage", c.String("input"))
return nil
}