From 23efe063cddc0e812596e6051f1c1a623b616632 Mon Sep 17 00:00:00 2001 From: Robert Maticevic Date: Thu, 21 Sep 2023 10:51:53 +0200 Subject: [PATCH] MINOR: specification: add mode to consul service discovery --- models/consul.go | 50 +++++++++++++++++++++ models/consul_compare.go | 8 ++++ models/consul_compare_test.go | 4 +- specification/build/haproxy_spec.yaml | 6 +++ specification/models/service-discovery.yaml | 4 ++ 5 files changed, 70 insertions(+), 2 deletions(-) diff --git a/models/consul.go b/models/consul.go index 71e2d6e4..1eb88d23 100644 --- a/models/consul.go +++ b/models/consul.go @@ -70,6 +70,10 @@ type Consul struct { // Pattern: ^[^\s]+$ ID *string `json:"id,omitempty"` + // mode + // Enum: [http https] + Mode *string `json:"mode,omitempty"` + // name Name string `json:"name,omitempty"` @@ -137,6 +141,10 @@ func (m *Consul) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateMode(formats); err != nil { + res = append(res, err) + } + if err := m.validatePort(formats); err != nil { res = append(res, err) } @@ -257,6 +265,48 @@ func (m *Consul) validateID(formats strfmt.Registry) error { return nil } +var consulTypeModePropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["http","https"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + consulTypeModePropEnum = append(consulTypeModePropEnum, v) + } +} + +const ( + + // ConsulModeHTTP captures enum value "http" + ConsulModeHTTP string = "http" + + // ConsulModeHTTPS captures enum value "https" + ConsulModeHTTPS string = "https" +) + +// prop value enum +func (m *Consul) validateModeEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, consulTypeModePropEnum, true); err != nil { + return err + } + return nil +} + +func (m *Consul) validateMode(formats strfmt.Registry) error { + if swag.IsZero(m.Mode) { // not required + return nil + } + + // value enum + if err := m.validateModeEnum("mode", "body", *m.Mode); err != nil { + return err + } + + return nil +} + func (m *Consul) validatePort(formats strfmt.Registry) error { if err := validate.Required("port", "body", m.Port); err != nil { diff --git a/models/consul_compare.go b/models/consul_compare.go index 7c305310..4e5a84e7 100644 --- a/models/consul_compare.go +++ b/models/consul_compare.go @@ -61,6 +61,10 @@ func (s Consul) Equal(t Consul, opts ...Options) bool { return false } + if !equalPointers(s.Mode, t.Mode) { + return false + } + if s.Name != t.Name { return false } @@ -161,6 +165,10 @@ func (s Consul) Diff(t Consul, opts ...Options) map[string][]interface{} { diff["ID"] = []interface{}{ValueOrNil(s.ID), ValueOrNil(t.ID)} } + if !equalPointers(s.Mode, t.Mode) { + diff["Mode"] = []interface{}{ValueOrNil(s.Mode), ValueOrNil(t.Mode)} + } + if s.Name != t.Name { diff["Name"] = []interface{}{s.Name, t.Name} } diff --git a/models/consul_compare_test.go b/models/consul_compare_test.go index fc8ffe80..9cf687f8 100644 --- a/models/consul_compare_test.go +++ b/models/consul_compare_test.go @@ -181,7 +181,7 @@ func TestConsulDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 20 { + if len(result) != 21 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { @@ -191,7 +191,7 @@ func TestConsulDiffFalse(t *testing.T) { if err != nil { t.Errorf(err.Error()) } - t.Errorf("Expected Consul to be different in 20 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected Consul to be different in 21 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 d83c3e4b..b08434da 100644 --- a/specification/build/haproxy_spec.yaml +++ b/specification/build/haproxy_spec.yaml @@ -9397,6 +9397,12 @@ definitions: pattern: ^[^\s]+$ type: string x-nullable: true + mode: + default: http + enum: + - http + - https + type: string name: type: string namespace: diff --git a/specification/models/service-discovery.yaml b/specification/models/service-discovery.yaml index f371c472..76f0b31b 100644 --- a/specification/models/service-discovery.yaml +++ b/specification/models/service-discovery.yaml @@ -106,6 +106,10 @@ consul: type: integer minimum: 1 maximum: 65535 + mode: + type: string + enum: [http, https] + default: http token: type: string pattern: '^[^\s]+$'