Skip to content

Commit c829232

Browse files
committed
Display constraints for configuration parameters
1 parent a05c5da commit c829232

File tree

5 files changed

+51
-10
lines changed

5 files changed

+51
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- `cb config-param list-supported` now returns `min_value`, `max_value`, and
10+
`enum` constraints for each parameters, if applicable.
811

912
## [3.6.0] - 2024-07-26
1013
### Added

spec/cb/config_param_spec.cr

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ Spectator.describe ConfigurationParameterGet do
7676
"parameters": [
7777
{
7878
"component": "postgres",
79+
"enum": [],
80+
"min_value": "100",
81+
"max_value": "2000",
7982
"name": "postgres:max_connections",
8083
"parameter_name": "max_connections",
8184
"requires_restart": false,
@@ -104,9 +107,21 @@ Spectator.describe ConfigurationParameterListSupported do
104107
Factory.configuration_parameter(value: nil),
105108
Factory.configuration_parameter(
106109
component: "pgbouncer",
107-
name: "pgbouncer:default_pool_size",
108-
parameter_name: "default_pool_size",
109-
value: nil
110+
name: "pgbouncer:auth_type",
111+
parameter_name: "auth_type",
112+
value: nil,
113+
min_value: nil,
114+
max_value: nil,
115+
enum: ["cert", "md5", "trust"]
116+
),
117+
Factory.configuration_parameter(
118+
component: "pgbouncer",
119+
name: "pgbouncer:fake",
120+
parameter_name: "fake",
121+
value: nil,
122+
min_value: nil,
123+
max_value: nil,
124+
enum: [] of String
110125
),
111126
]
112127
}
@@ -115,9 +130,10 @@ Spectator.describe ConfigurationParameterListSupported do
115130
action.call
116131

117132
expected = <<-EXPECTED
118-
Component Name Requires Restart
119-
postgres max_connections no
120-
pgbouncer default_pool_size no
133+
Component Name Requires Restart Constraints
134+
postgres max_connections no min: 100, max: 2000
135+
pgbouncer auth_type no enum: cert, md5, trust
136+
pgbouncer fake no
121137
EXPECTED
122138

123139
expect(&.output).to look_like expected
@@ -128,8 +144,8 @@ Spectator.describe ConfigurationParameterListSupported do
128144
action.call
129145

130146
expected = <<-EXPECTED
131-
Component Name Requires Restart
132-
postgres max_connections no
147+
Component Name Requires Restart Constraints
148+
postgres max_connections no min: 100, max: 2000
133149
EXPECTED
134150

135151
expect(&.output).to look_like expected
@@ -179,6 +195,9 @@ Spectator.describe ConfigurationParameterSet do
179195
"parameters": [
180196
{
181197
"component": "postgres",
198+
"enum": [],
199+
"min_value": "100",
200+
"max_value": "2000",
182201
"name": "postgres:max_connections",
183202
"parameter_name": "max_connections",
184203
"requires_restart": false,
@@ -242,6 +261,9 @@ Spectator.describe ConfigurationParameterReset do
242261
"parameters": [
243262
{
244263
"component": "postgres",
264+
"enum": [],
265+
"min_value": "100",
266+
"max_value": "2000",
245267
"name": "postgres:max_connections",
246268
"parameter_name": "max_connections",
247269
"requires_restart": false,

spec/support/factory.cr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ module Factory
109109
parameter_name: "max_connections",
110110
requires_restart: false,
111111
value: "100",
112+
enum: [] of String,
113+
min_value: "100",
114+
max_value: "2000",
112115
}.merge(params)
113116

114117
CB::Model::ConfigurationParameter.new **params

src/cb/config_param.cr

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,19 @@ module CB
9393
add "Component"
9494
add "Name"
9595
add "Requires Restart"
96+
add "Constraints"
9697
end
9798

9899
header unless no_header
99100

100-
rows parameters.map { |p| [p.component, p.parameter_name, p.requires_restart ? "yes" : "no"] }
101+
rows parameters.map { |p|
102+
constraints = [] of String
103+
constraints << "enum: #{p.enum.join(", ")}" if p.enum.size > 0
104+
constraints << "min: #{p.min_value}" if p.min_value && p.min_value != ""
105+
constraints << "max: #{p.max_value}" if p.max_value && p.max_value != ""
106+
107+
[p.component, p.parameter_name, p.requires_restart ? "yes" : "no", constraints.join(", ")]
108+
}
101109
end
102110

103111
output << table.render << '\n'
@@ -106,6 +114,9 @@ module CB
106114
"parameters": parameters.map do |p|
107115
{
108116
"component": p.component,
117+
"enum": p.enum,
118+
"min_value": p.min_value,
119+
"max_value": p.max_value,
109120
"name": p.name,
110121
"parameter_name": p.parameter_name,
111122
"require_restart": p.requires_restart,

src/models/config_param.cr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
module CB::Model
22
jrecord ConfigurationParameter,
33
component : String? = nil,
4+
enum : Array(String) = [] of String,
5+
min_value : String? = nil,
6+
max_value : String? = nil,
47
name : String = "",
58
parameter_name : String? = nil,
69
requires_restart : Bool = false,
710
value : String? = nil do
8-
@[JSON::Field(key: "parameter_name", emit_null: false)]
911
def to_s(io : IO)
1012
io << name.colorize.t_name << '=' << value
1113
end

0 commit comments

Comments
 (0)