Skip to content

Commit 898a53c

Browse files
committed
BUG/MINOR: metadata: fix metadata where it was missing
1 parent 0d28197 commit 898a53c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+378
-308
lines changed

config-parser/parsers/acl.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/haproxytech/client-native/v6/config-parser/common"
2323
"github.com/haproxytech/client-native/v6/config-parser/errors"
24+
"github.com/haproxytech/client-native/v6/misc"
2425
"github.com/haproxytech/client-native/v6/models"
2526
)
2627

@@ -35,11 +36,9 @@ func (h *ACL) parse(line string, parts []string, comment string) (*models.ACL, e
3536
ACLName: parts[1],
3637
Criterion: parts[2],
3738
Value: strings.Join(parts[3:], " "),
38-
Metadata: map[string]interface{}{},
3939
}
4040
if comment != "" {
41-
data.Metadata = map[string]interface{}{}
42-
data.Metadata["comment"] = comment
41+
data.Metadata = misc.ParseMetadata(comment)
4342
}
4443
return data, nil
4544
}
@@ -59,9 +58,14 @@ func (h *ACL) Result() ([]common.ReturnResultLine, error) {
5958
sb.WriteString(req.Criterion)
6059
sb.WriteString(" ")
6160
sb.WriteString(req.Value)
61+
62+
comment, err := misc.SerializeMetadata(req.Metadata)
63+
if err != nil {
64+
comment = ""
65+
}
6266
result[index] = common.ReturnResultLine{
6367
Data: sb.String(),
64-
Comment: common.ExtractComment(req.Metadata),
68+
Comment: comment,
6569
}
6670
}
6771
return result, nil

configuration/acme_provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func ParseAcmeProvider(p parser.Parser, name string) (*models.AcmeProvider, erro
157157
if data, err := p.SectionGet(parser.Acme, name); err == nil {
158158
d, ok := data.(types.Section)
159159
if ok {
160-
acme.Metadata = parseMetadata(d.Comment)
160+
acme.Metadata = misc.ParseMetadata(d.Comment)
161161
}
162162
}
163163

@@ -219,7 +219,7 @@ func SerializeAcmeProvider(p parser.Parser, acme *models.AcmeProvider) error {
219219
}
220220

221221
if acme.Metadata != nil {
222-
comment, err := serializeMetadata(acme.Metadata)
222+
comment, err := misc.SerializeMetadata(acme.Metadata)
223223
if err != nil {
224224
return err
225225
}

configuration/backend_switching_rule.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ func ParseBackendSwitchingRule(ub types.UseBackend) *models.BackendSwitchingRule
200200
Name: ub.Name,
201201
Cond: ub.Cond,
202202
CondTest: ub.CondTest,
203-
Metadata: parseMetadata(ub.Comment),
203+
Metadata: misc.ParseMetadata(ub.Comment),
204204
}
205205
}
206206

207207
func SerializeBackendSwitchingRule(bRule models.BackendSwitchingRule) types.UseBackend {
208-
comment, err := serializeMetadata(bRule.Metadata)
208+
comment, err := misc.SerializeMetadata(bRule.Metadata)
209209
if err != nil {
210210
comment = ""
211211
}

configuration/bind.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func ParseBind(ondiskBind types.Bind) *models.Bind {
213213
}
214214
}
215215
}
216-
b.Metadata = parseMetadata(ondiskBind.Comment)
216+
b.Metadata = misc.ParseMetadata(ondiskBind.Comment)
217217
b.BindParams, b.Name = parseBindParams(ondiskBind.Params)
218218
if b.Name == "" {
219219
b.Name = ondiskBind.Path
@@ -453,7 +453,7 @@ func SerializeBind(b models.Bind, opt *options.ConfigurationOptions) types.Bind
453453
} else {
454454
bind.Path = b.Address
455455
}
456-
comment, err := serializeMetadata(b.Metadata)
456+
comment, err := misc.SerializeMetadata(b.Metadata)
457457
if err == nil {
458458
bind.Comment = comment
459459
}

