From 63319b045868941ecf372e4a18f952aa9dfa8155 Mon Sep 17 00:00:00 2001 From: Helene Durand Date: Fri, 16 Feb 2024 12:34:02 +0100 Subject: [PATCH] MEDIUM: remove defaults and rename named_defaults --- specification/build/haproxy_spec.yaml | 58 +----- specification/haproxy-spec.yaml | 6 +- .../paths/configuration/defaults.yaml | 114 +++++++++++- .../paths/configuration/named_defaults.yaml | 149 --------------- test/convert.go | 13 +- test/defaults_test.go | 25 +-- test/expected/structured.json | 171 +----------------- test/http_check_test.go | 4 +- test/http_error_rule_test.go | 2 +- 9 files changed, 117 insertions(+), 425 deletions(-) delete mode 100644 specification/paths/configuration/named_defaults.yaml diff --git a/specification/build/haproxy_spec.yaml b/specification/build/haproxy_spec.yaml index 7ca26e5f..7f18f6f2 100644 --- a/specification/build/haproxy_spec.yaml +++ b/specification/build/haproxy_spec.yaml @@ -11228,60 +11228,6 @@ paths: tags: - Global /services/haproxy/configuration/defaults: - get: - deprecated: true - description: Returns defaults part of configuration, this has been deprecated, use named_defaults instead. - operationId: getDefaults - parameters: - - $ref: '#/parameters/transaction_id' - responses: - "200": - description: Successful operation - headers: - Configuration-Version: - description: Configuration file version - type: string - schema: - $ref: '#/definitions/defaults' - default: - $ref: '#/responses/DefaultError' - summary: Return defaults part of configuration - tags: - - Defaults - put: - deprecated: true - description: Replace defaults part of config, this has been deprecated, use named_defaults instead. - operationId: replaceDefaults - parameters: - - in: body - name: data - required: true - schema: - $ref: '#/definitions/defaults' - - $ref: '#/parameters/transaction_id' - - $ref: '#/parameters/version' - - $ref: '#/parameters/force_reload' - responses: - "200": - description: Defaults replaced - schema: - $ref: '#/definitions/defaults' - "202": - description: Configuration change accepted and reload requested - headers: - Reload-ID: - description: ID of the requested reload - type: string - schema: - $ref: '#/definitions/defaults' - "400": - $ref: '#/responses/BadRequest' - default: - $ref: '#/responses/DefaultError' - summary: Replace defaults - tags: - - Defaults - /services/haproxy/configuration/named_defaults: get: description: Returns an array of all configured defaults. operationId: getDefaultsSections @@ -11301,7 +11247,7 @@ paths: summary: Return an array of defaults tags: - Defaults - post: + put: description: Adds a new defaults section to the configuration file. operationId: createDefaultsSection parameters: @@ -11335,7 +11281,7 @@ paths: summary: Add a defaults section tags: - Defaults - /services/haproxy/configuration/named_defaults/{name}: + /services/haproxy/configuration/defaults/{name}: delete: description: Deletes a defaults section from the configuration by it's name. operationId: deleteDefaultsSection diff --git a/specification/haproxy-spec.yaml b/specification/haproxy-spec.yaml index de259cfb..3279966b 100644 --- a/specification/haproxy-spec.yaml +++ b/specification/haproxy-spec.yaml @@ -788,10 +788,8 @@ paths: $ref: "paths/configuration/global.yaml#/global" /services/haproxy/configuration/defaults: $ref: "paths/configuration/defaults.yaml#/defaults" - /services/haproxy/configuration/named_defaults: - $ref: "paths/configuration/named_defaults.yaml#/defaults" - /services/haproxy/configuration/named_defaults/{name}: - $ref: "paths/configuration/named_defaults.yaml#/defaults_one" + /services/haproxy/configuration/defaults/{name}: + $ref: "paths/configuration/defaults.yaml#/defaults_one" /services/haproxy/configuration/frontends: $ref: "paths/configuration/frontend.yaml#/frontends" /services/haproxy/configuration/frontends/{name}: diff --git a/specification/paths/configuration/defaults.yaml b/specification/paths/configuration/defaults.yaml index 7d51248e..de785666 100644 --- a/specification/paths/configuration/defaults.yaml +++ b/specification/paths/configuration/defaults.yaml @@ -1,10 +1,9 @@ --- defaults: get: - deprecated: true - summary: Return defaults part of configuration - description: Returns defaults part of configuration, this has been deprecated, use named_defaults instead. - operationId: getDefaults + summary: Return an array of defaults + description: Returns an array of all configured defaults. + operationId: getDefaultsSections parameters: - $ref: "#/parameters/transaction_id" tags: @@ -17,14 +16,13 @@ defaults: description: Configuration file version type: string schema: - $ref: "#/definitions/defaults" + $ref: "#/definitions/defaults_sections" 'default': $ref: '#/responses/DefaultError' put: - deprecated: true - summary: Replace defaults - description: Replace defaults part of config, this has been deprecated, use named_defaults instead. - operationId: replaceDefaults + summary: Add a defaults section + description: Adds a new defaults section to the configuration file. + operationId: createDefaultsSection parameters: - name: data required: true @@ -36,6 +34,72 @@ defaults: - $ref: "#/parameters/force_reload" tags: - Defaults + responses: + '202': + description: Configuration change accepted and reload requested + headers: + Reload-ID: + description: ID of the requested reload + type: string + schema: + $ref: "#/definitions/defaults" + '201': + description: Defaults created + schema: + $ref: "#/definitions/defaults" + '409': + $ref: '#/responses/AlreadyExists' + '400': + $ref: '#/responses/BadRequest' + 'default': + $ref: '#/responses/DefaultError' +defaults_one: + get: + summary: Return a defaults section + description: Returns one defaults section configuration by it's name. + operationId: getDefaultsSection + tags: + - Defaults + parameters: + - name: name + in: path + description: Defaults name + required: true + type: string + - $ref: "#/parameters/transaction_id" + responses: + '200': + description: Successful operation + headers: + Configuration-Version: + description: Configuration file version + type: string + schema: + $ref: "#/definitions/defaults" + '404': + $ref: '#/responses/NotFound' + 'default': + $ref: '#/responses/DefaultError' + put: + summary: Replace a defatults section + description: Replaces a defatults section configuration by it's name. + operationId: replaceDefaultsSection + tags: + - Defaults + parameters: + - name: name + in: path + description: Defaults name + required: true + type: string + - name: data + required: true + in: body + schema: + $ref: "#/definitions/defaults" + - $ref: "#/parameters/transaction_id" + - $ref: "#/parameters/version" + - $ref: "#/parameters/force_reload" responses: '202': description: Configuration change accepted and reload requested @@ -46,10 +110,40 @@ defaults: schema: $ref: "#/definitions/defaults" '200': - description: Defaults replaced + description: Defaults section replaced schema: $ref: "#/definitions/defaults" '400': $ref: '#/responses/BadRequest' + '404': + $ref: '#/responses/NotFound' + 'default': + $ref: '#/responses/DefaultError' + delete: + summary: Delete a defaults section + description: Deletes a defaults section from the configuration by it's name. + operationId: deleteDefaultsSection + tags: + - Defaults + parameters: + - name: name + in: path + description: Defaults name + required: true + type: string + - $ref: "#/parameters/transaction_id" + - $ref: "#/parameters/version" + - $ref: "#/parameters/force_reload" + responses: + '202': + description: Configuration change accepted and reload requested + headers: + Reload-ID: + description: ID of the requested reload + type: string + '204': + description: Defaults section deleted + '404': + $ref: '#/responses/NotFound' 'default': $ref: '#/responses/DefaultError' diff --git a/specification/paths/configuration/named_defaults.yaml b/specification/paths/configuration/named_defaults.yaml deleted file mode 100644 index bdbde998..00000000 --- a/specification/paths/configuration/named_defaults.yaml +++ /dev/null @@ -1,149 +0,0 @@ ---- -defaults: - get: - summary: Return an array of defaults - description: Returns an array of all configured defaults. - operationId: getDefaultsSections - parameters: - - $ref: "#/parameters/transaction_id" - tags: - - Defaults - responses: - '200': - description: Successful operation - headers: - Configuration-Version: - description: Configuration file version - type: string - schema: - $ref: "#/definitions/defaults_sections" - 'default': - $ref: '#/responses/DefaultError' - post: - summary: Add a defaults section - description: Adds a new defaults section to the configuration file. - operationId: createDefaultsSection - parameters: - - name: data - required: true - in: body - schema: - $ref: "#/definitions/defaults" - - $ref: "#/parameters/transaction_id" - - $ref: "#/parameters/version" - - $ref: "#/parameters/force_reload" - tags: - - Defaults - responses: - '202': - description: Configuration change accepted and reload requested - headers: - Reload-ID: - description: ID of the requested reload - type: string - schema: - $ref: "#/definitions/defaults" - '201': - description: Defaults created - schema: - $ref: "#/definitions/defaults" - '409': - $ref: '#/responses/AlreadyExists' - '400': - $ref: '#/responses/BadRequest' - 'default': - $ref: '#/responses/DefaultError' -defaults_one: - get: - summary: Return a defaults section - description: Returns one defaults section configuration by it's name. - operationId: getDefaultsSection - tags: - - Defaults - parameters: - - name: name - in: path - description: Defaults name - required: true - type: string - - $ref: "#/parameters/transaction_id" - responses: - '200': - description: Successful operation - headers: - Configuration-Version: - description: Configuration file version - type: string - schema: - $ref: "#/definitions/defaults" - '404': - $ref: '#/responses/NotFound' - 'default': - $ref: '#/responses/DefaultError' - put: - summary: Replace a defatults section - description: Replaces a defatults section configuration by it's name. - operationId: replaceDefaultsSection - tags: - - Defaults - parameters: - - name: name - in: path - description: Defaults name - required: true - type: string - - name: data - required: true - in: body - schema: - $ref: "#/definitions/defaults" - - $ref: "#/parameters/transaction_id" - - $ref: "#/parameters/version" - - $ref: "#/parameters/force_reload" - responses: - '202': - description: Configuration change accepted and reload requested - headers: - Reload-ID: - description: ID of the requested reload - type: string - schema: - $ref: "#/definitions/defaults" - '200': - description: Defaults section replaced - schema: - $ref: "#/definitions/defaults" - '400': - $ref: '#/responses/BadRequest' - '404': - $ref: '#/responses/NotFound' - 'default': - $ref: '#/responses/DefaultError' - delete: - summary: Delete a defaults section - description: Deletes a defaults section from the configuration by it's name. - operationId: deleteDefaultsSection - tags: - - Defaults - parameters: - - name: name - in: path - description: Defaults name - required: true - type: string - - $ref: "#/parameters/transaction_id" - - $ref: "#/parameters/version" - - $ref: "#/parameters/force_reload" - responses: - '202': - description: Configuration change accepted and reload requested - headers: - Reload-ID: - description: ID of the requested reload - type: string - '204': - description: Defaults section deleted - '404': - $ref: '#/responses/NotFound' - 'default': - $ref: '#/responses/DefaultError' diff --git a/test/convert.go b/test/convert.go index c26322d3..cb630719 100644 --- a/test/convert.go +++ b/test/convert.go @@ -268,18 +268,13 @@ func StructuredToCaptureMap() map[string]models.Captures { return res } -func StructuredToDefaultsMap() models.Defaults { - resources, _ := expectedResources[models.Defaults]("defaults") - return resources[""] -} - func StructuredToGlobalMap() models.Global { resources, _ := expectedResources[models.Global]("global") return resources[""] } -func StructuredToNamedDefaultsMap() map[string][]*models.Defaults { - resources, _ := expectedResources[models.Defaults]("named_defaults") +func StructuredToDefaultsMap() map[string][]*models.Defaults { + resources, _ := expectedResources[models.Defaults]("defaults") res := make(map[string][]*models.Defaults) for _, v := range resources { currentv := v @@ -343,7 +338,7 @@ func StructuredToHTTPCheckMap() map[string]models.HTTPChecks { res := make(map[string]models.HTTPChecks) resources := make(map[string][]models.HTTPCheck) _ = expectedChildResources[models.Backend, models.HTTPCheck](resources, "backends", "name", "http_check_list") - _ = expectedRootChildResources[models.Defaults, models.HTTPCheck](resources, "defaults", "name", "http_check_list") + _ = expectedChildResources[models.Defaults, models.HTTPCheck](resources, "defaults", "name", "http_check_list") for k, v := range resources { res[k] = toSliceOfPtrs(v) } @@ -355,7 +350,7 @@ func StructuredToHTTPErrorRuleMap() map[string]models.HTTPErrorRules { resources := make(map[string][]models.HTTPErrorRule) _ = expectedChildResources[models.Backend, models.HTTPErrorRule](resources, "backends", "name", "http_error_rule_list") _ = expectedChildResources[models.Frontend, models.HTTPErrorRule](resources, "frontends", "name", "http_error_rule_list") - _ = expectedRootChildResources[models.Defaults, models.HTTPErrorRule](resources, "defaults", "name", "http_error_rule_list") + _ = expectedChildResources[models.Defaults, models.HTTPErrorRule](resources, "defaults", "name", "http_error_rule_list") for k, v := range resources { res[k] = toSliceOfPtrs(v) } diff --git a/test/defaults_test.go b/test/defaults_test.go index 300df985..276e5081 100644 --- a/test/defaults_test.go +++ b/test/defaults_test.go @@ -11,35 +11,12 @@ import ( "github.com/stretchr/testify/require" ) -func defaultsExpectation() models.Defaults { - initStructuredExpected() - res := StructuredToDefaultsMap() - return res -} - func namedDefaultsExpectation() map[string][]*models.Defaults { initStructuredExpected() - res := StructuredToNamedDefaultsMap() + res := StructuredToDefaultsMap() return res } -func TestGetDefaults(t *testing.T) { //nolint:gocognit,gocyclo - v, d, err := clientTest.GetDefaultsConfiguration("") - if err != nil { - t.Error(err.Error()) - } - - if v != version { - t.Errorf("Version %v returned, expected %v", v, version) - } - checkDefaults(t, d) -} - -func checkDefaults(t *testing.T, g *models.Defaults) { - want := defaultsExpectation() - require.True(t, g.Equal(want), "%s - diff %v", g.Name, cmp.Diff(*g, want)) -} - func TestPushDefaults(t *testing.T) { tOut := int64(6000) tOutS := int64(200) diff --git a/test/expected/structured.json b/test/expected/structured.json index b0e422cc..c23d1509 100644 --- a/test/expected/structured.json +++ b/test/expected/structured.json @@ -1,173 +1,4 @@ { - "defaults": { - "error_files": [ - { - "code": 403, - "file": "/test/403.html" - }, - { - "code": 500, - "file": "/test/500.html" - }, - { - "code": 429, - "file": "/test/429.html" - } - ], - "accept_invalid_http_request": "enabled", - "accept_invalid_http_response": "enabled", - "backlog": 1024, - "balance": { - "algorithm": "roundrobin" - }, - "bind_process": "1-4", - "check_timeout": 2000, - "checkcache": "disabled", - "client_fin_timeout": 1000, - "client_timeout": 4000, - "clitcpka": "enabled", - "clitcpka_cnt": 10, - "clitcpka_idle": 10000, - "clitcpka_intvl": 10000, - "compression": { - "offload": true - }, - "connect_timeout": 5000, - "default_backend": "test", - "default_server": { - "fall": 2000, - "health_check_port": 8888, - "inter": 5000, - "rise": 4000 - }, - "disable_h2_upgrade": "enabled", - "dontlog_normal": "enabled", - "dontlognull": "enabled", - "email_alert": { - "from": "srv01@example.com", - "level": "err", - "mailers": "localmailer1", - "myhostname": "srv01", - "to": "support@example.com" - }, - "external_check": "enabled", - "external_check_command": "/bin/true", - "external_check_path": "/bin", - "forwardfor": { - "enabled": "enabled", - "header": "X-Forwarded-For" - }, - "fullconn": 10, - "h1_case_adjust_bogus_client": "enabled", - "h1_case_adjust_bogus_server": "enabled", - "http-check": { - "index": 0, - "type": "send-state" - }, - "http-use-htx": "enabled", - "http_connection_mode": "httpclose", - "http_ignore_probes": "disabled", - "http_keep_alive_timeout": 3000, - "http_no_delay": "enabled", - "http_request_timeout": 2000, - "http_restrict_req_hdr_names": "reject", - "http_send_name_header": "", - "http_use_proxy_header": "disabled", - "httplog": true, - "httpslog": "disabled", - "idle_close_on_response": "enabled", - "independent_streams": "disabled", - "load_server_state_from_file": "global", - "log_health_checks": "enabled", - "max_keep_alive_queue": 100, - "maxconn": 2000, - "mode": "http", - "monitor_uri": "/monitor", - "nolinger": "disabled", - "originalto": { - "enabled": "enabled" - }, - "persist": "enabled", - "persist_rule": { - "type": "rdp-cookie" - }, - "prefer_last_server": "enabled", - "queue_timeout": 900, - "retry_on": "503 504", - "server_fin_timeout": 1000, - "server_timeout": 2000, - "socket_stats": "enabled", - "source": { - "address": "192.168.1.200", - "address_second": "192.168.1.201", - "port": 80, - "port_second": 443, - "usesrc": "address" - }, - "splice_auto": "enabled", - "splice_request": "enabled", - "splice_response": "enabled", - "srvtcpka": "enabled", - "srvtcpka_cnt": 10, - "srvtcpka_idle": 10000, - "srvtcpka_intvl": 10000, - "stats_options": { - "stats_auths": [ - { - "passwd": "AdMiN123", - "user": "admin" - }, - { - "passwd": "AdMiN1234", - "user": "admin2" - } - ], - "stats_realm": true, - "stats_realm_realm": "HAProxy\\\\ Statistics", - "stats_show_modules": true, - "stats_show_node_name": null - }, - "tarpit_timeout": 2000, - "tcp_smart_accept": "enabled", - "tcp_smart_connect": "enabled", - "tcpka": "enabled", - "transparent": "enabled", - "http_check_list": [ - { - "index": 0, - "type": "send-state" - }, - { - "index": 1, - "type": "disable-on-404" - } - ], - "http_error_rule_list": [ - { - "index": 0, - "return_content": "/test/503", - "return_content_format": "file", - "return_content_type": "\"application/json\"", - "status": 503, - "type": "status" - }, - { - "index": 1, - "return_content": "/test/429", - "return_content_format": "file", - "return_content_type": "application/json", - "status": 429, - "type": "status" - } - ], - "tcp_check_rule_list": [ - { - "action": "send", - "data": "GET\\ /\\ HTTP/2.0\\r\\n", - "index": 0 - } - ] - }, "global": { "h1_case_adjust": [ { @@ -2935,7 +2766,7 @@ } } }, - "named_defaults": { + "defaults": { "test_defaults": { "backlog": 1024, "balance": { diff --git a/test/http_check_test.go b/test/http_check_test.go index 2c1bd7e8..54a7b2b7 100644 --- a/test/http_check_test.go +++ b/test/http_check_test.go @@ -61,7 +61,7 @@ func TestGetHTTPChecks(t *testing.T) { //nolint:gocognit,gocyclo if err != nil { t.Error(err.Error()) } - mchecks[configuration.DefaultsParentName] = checks + mchecks[configuration.DefaultsParentName+"/unnamed_defaults_1"] = checks _, checks, err = clientTest.GetHTTPChecks(configuration.BackendParentName, "test_2", "") if err != nil { @@ -115,7 +115,7 @@ func TestGetHTTPCheck(t *testing.T) { if err != nil { t.Error(err.Error()) } - m[configuration.DefaultsParentName+"/0"] = models.HTTPChecks{check} + m[configuration.DefaultsParentName+"/unnamed_defaults_1/0"] = models.HTTPChecks{check} checkHttpChecks(t, m) } diff --git a/test/http_error_rule_test.go b/test/http_error_rule_test.go index 4afbee26..8be276a3 100644 --- a/test/http_error_rule_test.go +++ b/test/http_error_rule_test.go @@ -53,7 +53,7 @@ func TestGetHTTPErrorRules(t *testing.T) { //nolint:gocognit,gocyclo if err != nil { t.Error(err.Error()) } - mr[configuration.DefaultsParentName] = checks + mr[configuration.DefaultsParentName+"/unnamed_defaults_1"] = checks _, checks, err = clientTest.GetHTTPErrorRules(configuration.BackendParentName, "test_2", "") if err != nil {