Skip to content

Commit 5fbf4c4

Browse files
committed
feat(config,utils/flags): add s3.bucket_lookup_type flag in cli options
1 parent 8c78612 commit 5fbf4c4

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ OPTIONS:
263263
--s3.bucket value The S3/minio bucket to use when using S3 proxy backend.
264264
[$BAZEL_REMOTE_S3_BUCKET]
265265
266+
--s3.bucket_lookup_type value The S3/minio bucket lookup type to use when
267+
using S3 proxy backend. (default: auto, types: auto|dns|path)
268+
[$BAZEL_REMOTE_S3_BUCKET_LOOKUP_TYPE]
269+
266270
--s3.prefix value The S3/minio object prefix to use when using S3 proxy
267271
backend. [$BAZEL_REMOTE_S3_PREFIX]
268272

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ func get(ctx *cli.Context) (*Config, error) {
447447
s3 = &S3CloudStorageConfig{
448448
Endpoint: ctx.String("s3.endpoint"),
449449
Bucket: ctx.String("s3.bucket"),
450+
BucketLookupType: ctx.String("s3.bucket_lookup_type"),
450451
Prefix: ctx.String("s3.prefix"),
451452
AuthMethod: ctx.String("s3.auth_method"),
452453
AccessKeyID: ctx.String("s3.access_key_id"),

config/proxy.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/buchgr/bazel-remote/v2/cache/gcsproxy"
99
"github.com/buchgr/bazel-remote/v2/cache/httpproxy"
1010
"github.com/buchgr/bazel-remote/v2/cache/s3proxy"
11+
"github.com/minio/minio-go/v7"
1112
)
1213

1314
func (c *Config) setProxy() error {
@@ -49,7 +50,7 @@ func (c *Config) setProxy() error {
4950
c.ProxyBackend = s3proxy.New(
5051
c.S3CloudStorage.Endpoint,
5152
c.S3CloudStorage.Bucket,
52-
c.S3CloudStorage.BucketLookupType,
53+
parseBucketLoopupType(c.S3CloudStorage.BucketLookupType),
5354
c.S3CloudStorage.Prefix,
5455
creds,
5556
c.S3CloudStorage.DisableSSL,
@@ -79,3 +80,14 @@ func (c *Config) setProxy() error {
7980

8081
return nil
8182
}
83+
84+
func parseBucketLoopupType(typeStr string) minio.BucketLookupType {
85+
valMap := map[string]minio.BucketLookupType{
86+
"auto": minio.BucketLookupAuto,
87+
"dns": minio.BucketLookupDNS,
88+
"path": minio.BucketLookupPath,
89+
}
90+
91+
// also when not found the type, return "auto" type.
92+
return valMap[typeStr]
93+
}

config/s3.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/buchgr/bazel-remote/v2/cache/s3proxy"
88

9-
"github.com/minio/minio-go/v7"
109
"github.com/minio/minio-go/v7/pkg/credentials"
1110
)
1211

@@ -25,8 +24,7 @@ type S3CloudStorageConfig struct {
2524
KeyVersion *int `yaml:"key_version"`
2625
AWSProfile string `yaml:"aws_profile"`
2726
AWSSharedCredentialsFile string `yaml:"aws_shared_credentials_file"`
28-
29-
BucketLookupType minio.BucketLookupType `yaml:"bucket_lookup_type"`
27+
BucketLookupType string `yaml:"bucket_lookup_type"`
3028
}
3129

3230
func (s3c S3CloudStorageConfig) GetCredentials() (*credentials.Credentials, error) {

utils/flags/flags.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ func GetCliFlags() []cli.Flag {
219219
Usage: "The S3/minio bucket to use when using S3 proxy backend.",
220220
EnvVars: []string{"BAZEL_REMOTE_S3_BUCKET"},
221221
},
222+
&cli.StringFlag{
223+
Name: "s3.bucket_lookup_type",
224+
Value: "auto",
225+
Usage: "The S3/minio bucket lookup type(auto|dns|path) to use when using S3 proxy backend.",
226+
EnvVars: []string{"BAZEL_REMOTE_S3_BUCKET_LOOKUP_TYPE"},
227+
},
222228
&cli.StringFlag{
223229
Name: "s3.prefix",
224230
Value: "",

0 commit comments

Comments
 (0)