From 7307dd2ab5901b4cb9871971cf6be597b3c20eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Gaumont?= Date: Thu, 26 Sep 2024 11:45:21 +0200 Subject: [PATCH] Display constraints for configuration parameters --- CHANGELOG.md | 3 +++ spec/cb/config_param_spec.cr | 38 ++++++++++++++++++++++++++++-------- spec/support/factory.cr | 3 +++ src/cb/config_param.cr | 13 +++++++++++- src/models/config_param.cr | 4 +++- 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65081a9..62b0231 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- `cb config-param list-supported` now returns `min_value`, `max_value`, and + `enum` constraints for each parameters, if applicable. ## [3.6.0] - 2024-07-26 ### Added diff --git a/spec/cb/config_param_spec.cr b/spec/cb/config_param_spec.cr index 50e0dc5..a2945c0 100644 --- a/spec/cb/config_param_spec.cr +++ b/spec/cb/config_param_spec.cr @@ -76,6 +76,9 @@ Spectator.describe ConfigurationParameterGet do "parameters": [ { "component": "postgres", + "enum": [], + "min_value": "100", + "max_value": "2000", "name": "postgres:max_connections", "parameter_name": "max_connections", "requires_restart": false, @@ -104,9 +107,21 @@ Spectator.describe ConfigurationParameterListSupported do Factory.configuration_parameter(value: nil), Factory.configuration_parameter( component: "pgbouncer", - name: "pgbouncer:default_pool_size", - parameter_name: "default_pool_size", - value: nil + name: "pgbouncer:auth_type", + parameter_name: "auth_type", + value: nil, + min_value: nil, + max_value: nil, + enum: ["cert", "md5", "trust"] + ), + Factory.configuration_parameter( + component: "pgbouncer", + name: "pgbouncer:fake", + parameter_name: "fake", + value: nil, + min_value: nil, + max_value: nil, + enum: [] of String ), ] } @@ -115,9 +130,10 @@ Spectator.describe ConfigurationParameterListSupported do action.call expected = <<-EXPECTED - Component Name Requires Restart - postgres max_connections no - pgbouncer default_pool_size no + Component Name Requires Restart Constraints + postgres max_connections no min: 100, max: 2000 + pgbouncer auth_type no enum: cert, md5, trust + pgbouncer fake no EXPECTED expect(&.output).to look_like expected @@ -128,8 +144,8 @@ Spectator.describe ConfigurationParameterListSupported do action.call expected = <<-EXPECTED - Component Name Requires Restart - postgres max_connections no + Component Name Requires Restart Constraints + postgres max_connections no min: 100, max: 2000 EXPECTED expect(&.output).to look_like expected @@ -179,6 +195,9 @@ Spectator.describe ConfigurationParameterSet do "parameters": [ { "component": "postgres", + "enum": [], + "min_value": "100", + "max_value": "2000", "name": "postgres:max_connections", "parameter_name": "max_connections", "requires_restart": false, @@ -242,6 +261,9 @@ Spectator.describe ConfigurationParameterReset do "parameters": [ { "component": "postgres", + "enum": [], + "min_value": "100", + "max_value": "2000", "name": "postgres:max_connections", "parameter_name": "max_connections", "requires_restart": false, diff --git a/spec/support/factory.cr b/spec/support/factory.cr index 1f4a423..87b2854 100644 --- a/spec/support/factory.cr +++ b/spec/support/factory.cr @@ -109,6 +109,9 @@ module Factory parameter_name: "max_connections", requires_restart: false, value: "100", + enum: [] of String, + min_value: "100", + max_value: "2000", }.merge(params) CB::Model::ConfigurationParameter.new **params diff --git a/src/cb/config_param.cr b/src/cb/config_param.cr index 81fd6f6..c16640b 100644 --- a/src/cb/config_param.cr +++ b/src/cb/config_param.cr @@ -93,11 +93,19 @@ module CB add "Component" add "Name" add "Requires Restart" + add "Constraints" end header unless no_header - rows parameters.map { |p| [p.component, p.parameter_name, p.requires_restart ? "yes" : "no"] } + rows parameters.map { |p| + constraints = [] of String + constraints << "enum: #{p.enum.join(", ")}" if p.enum.size > 0 + constraints << "min: #{p.min_value}" if p.min_value && p.min_value != "" + constraints << "max: #{p.max_value}" if p.max_value && p.max_value != "" + + [p.component, p.parameter_name, p.requires_restart ? "yes" : "no", constraints.join(", ")] + } end output << table.render << '\n' @@ -106,6 +114,9 @@ module CB "parameters": parameters.map do |p| { "component": p.component, + "enum": p.enum, + "min_value": p.min_value, + "max_value": p.max_value, "name": p.name, "parameter_name": p.parameter_name, "require_restart": p.requires_restart, diff --git a/src/models/config_param.cr b/src/models/config_param.cr index 3297f41..ecb7251 100644 --- a/src/models/config_param.cr +++ b/src/models/config_param.cr @@ -1,11 +1,13 @@ module CB::Model jrecord ConfigurationParameter, component : String? = nil, + enum : Array(String) = [] of String, + min_value : String? = nil, + max_value : String? = nil, name : String = "", parameter_name : String? = nil, requires_restart : Bool = false, value : String? = nil do - @[JSON::Field(key: "parameter_name", emit_null: false)] def to_s(io : IO) io << name.colorize.t_name << '=' << value end