+ $psql_path = $postgresql::params::psql_path
+ $module_workdir = $postgresql::params::module_workdir
+ $validcon_script_path = $postgresql::client::validcon_script_path
+
+ $cmd_init = "${psql_path} --tuples-only --quiet "
+ $cmd_host = $database_host ? {
+ undef => '',
+ default => "-h ${database_host} ",
+ }
+ $cmd_user = $database_username ? {
+ undef => '',
+ default => "-U ${database_username} ",
+ }
+ $cmd_port = $database_port ? {
+ undef => '',
+ default => "-p ${database_port} ",
+ }
+ $cmd_dbname = $database_name ? {
+ undef => "--dbname ${postgresql::params::default_database} ",
+ default => "--dbname ${database_name} ",
+ }
+ $pass_env = $database_password ? {
+ undef => undef,
+ default => "PGPASSWORD=${database_password}",
+ }
+ $cmd = join([$cmd_init, $cmd_host, $cmd_user, $cmd_port, $cmd_dbname], ' ')
+ $validate_cmd = "${validcon_script_path} ${sleep} ${tries} '${cmd}'"
+
+ # This is more of a safety valve, we add a little extra to compensate for the
+ # time it takes to run each psql command.
+ $timeout = (($sleep + 2) * $tries)
+
+ # Combine $database_password and $connect_settings into an array of environment
+ # variables, ensure $database_password is last, allowing it to override a password
+ # from the $connect_settings hash
+ if $connect_settings != undef {
+ if $pass_env != undef {
+ $env = concat(join_keys_to_values( $connect_settings, '='), $pass_env)
+ } else {
+ $env = join_keys_to_values( $connect_settings, '=')
+ }
+ } else {
+ $env = $pass_env
+ }
+
+ $exec_name = "validate postgres connection for ${database_username}@${database_host}:${database_port}/${database_name}"