From c46aca2cc5f9e351f3881ced29d0acbd57678f17 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 | 2 ++ spec/cb/config_param_spec.cr | 28 ++++++++++++++++++++-------- spec/support/factory.cr | 3 +++ src/cb/config_param.cr | 13 ++++++++++++- src/models/config_param.cr | 4 +++- 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65081a9..364c7b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `remove-firewall-rule` and `update-firewall-rule`. - `cb network` now manages VPC peerings and supports the following subcommands: `create-peering`, `delete-peering`, `get-peering` and `list-peerings`. +- `cb config-param list-supported` now returns `min_value`, `max_value`, and + `enum` constraints for each parameters, if applicable. ### Deprecated - `cb firewall` deprecated in favor of `cb network`. diff --git a/spec/cb/config_param_spec.cr b/spec/cb/config_param_spec.cr index 50e0dc5..e55d85c 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,12 @@ 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"] ), ] } @@ -115,9 +121,9 @@ 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 EXPECTED expect(&.output).to look_like expected @@ -128,8 +134,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 +185,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 +251,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