Skip to content

Commit

Permalink
(maint) fix for connection validator
Browse files Browse the repository at this point in the history
last fix for postgres 8 ever. postgres 8 does not support the CONNECT privilege or equals signs in the command. --no-password doesn't seem to be required.  Also cleaned up conditional in the util script.
  • Loading branch information
eputnam committed Jun 12, 2017
1 parent 4dac726 commit e1cfec4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions lib/puppet/util/postgresql_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ def build_psql_cmd
final_cmd.push cmd_init

cmd_parts = {
:host => "--host=#{@resource[:host]}",
:port => "--port=#{@resource[:port]}",
:db_username => "--username=#{@resource[:db_username]}",
:db_name => "--dbname=#{@resource[:db_name]}",
:command => "--command='#{@resource[:command]}'"
:host => "--host #{@resource[:host]}",
:port => "--port #{@resource[:port]}",
:db_username => "--username #{@resource[:db_username]}",
:db_name => "--dbname #{@resource[:db_name]}",
:command => "--command '#{@resource[:command]}'"
}

cmd_parts[:db_password] = "--no-password " if @resource[:db_password]

cmd_parts.each do |k,v|
final_cmd.push v if @resource[k]
end
Expand All @@ -40,8 +38,9 @@ def parse_connect_settings
def attempt_connection(sleep_length, tries)
(0..tries-1).each do |try|
Puppet.debug "PostgresqlValidator.attempt_connection: Attempting connection to #{@resource[:db_name]}"
if execute_command =~ /1/
Puppet.debug "PostgresqlValidator.attempt_connection: Connection to #{@resource[:db_name]} successful!"
Puppet.debug "PostgresqlValidator.attempt_connection: #{build_validate_cmd}"
if execute_command.length > 0
Puppet.debug "PostgresqlValidator.attempt_connection: Connection to #{@resource[:db_name] || parse_connect_settings.select { |elem| elem.match /PGDATABASE/ }} successful!"
return true
else
Puppet.warning "PostgresqlValidator.attempt_connection: Sleeping for #{sleep_length} seconds"
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/postgresql_conn_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class { 'postgresql::server':
require => Postgresql::Server::Role['testuser']
}->
postgresql::server::database_grant { 'allow connect for testuser':
privilege => 'CONNECT',
privilege => 'ALL',
db => 'testdb',
role => 'testuser',
}
Expand Down

0 comments on commit e1cfec4

Please sign in to comment.