Skip to content

Commit 49bc4de

Browse files
authored
fix: add validation for s3.bucket_lookup_type
1 parent 67dbda2 commit 49bc4de

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ OPTIONS:
264264
[$BAZEL_REMOTE_S3_BUCKET]
265265
266266
--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)
267+
using S3 proxy backend. (default: auto, Allowed values: auto, dns, path.)
268268
[$BAZEL_REMOTE_S3_BUCKET_LOOKUP_TYPE]
269269
270270
--s3.prefix value The S3/minio object prefix to use when using S3 proxy
@@ -466,6 +466,7 @@ http_address: 0.0.0.0:8080
466466
# bucket: test-bucket
467467
# prefix: test-prefix
468468
# disable_ssl: true
469+
# bucket_lookup_type: auto
469470
#
470471
# Provide exactly one auth_method (access_key, iam_role, or credentials_file) and accompanying configuration.
471472
#

config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/buchgr/bazel-remote/v2/cache/s3proxy"
2020

2121
"github.com/urfave/cli/v2"
22+
"golang.org/x/exp/slices"
2223
yaml "gopkg.in/yaml.v3"
2324
)
2425

@@ -349,6 +350,11 @@ func validateConfig(c *Config) error {
349350
if c.S3CloudStorage.KeyVersion != nil && *c.S3CloudStorage.KeyVersion != 2 {
350351
return fmt.Errorf("s3.key_version (deprecated) must be 2, found %d", c.S3CloudStorage.KeyVersion)
351352
}
353+
354+
if c.S3CloudStorage.BucketLookupType != "" && !slices.Contains([]string{"auto", "dns", "path"}, c.S3CloudStorage.BucketLookupType) {
355+
return fmt.Errorf("s3.bucket_lookup_type must be one of: [auto,dns,path] or be empty, found %s",
356+
c.S3CloudStorage.BucketLookupType)
357+
}
352358
}
353359

354360
if c.AzBlobConfig != nil {

config/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (c *Config) setProxy() error {
8181
return nil
8282
}
8383

84-
func parseBucketLookupType(typeStr string) minio.BucketLookupType {
84+
func parseBucketLookupType(typeStr string) (minio.BucketLookupType, error) {
8585
valMap := map[string]minio.BucketLookupType{
8686
"auto": minio.BucketLookupAuto,
8787
"dns": minio.BucketLookupDNS,

utils/flags/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func GetCliFlags() []cli.Flag {
222222
&cli.StringFlag{
223223
Name: "s3.bucket_lookup_type",
224224
Value: "auto",
225-
Usage: "The S3/minio bucket lookup type(auto|dns|path) to use when using S3 proxy backend.",
225+
Usage: "The S3/minio bucket lookup type to use when using S3 proxy backend. Allowed values: auto, dns, path.",
226226
EnvVars: []string{"BAZEL_REMOTE_S3_BUCKET_LOOKUP_TYPE"},
227227
},
228228
&cli.StringFlag{

0 commit comments

Comments
 (0)