Skip to content

Commit

Permalink
Fix config param valus being truncated.
Browse files Browse the repository at this point in the history
It was reported that the `cb config-param set` command was truncating
values that contain a `=` character. This was due to how the input line
was being parsed and tokenized. Here, we've simply limited the parsing
to the first instance of this character such that it will only ever
split the parameter name and value from the input.
  • Loading branch information
abrightwell committed May 8, 2024
1 parent 0c8b0e5 commit b1c13b7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ 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]
### Fixed
- `cb config-param set` issue truncating values with multiple `=` characters.

## [3.5.0] - 2024-01-31
### Added
Expand Down
5 changes: 4 additions & 1 deletion spec/cb/config_param_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ Spectator.describe ConfigurationParameterSet do

describe "#call" do
before_each {
action.args = ["postgres:max_connections=100"]
action.args = [
"postgres:max_connections=100",
]

action.cluster_id = cluster.id
}

Expand Down
24 changes: 12 additions & 12 deletions spec/support/factory.cr
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ module Factory
CB::Model::ClusterStatus.new **params
end

def configuration_parameter(**params)
params = {
component: "postgres",
name: "postgres:max_connections",
parameter_name: "max_connections",
requires_restart: false,
value: "100",
}.merge(params)

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

def firewall_rule(**params)
params = {
id: "shofthj3fzaipie44lt6a5i3de",
Expand Down Expand Up @@ -183,18 +195,6 @@ module Factory
CB::Model::Role.new **params
end

def configuration_parameter(**params)
params = {
component: "postgres",
name: "postgres:max_connections",
parameter_name: "max_connections",
requires_restart: false,
value: "100",
}.merge(params)

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

def role_user(**params)
params = {
account_email: "[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion src/cb/config_param.cr
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module CB
super

updated_parameters = @args.map do |arg|
parts = arg.split('=')
parts = arg.split(separator: '=', limit: 2)
{"name" => parts[0], "value" => parts[1]}
rescue IndexError
raise Error.new("Invalid argument: #{arg}). Make sure that it has the following format <component>:<name>=<value>.")
Expand Down
26 changes: 16 additions & 10 deletions src/cb/psql.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module CB
setter psql

def initialize(@client, @input = STDIN, @output = STDOUT)
@psql = ->(args : Enumerable(String), env : Process::Env) { Process.exec("psql", args, env: env) }
@psql = ->(args : Enumerable(String), env : Process::Env) { Process.exec("psql", args, env: env, shell: true) }
end

def validate
Expand Down Expand Up @@ -79,20 +79,26 @@ module CB

private def escape(str) : String
String.build do |build|
str.each_char do |char|
case char
when '\''
build << "\\'"
else
build << char
end
end
str.each_char { |char| build << char.unicode_escape }
# case char
# when '\''
# build <<
# else
# build << char
# end
# end
end
end

private def build_psqlrc(c, team_name) : String
# psqlpromptname = String.build do |s|
# s << "%[%033[33;1m%]%x%[%033[0m%]%[%033[1m%]%/%[%033[0m%]%R%# "
# end

#
psqlpromptname = String.build do |s|
s << "%[%033[32m%]#{escape(team_name.to_s)}%[%033m%]" << "/" if team_name
s << "%[%033[33;1m%]#{team_name.to_s}%[%033[0m%]" << "/" if team_name
# s << "%[%033[33;1m%]HELLO!%[%033[0m%]" << "/" if team_name
s << "%[%033[36m%]#{c.name}%[%033m%]"
end

Expand Down

0 comments on commit b1c13b7

Please sign in to comment.