From 421b28a81c91b8346af31d6b148bff3be17dbb8e Mon Sep 17 00:00:00 2001 From: Marko Juraga Date: Tue, 5 Dec 2023 15:35:01 +0100 Subject: [PATCH] MINOR: server: add set-proxy-v2-tlv-fmt --- configuration/configuration_test.go | 4 +- configuration/server.go | 10 ++ configuration/server_test.go | 42 +++++ go.mod | 6 +- go.sum | 12 +- models/server_params.go | 126 +++++++++++++- models/server_params_compare.go | 81 +++++++++ models/server_params_compare_test.go | 162 +++++++++++++++++- specification/build/haproxy_spec.yaml | 10 ++ .../models/configuration/server_params.yaml | 10 ++ 10 files changed, 449 insertions(+), 14 deletions(-) diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index 70d1c557..5d74d24a 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -336,7 +336,7 @@ frontend test bind 192.168.1.2:8080 name webserv3 thread 1/1 bind [2a01:c9c0:a3:8::3]:80 name ipv6 thread 1/1-1 bind 192.168.1.1:80 name test-quic quic-socket connection thread 1/1 - bind 192.168.1.1:80 name testnbcon thread 1/all nbconn 6 + bind 192.168.1.1:80 name testnbcon thread 1/all nbconn 6 bind-process odd option httplog option dontlognull @@ -650,7 +650,7 @@ backend test external-check command /bin/false use-server webserv if TRUE use-server webserv2 unless TRUE - server webserv 192.168.1.1:9200 maxconn 1000 ssl weight 10 inter 2s cookie BLAH slowstart 6000 proxy-v2-options authority,crc32c ws h1 pool-low-conn 128 id 1234 pool-purge-delay 10s tcp-ut 2s curves secp384r1 client-sigalgs ECDSA+SHA256:RSA+SHA256 sigalgs ECDSA+SHA256 log-bufsize 10 + server webserv 192.168.1.1:9200 maxconn 1000 ssl weight 10 inter 2s cookie BLAH slowstart 6000 proxy-v2-options authority,crc32c ws h1 pool-low-conn 128 id 1234 pool-purge-delay 10s tcp-ut 2s curves secp384r1 client-sigalgs ECDSA+SHA256:RSA+SHA256 sigalgs ECDSA+SHA256 log-bufsize 10 set-proxy-v2-tlv-fmt(0x20) %[fc_pp_tlv(0x20)] server webserv2 192.168.1.1:9300 maxconn 1000 ssl weight 10 inter 2s cookie BLAH slowstart 6000 proxy-v2-options authority,crc32c ws h1 pool-low-conn 128 http-request set-dst hdr(x-dst) http-request set-dst-port int(4000) diff --git a/configuration/server.go b/configuration/server.go index fd97e9f1..1d698deb 100644 --- a/configuration/server.go +++ b/configuration/server.go @@ -478,6 +478,13 @@ func parseServerParams(serverOptions []params.ServerOption, serverParams *models case "ws": serverParams.Ws = v.Value } + case *params.ServerOptionIDValue: + if v.Name == "set-proxy-v2-tlv-fmt" { + serverParams.SetProxyV2TlvFmt = &models.ServerParamsSetProxyV2TlvFmt{ + ID: &v.ID, + Value: &v.Value, + } + } } } // Add corresponding arguments to the source option. @@ -803,6 +810,9 @@ func serializeServerParams(s models.ServerParams) (options []params.ServerOption if s.Socks4 != "" { options = append(options, ¶ms.ServerOptionValue{Name: "socks4", Value: s.Socks4}) } + if s.SetProxyV2TlvFmt != nil && s.SetProxyV2TlvFmt.ID != nil && s.SetProxyV2TlvFmt.Value != nil { + options = append(options, ¶ms.ServerOptionIDValue{Name: "set-proxy-v2-tlv-fmt", ID: *s.SetProxyV2TlvFmt.ID, Value: *s.SetProxyV2TlvFmt.Value}) + } if s.TCPUt != nil { options = append(options, ¶ms.ServerOptionValue{Name: "tcp-ut", Value: strconv.FormatInt(*s.TCPUt, 10)}) } diff --git a/configuration/server_test.go b/configuration/server_test.go index 845e3a64..6e695155 100644 --- a/configuration/server_test.go +++ b/configuration/server_test.go @@ -86,6 +86,26 @@ func TestGetServers(t *testing.T) { //nolint:gocognit,gocyclo if s.Name == "webserv2" && s.LogBufsize != nil { t.Errorf("%v: LogBufsize should be nil: %v", s.Name, s.LogBufsize) } + if s.Name == "webserv" { + if s.SetProxyV2TlvFmt != nil { + if s.SetProxyV2TlvFmt.ID != nil { + if *s.SetProxyV2TlvFmt.ID != "0x20" { + t.Errorf("%v: SetProxyV2TlvFmt ID should be 0x20: %s", s.Name, *s.SetProxyV2TlvFmt.ID) + } + } else { + t.Errorf("%v: SetProxyV2TlvFmt ID should be set", s.Name) + } + if s.SetProxyV2TlvFmt.Value != nil { + if *s.SetProxyV2TlvFmt.Value != "%[fc_pp_tlv(0x20)]" { + t.Errorf("%v: SetProxyV2TlvFmt Value should be %%[fc_pp_tlv(0x20)]: %s", s.Name, *s.SetProxyV2TlvFmt.Value) + } + } else { + t.Errorf("%v: SetProxyV2TlvFmt Value should be set", s.Name) + } + } else { + t.Errorf("%v: SetProxyV2TlvFmt should be set", s.Name) + } + } } _, servers, err = clientTest.GetServers("backend", "test_2", "") @@ -168,6 +188,24 @@ func TestGetServer(t *testing.T) { if s.LogBufsize == nil || *s.LogBufsize != 10 { t.Errorf("%v: LogBufsize should be 10: %v", s.Name, s.LogBufsize) } + if s.SetProxyV2TlvFmt != nil { + if s.SetProxyV2TlvFmt.ID != nil { + if *s.SetProxyV2TlvFmt.ID != "0x20" { + t.Errorf("%v: SetProxyV2TlvFmt ID should be 0x20: %s", s.Name, *s.SetProxyV2TlvFmt.ID) + } + } else { + t.Errorf("%v: SetProxyV2TlvFmt ID should be set", s.Name) + } + if s.SetProxyV2TlvFmt.Value != nil { + if *s.SetProxyV2TlvFmt.Value != "%[fc_pp_tlv(0x20)]" { + t.Errorf("%v: SetProxyV2TlvFmt Value should be %%[fc_pp_tlv(0x20)]: %s", s.Name, *s.SetProxyV2TlvFmt.Value) + } + } else { + t.Errorf("%v: SetProxyV2TlvFmt Value should be set", s.Name) + } + } else { + t.Errorf("%v: SetProxyV2TlvFmt should be set", s.Name) + } _, err = s.MarshalBinary() if err != nil { @@ -270,6 +308,10 @@ func TestCreateEditDeleteServer(t *testing.T) { Sigalgs: "RSA+SHA256", ClientSigalgs: "ECDSA+SHA256", LogBufsize: misc.Int64P(11), + SetProxyV2TlvFmt: &models.ServerParamsSetProxyV2TlvFmt{ + ID: misc.StringP("0x50"), + Value: misc.StringP("%[fc_pp_tlv(0x20)]"), + }, }, } diff --git a/go.mod b/go.mod index c73c67ae..0a44db7f 100644 --- a/go.mod +++ b/go.mod @@ -11,13 +11,13 @@ require ( github.com/google/go-cmp v0.6.0 github.com/google/renameio v1.0.1 github.com/google/uuid v1.3.1 - github.com/haproxytech/config-parser/v5 v5.0.1-0.20231205124653-983ec1a8fa02 + github.com/haproxytech/config-parser/v5 v5.0.1-0.20231205133436-67d880c8f163 github.com/json-iterator/go v1.1.12 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/mitchellh/mapstructure v1.5.0 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 - golang.org/x/text v0.13.0 + golang.org/x/text v0.14.0 golang.org/x/tools v0.14.0 ) @@ -40,6 +40,6 @@ require ( github.com/rogpeppe/go-internal v1.6.1 // indirect go.mongodb.org/mongo-driver v1.12.1 // indirect golang.org/x/mod v0.13.0 // indirect - golang.org/x/sys v0.14.0 // indirect + golang.org/x/sys v0.15.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 682e1d7b..0f475dec 100644 --- a/go.sum +++ b/go.sum @@ -84,8 +84,8 @@ github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWU github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/haproxytech/config-parser/v5 v5.0.1-0.20231205124653-983ec1a8fa02 h1:UqP7BhPVKlI/49JwnZDlR1rHZ3YQulmk5gPxl4V+rYA= -github.com/haproxytech/config-parser/v5 v5.0.1-0.20231205124653-983ec1a8fa02/go.mod h1:ASOyT1KguwXaY0NfoLNjLLs0OlnYHnFgUJsdJe6NhZg= +github.com/haproxytech/config-parser/v5 v5.0.1-0.20231205133436-67d880c8f163 h1:drZRX/gg1eUH3f4VkdjfEwfGqiDxJP0xvNQQt7FeHgc= +github.com/haproxytech/config-parser/v5 v5.0.1-0.20231205133436-67d880c8f163/go.mod h1:iy8nBB1eopwYbyeh3FQpjxZUxfcIDyTV9bW0F1t+cVA= github.com/haproxytech/go-logger v1.1.0 h1:HgGtYaI1ApkvbQdsm7f9AzQQoxTB7w37criTflh7IQE= github.com/haproxytech/go-logger v1.1.0/go.mod h1:OekUd8HCb7ubxMplzHUPBTHNxZmddOWfOjWclZsqIeM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= @@ -209,8 +209,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -220,8 +220,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= diff --git a/models/server_params.go b/models/server_params.go index c194ba92..fc8634f5 100644 --- a/models/server_params.go +++ b/models/server_params.go @@ -284,6 +284,9 @@ type ServerParams struct { // Enum: [enabled disabled] SendProxyV2SslCn string `json:"send_proxy_v2_ssl_cn,omitempty"` + // set proxy v2 tlv fmt + SetProxyV2TlvFmt *ServerParamsSetProxyV2TlvFmt `json:"set-proxy-v2-tlv-fmt,omitempty"` + // shard Shard int64 `json:"shard,omitempty"` @@ -537,6 +540,10 @@ func (m *ServerParams) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateSetProxyV2TlvFmt(formats); err != nil { + res = append(res, err) + } + if err := m.validateSni(formats); err != nil { res = append(res, err) } @@ -1983,6 +1990,25 @@ func (m *ServerParams) validateSendProxyV2SslCn(formats strfmt.Registry) error { return nil } +func (m *ServerParams) validateSetProxyV2TlvFmt(formats strfmt.Registry) error { + if swag.IsZero(m.SetProxyV2TlvFmt) { // not required + return nil + } + + if m.SetProxyV2TlvFmt != nil { + if err := m.SetProxyV2TlvFmt.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("set-proxy-v2-tlv-fmt") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("set-proxy-v2-tlv-fmt") + } + return err + } + } + + return nil +} + func (m *ServerParams) validateSni(formats strfmt.Registry) error { if swag.IsZero(m.Sni) { // not required return nil @@ -2430,8 +2456,33 @@ func (m *ServerParams) validateWs(formats strfmt.Registry) error { return nil } -// ContextValidate validates this server params based on context it is used +// ContextValidate validate this server params based on the context it is used func (m *ServerParams) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateSetProxyV2TlvFmt(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *ServerParams) contextValidateSetProxyV2TlvFmt(ctx context.Context, formats strfmt.Registry) error { + + if m.SetProxyV2TlvFmt != nil { + if err := m.SetProxyV2TlvFmt.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("set-proxy-v2-tlv-fmt") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("set-proxy-v2-tlv-fmt") + } + return err + } + } + return nil } @@ -2452,3 +2503,76 @@ func (m *ServerParams) UnmarshalBinary(b []byte) error { *m = res return nil } + +// ServerParamsSetProxyV2TlvFmt server params set proxy v2 tlv fmt +// +// swagger:model ServerParamsSetProxyV2TlvFmt +type ServerParamsSetProxyV2TlvFmt struct { + + // id + // Required: true + ID *string `json:"id"` + + // value + // Required: true + Value *string `json:"value"` +} + +// Validate validates this server params set proxy v2 tlv fmt +func (m *ServerParamsSetProxyV2TlvFmt) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateID(formats); err != nil { + res = append(res, err) + } + + if err := m.validateValue(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *ServerParamsSetProxyV2TlvFmt) validateID(formats strfmt.Registry) error { + + if err := validate.Required("set-proxy-v2-tlv-fmt"+"."+"id", "body", m.ID); err != nil { + return err + } + + return nil +} + +func (m *ServerParamsSetProxyV2TlvFmt) validateValue(formats strfmt.Registry) error { + + if err := validate.Required("set-proxy-v2-tlv-fmt"+"."+"value", "body", m.Value); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this server params set proxy v2 tlv fmt based on context it is used +func (m *ServerParamsSetProxyV2TlvFmt) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *ServerParamsSetProxyV2TlvFmt) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *ServerParamsSetProxyV2TlvFmt) UnmarshalBinary(b []byte) error { + var res ServerParamsSetProxyV2TlvFmt + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/models/server_params_compare.go b/models/server_params_compare.go index e34663c6..38c6ab46 100644 --- a/models/server_params_compare.go +++ b/models/server_params_compare.go @@ -305,6 +305,28 @@ func (s ServerParams) Equal(t ServerParams, opts ...Options) bool { return false } + if s.SetProxyV2TlvFmt == nil || t.SetProxyV2TlvFmt == nil { + if s.SetProxyV2TlvFmt != nil || t.SetProxyV2TlvFmt != nil { + if opt.NilSameAsEmpty { + empty := &ServerParamsSetProxyV2TlvFmt{} + if s.SetProxyV2TlvFmt == nil { + if !(t.SetProxyV2TlvFmt.Equal(*empty)) { + return false + } + } + if t.SetProxyV2TlvFmt == nil { + if !(s.SetProxyV2TlvFmt.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.SetProxyV2TlvFmt.Equal(*t.SetProxyV2TlvFmt, opt) { + return false + } + if s.Shard != t.Shard { return false } @@ -681,6 +703,28 @@ func (s ServerParams) Diff(t ServerParams, opts ...Options) map[string][]interfa diff["SendProxyV2SslCn"] = []interface{}{s.SendProxyV2SslCn, t.SendProxyV2SslCn} } + if s.SetProxyV2TlvFmt == nil || t.SetProxyV2TlvFmt == nil { + if s.SetProxyV2TlvFmt != nil || t.SetProxyV2TlvFmt != nil { + if opt.NilSameAsEmpty { + empty := &ServerParamsSetProxyV2TlvFmt{} + if s.SetProxyV2TlvFmt == nil { + if !(t.SetProxyV2TlvFmt.Equal(*empty)) { + diff["SetProxyV2TlvFmt"] = []interface{}{ValueOrNil(s.SetProxyV2TlvFmt), ValueOrNil(t.SetProxyV2TlvFmt)} + } + } + if t.SetProxyV2TlvFmt == nil { + if !(s.SetProxyV2TlvFmt.Equal(*empty)) { + diff["SetProxyV2TlvFmt"] = []interface{}{ValueOrNil(s.SetProxyV2TlvFmt), ValueOrNil(t.SetProxyV2TlvFmt)} + } + } + } else { + diff["SetProxyV2TlvFmt"] = []interface{}{ValueOrNil(s.SetProxyV2TlvFmt), ValueOrNil(t.SetProxyV2TlvFmt)} + } + } + } else if !s.SetProxyV2TlvFmt.Equal(*t.SetProxyV2TlvFmt, opt) { + diff["SetProxyV2TlvFmt"] = []interface{}{ValueOrNil(s.SetProxyV2TlvFmt), ValueOrNil(t.SetProxyV2TlvFmt)} + } + if s.Shard != t.Shard { diff["Shard"] = []interface{}{s.Shard, t.Shard} } @@ -767,3 +811,40 @@ func (s ServerParams) Diff(t ServerParams, opts ...Options) map[string][]interfa return diff } + +// Equal checks if two structs of type ServerParamsSetProxyV2TlvFmt are equal +// +// var a, b ServerParamsSetProxyV2TlvFmt +// equal := a.Equal(b) +// +// opts ...Options are ignored in this method +func (s ServerParamsSetProxyV2TlvFmt) Equal(t ServerParamsSetProxyV2TlvFmt, opts ...Options) bool { + if !equalPointers(s.ID, t.ID) { + return false + } + + if !equalPointers(s.Value, t.Value) { + return false + } + + return true +} + +// Diff checks if two structs of type ServerParamsSetProxyV2TlvFmt are equal +// +// var a, b ServerParamsSetProxyV2TlvFmt +// diff := a.Diff(b) +// +// opts ...Options are ignored in this method +func (s ServerParamsSetProxyV2TlvFmt) Diff(t ServerParamsSetProxyV2TlvFmt, opts ...Options) map[string][]interface{} { + diff := make(map[string][]interface{}) + if !equalPointers(s.ID, t.ID) { + diff["ID"] = []interface{}{ValueOrNil(s.ID), ValueOrNil(t.ID)} + } + + if !equalPointers(s.Value, t.Value) { + diff["Value"] = []interface{}{ValueOrNil(s.Value), ValueOrNil(t.Value)} + } + + return diff +} diff --git a/models/server_params_compare_test.go b/models/server_params_compare_test.go index 05019711..7e8f0cf7 100644 --- a/models/server_params_compare_test.go +++ b/models/server_params_compare_test.go @@ -213,7 +213,7 @@ func TestServerParamsDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 89 { + if len(result) != 90 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { @@ -223,7 +223,165 @@ func TestServerParamsDiffFalse(t *testing.T) { if err != nil { t.Errorf(err.Error()) } - t.Errorf("Expected ServerParams to be different in 89 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected ServerParams to be different in 90 cases, but it is not (%d) %s %s", len(result), a, b) + } + } +} + +func TestServerParamsSetProxyV2TlvFmtEqual(t *testing.T) { + samples := []struct { + a, b ServerParamsSetProxyV2TlvFmt + }{} + for i := 0; i < 2; i++ { + var sample ServerParamsSetProxyV2TlvFmt + var result ServerParamsSetProxyV2TlvFmt + err := faker.FakeData(&sample) + if err != nil { + t.Errorf(err.Error()) + } + byteJSON, err := json.Marshal(sample) + if err != nil { + t.Errorf(err.Error()) + } + err = json.Unmarshal(byteJSON, &result) + if err != nil { + t.Errorf(err.Error()) + } + + samples = append(samples, struct { + a, b ServerParamsSetProxyV2TlvFmt + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Equal(sample.b) + if !result { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Errorf(err.Error()) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Errorf(err.Error()) + } + t.Errorf("Expected ServerParamsSetProxyV2TlvFmt to be equal, but it is not %s %s", a, b) + } + } +} + +func TestServerParamsSetProxyV2TlvFmtEqualFalse(t *testing.T) { + samples := []struct { + a, b ServerParamsSetProxyV2TlvFmt + }{} + for i := 0; i < 2; i++ { + var sample ServerParamsSetProxyV2TlvFmt + var result ServerParamsSetProxyV2TlvFmt + err := faker.FakeData(&sample) + if err != nil { + t.Errorf(err.Error()) + } + err = faker.FakeData(&result) + if err != nil { + t.Errorf(err.Error()) + } + samples = append(samples, struct { + a, b ServerParamsSetProxyV2TlvFmt + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Equal(sample.b) + if result { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Errorf(err.Error()) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Errorf(err.Error()) + } + t.Errorf("Expected ServerParamsSetProxyV2TlvFmt to be different, but it is not %s %s", a, b) + } + } +} + +func TestServerParamsSetProxyV2TlvFmtDiff(t *testing.T) { + samples := []struct { + a, b ServerParamsSetProxyV2TlvFmt + }{} + for i := 0; i < 2; i++ { + var sample ServerParamsSetProxyV2TlvFmt + var result ServerParamsSetProxyV2TlvFmt + err := faker.FakeData(&sample) + if err != nil { + t.Errorf(err.Error()) + } + byteJSON, err := json.Marshal(sample) + if err != nil { + t.Errorf(err.Error()) + } + err = json.Unmarshal(byteJSON, &result) + if err != nil { + t.Errorf(err.Error()) + } + + samples = append(samples, struct { + a, b ServerParamsSetProxyV2TlvFmt + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Diff(sample.b) + if len(result) != 0 { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Errorf(err.Error()) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Errorf(err.Error()) + } + t.Errorf("Expected ServerParamsSetProxyV2TlvFmt to be equal, but it is not %s %s, %v", a, b, result) + } + } +} + +func TestServerParamsSetProxyV2TlvFmtDiffFalse(t *testing.T) { + samples := []struct { + a, b ServerParamsSetProxyV2TlvFmt + }{} + for i := 0; i < 2; i++ { + var sample ServerParamsSetProxyV2TlvFmt + var result ServerParamsSetProxyV2TlvFmt + err := faker.FakeData(&sample) + if err != nil { + t.Errorf(err.Error()) + } + err = faker.FakeData(&result) + if err != nil { + t.Errorf(err.Error()) + } + samples = append(samples, struct { + a, b ServerParamsSetProxyV2TlvFmt + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Diff(sample.b) + if len(result) != 2 { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Errorf(err.Error()) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Errorf(err.Error()) + } + t.Errorf("Expected ServerParamsSetProxyV2TlvFmt to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } } } diff --git a/specification/build/haproxy_spec.yaml b/specification/build/haproxy_spec.yaml index ae31ac69..4290f468 100644 --- a/specification/build/haproxy_spec.yaml +++ b/specification/build/haproxy_spec.yaml @@ -786,6 +786,16 @@ definitions: - enabled - disabled type: string + set-proxy-v2-tlv-fmt: + properties: + id: + type: string + value: + type: string + required: + - id + - value + type: object shard: type: integer sigalgs: diff --git a/specification/models/configuration/server_params.yaml b/specification/models/configuration/server_params.yaml index 291c1014..cc05ef3c 100644 --- a/specification/models/configuration/server_params.yaml +++ b/specification/models/configuration/server_params.yaml @@ -238,6 +238,16 @@ server_params: send-proxy-v2: type: string enum: [enabled, disabled] + set-proxy-v2-tlv-fmt: + type: object + required: + - id + - value + properties: + id: + type: string + value: + type: string proxy-v2-options: type: array x-omitempty: true