Skip to content

Commit 5cf2b73

Browse files
ignore configs with no KVs and simplify config builder (#2342)
convert all \n to ','
1 parent 5533096 commit 5cf2b73

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

restapi/admin_config.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package restapi
1818

1919
import (
2020
"context"
21-
"errors"
2221
"fmt"
2322
"strings"
2423

@@ -132,7 +131,7 @@ func getConfig(ctx context.Context, client MinioAdmin, name string) ([]*models.C
132131
confkv = append(confkv, &models.ConfigurationKV{Key: kv.Key, Value: kv.Value})
133132
}
134133
if len(confkv) == 0 {
135-
return nil, errors.New("Invalid SubSystem - check config format")
134+
continue
136135
}
137136
var fullConfigName string
138137
if scfg.Target == "" {
@@ -192,15 +191,20 @@ func setConfigWithARNAccountID(ctx context.Context, client MinioAdmin, configNam
192191
// buildConfig builds a concatenated string including name and keyvalues
193192
// e.g. `region name=us-west-1`
194193
func buildConfig(configName *string, kvs []*models.ConfigurationKV) *string {
195-
configElements := []string{*configName}
194+
var builder strings.Builder
195+
builder.WriteString(*configName)
196196
for _, kv := range kvs {
197-
key := kv.Key
198-
val := fmt.Sprintf("\"%s\"", kv.Value)
199-
if key != "" {
200-
configElements = append(configElements, fmt.Sprintf("%s=%s", key, val))
197+
key := strings.TrimSpace(kv.Key)
198+
if key == "" {
199+
continue
201200
}
201+
builder.WriteString(" ")
202+
builder.WriteString(key)
203+
builder.WriteString("=")
204+
// All newlines must be converted to ','
205+
builder.WriteString(strings.ReplaceAll(strings.TrimSpace(fmt.Sprintf("\"%s\"", kv.Value)), "\n", ","))
202206
}
203-
config := strings.Join(configElements, " ")
207+
config := builder.String()
204208
return &config
205209
}
206210

0 commit comments

Comments
 (0)