configuration/cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func ParseCacheSection(p parser.Parser, cache *models.Cache) error {
177177
if data, err := p.SectionGet(parser.Cache, name); err == nil {
178178
d, ok := data.(*types.Section)
179179
if ok && d != nil {
180-
cache.Metadata = parseMetadata(d.Comment)
180+
cache.Metadata = misc.ParseMetadata(d.Comment)
181181
}
182182
}
183183

@@ -222,7 +222,7 @@ func SerializeCacheSection(p parser.Parser, data *models.Cache) error {
222222
var err error
223223

224224
if data.Metadata != nil {
225-
comment, err := serializeMetadata(data.Metadata)
225+
comment, err := misc.SerializeMetadata(data.Metadata)
226226
if err != nil {
227227
return err
228228
}

configuration/capture.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
parser "github.com/haproxytech/client-native/v6/config-parser"
2424
parser_errors "github.com/haproxytech/client-native/v6/config-parser/errors"
2525
"github.com/haproxytech/client-native/v6/config-parser/types"
26+
"github.com/haproxytech/client-native/v6/misc"
2627

2728
"github.com/haproxytech/client-native/v6/models"
2829
)
@@ -187,12 +188,12 @@ func ParseDeclareCapture(f types.DeclareCapture) *models.Capture {
187188
return &models.Capture{
188189
Type: f.Type,
189190
Length: f.Length,
190-
Metadata: parseMetadata(f.Comment),
191+
Metadata: misc.ParseMetadata(f.Comment),
191192
}
192193
}
193194

194195
func SerializeDeclareCapture(f models.Capture) types.DeclareCapture {
195-
comment, err := serializeMetadata(f.Metadata)
196+
comment, err := misc.SerializeMetadata(f.Metadata)
196197
if err != nil {
197198
comment = ""
198199
}

configuration/configuration.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ func (s *SectionParser) metadata() any {
420420
}
421421

422422
d := sectionData.(types.Section)
423-
return parseMetadata(d.Comment)
423+
return misc.ParseMetadata(d.Comment)
424424
}
425425

426426
func (s *SectionParser) checkTimeouts(fieldName string) (bool, interface{}) {
@@ -1731,7 +1731,7 @@ func (s *SectionObject) metadata(field reflect.Value) error {
17311731
metadata[key] = valueVal
17321732
}
17331733

1734-
comment, err := serializeMetadata(metadata)
1734+
comment, err := misc.SerializeMetadata(metadata)
17351735
if err != nil {
17361736
return err
17371737
}

configuration/crt_load.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
parser "github.com/haproxytech/client-native/v6/config-parser"
2323
parser_errors "github.com/haproxytech/client-native/v6/config-parser/errors"
2424
"github.com/haproxytech/client-native/v6/config-parser/types"
25+
"github.com/haproxytech/client-native/v6/misc"
2526
"github.com/haproxytech/client-native/v6/models"
2627
)
2728

@@ -163,7 +164,7 @@ func SerializeCrtLoad(load *models.CrtLoad) *types.LoadCert {
163164
Ocsp: load.Ocsp,
164165
Sctl: load.Sctl,
165166
}
166-
comment, err := serializeMetadata(load.Metadata)
167+
comment, err := misc.SerializeMetadata(load.Metadata)
167168
if err == nil {
168169
t.Comment = comment
169170
}

configuration/crt_store.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func ParseCrtStore(p parser.Parser, name string) (*models.CrtStore, error) {
152152
if data, err := p.SectionGet(parser.CrtStore, name); err == nil {
153153
d, ok := data.(types.Section)
154154
if ok {
155-
store.Metadata = parseMetadata(d.Comment)
155+
store.Metadata = misc.ParseMetadata(d.Comment)
156156
}
157157
}
158158

@@ -211,7 +211,7 @@ func ParseCrtStore(p parser.Parser, name string) (*models.CrtStore, error) {
211211
Key: l.Key,
212212
Ocsp: l.Ocsp,
213213
Sctl: l.Sctl,
214-
Metadata: parseMetadata(l.Comment),
214+
Metadata: misc.ParseMetadata(l.Comment),
215215
}
216216
if l.OcspUpdate != nil {
217217
if *l.OcspUpdate {
@@ -232,7 +232,7 @@ func SerializeCrtStore(p parser.Parser, store *models.CrtStore) error {
232232
}
233233

234234
if store.Metadata != nil {
235-
comment, err := serializeMetadata(store.Metadata)
235+
comment, err := misc.SerializeMetadata(store.Metadata)
236236
if err != nil {
237237
return err
238238
}

configuration/dgram_bind.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
parser_errors "github.com/haproxytech/client-native/v6/config-parser/errors"
2727
"github.com/haproxytech/client-native/v6/config-parser/params"
2828
"github.com/haproxytech/client-native/v6/config-parser/types"
29+
"github.com/haproxytech/client-native/v6/misc"
2930

3031
"github.com/haproxytech/client-native/v6/models"
3132
)
@@ -245,7 +246,7 @@ func ParseDgramBind(ondiskDgramBind types.DgramBind) *models.DgramBind {
245246
if b.Name == "" {
246247
b.Name = ondiskDgramBind.Path
247248
}
248-
b.Metadata = parseMetadata(ondiskDgramBind.Comment)
249+
b.Metadata = misc.ParseMetadata(ondiskDgramBind.Comment)
249250
return b
250251
}
251252

@@ -281,7 +282,7 @@ func SerializeDgramBind(b models.DgramBind) types.DgramBind {
281282
dBind.Params = append(dBind.Params, &params.BindOptionValue{Name: "namespace", Value: b.Namespace})
282283
}
283284

284-
comment, err := serializeMetadata(b.Metadata)
285+
comment, err := misc.SerializeMetadata(b.Metadata)
285286
if err == nil {
286287
dBind.Comment = comment
287288
}

0 commit comments

Comments
 (0)