-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcs.go
54 lines (46 loc) · 1.14 KB
/
cs.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
package config
import (
"context"
"log/slog"
"github.com/m-mizutani/octovy/pkg/domain/interfaces"
"github.com/m-mizutani/octovy/pkg/infra/cs"
"github.com/urfave/cli/v2"
)
type CloudStorage struct {
bucket string
prefix string
}
func (x *CloudStorage) Flags() []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "cloud-storage-bucket",
Usage: "Cloud Storage bucket name",
Category: "Cloud Storage",
Destination: &x.bucket,
EnvVars: []string{"OCTOVY_CLOUD_STORAGE_BUCKET"},
},
&cli.StringFlag{
Name: "cloud-storage-prefix",
Usage: "Cloud Storage prefix",
Category: "Cloud Storage",
Destination: &x.prefix,
EnvVars: []string{"OCTOVY_CLOUD_STORAGE_PREFIX"},
},
}
}
func (x *CloudStorage) LogValue() slog.Value {
return slog.GroupValue(
slog.Any("Bucket", x.bucket),
slog.Any("Prefix", x.prefix),
)
}
func (x *CloudStorage) NewClient(ctx context.Context) (interfaces.Storage, error) {
if x.bucket == "" {
return nil, nil
}
var options []cs.Option
if x.prefix != "" {
options = append(options, cs.WithPrefix(x.prefix))
}
return cs.New(ctx, x.bucket, options...)
}