mirror of
https://github.com/inspec/inspec
synced 2024-11-14 00:47:10 +00:00
Fixed command for windows and replaced warn with Inspec::Log.warn
Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
This commit is contained in:
parent
180ebf0590
commit
471b7b4550
1 changed files with 21 additions and 23 deletions
|
@ -55,7 +55,7 @@ module Inspec::Resources
|
|||
@version = version_from_psql
|
||||
if @version.to_s.empty?
|
||||
if inspec.directory("/var/lib/pgsql/data").exist?
|
||||
warn "Unable to determine PostgreSQL version: psql did not return" \
|
||||
Inspec::Log.warn "Unable to determine PostgreSQL version: psql did not return" \
|
||||
"a version number and unversioned data directories were found."
|
||||
else
|
||||
@version = version_from_dir("/var/lib/pgsql")
|
||||
|
@ -77,13 +77,13 @@ module Inspec::Resources
|
|||
|
||||
def verify_dirs
|
||||
unless inspec.directory(@conf_dir).exist?
|
||||
warn "Default postgresql configuration directory: #{@conf_dir} does not exist. " \
|
||||
Inspec::Log.warn "Default postgresql configuration directory: #{@conf_dir} does not exist. " \
|
||||
"Postgresql may not be installed or we've misidentified the configuration " \
|
||||
"directory."
|
||||
end
|
||||
|
||||
unless inspec.directory(@data_dir).exist?
|
||||
warn "Default postgresql data directory: #{@data_dir} does not exist. " \
|
||||
Inspec::Log.warn "Default postgresql data directory: #{@data_dir} does not exist. " \
|
||||
"Postgresql may not be installed or we've misidentified the data " \
|
||||
"directory."
|
||||
end
|
||||
|
@ -92,16 +92,14 @@ module Inspec::Resources
|
|||
def version_from_psql
|
||||
return unless inspec.command("psql").exist?
|
||||
|
||||
if inspec.os.windows?
|
||||
version = inspec.command("psql --version | awk '{ print $NF }'").stdout.strip.split(".")
|
||||
else
|
||||
version = inspec.command("psql --version | awk '{ print $NF }' | awk -F. '{ print $1\".\"$2 }'").stdout.strip.split(".")
|
||||
end
|
||||
version = inspec.command("psql --version").stdout.strip.split(" ")[2].split(".")
|
||||
|
||||
if version.first.to_i >= 10
|
||||
version.first
|
||||
else
|
||||
"#{version[0]}.#{version[1]}"
|
||||
unless version.empty?
|
||||
if version.first.to_i >= 10
|
||||
version.first
|
||||
else
|
||||
"#{version[0]}.#{version[1]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -118,7 +116,7 @@ module Inspec::Resources
|
|||
data_dir_loc = dir_list.detect { |i| inspec.directory(i).exist? }
|
||||
|
||||
if data_dir_loc.nil?
|
||||
warn 'Unable to find the PostgreSQL data_dir in expected location(s), please
|
||||
Inspec::Log.warn 'Unable to find the PostgreSQL data_dir in expected location(s), please
|
||||
execute "psql -t -A -p <port> -h <host> -c "show hba_file";" as the PostgreSQL
|
||||
DBA to find the non-standard data_dir location.'
|
||||
end
|
||||
|
@ -130,15 +128,15 @@ module Inspec::Resources
|
|||
entries = dirs.lines.count
|
||||
case entries
|
||||
when 0
|
||||
warn "Could not determine version of installed postgresql by inspecting #{dir}"
|
||||
Inspec::Log.warn "Could not determine version of installed postgresql by inspecting #{dir}"
|
||||
nil
|
||||
when 1
|
||||
warn "Using #{dirs}: #{dir_to_version(dirs)}"
|
||||
Inspec::Log.warn "Using #{dirs}: #{dir_to_version(dirs)}"
|
||||
dir_to_version(dirs)
|
||||
else
|
||||
warn "Multiple versions of postgresql installed or incorrect base dir #{dir}"
|
||||
Inspec::Log.warn "Multiple versions of postgresql installed or incorrect base dir #{dir}"
|
||||
first = dir_to_version(dirs.lines.first)
|
||||
warn "Using the first version found: #{first}"
|
||||
Inspec::Log.warn "Using the first version found: #{first}"
|
||||
first
|
||||
end
|
||||
end
|
||||
|
@ -148,14 +146,14 @@ module Inspec::Resources
|
|||
entries = dirs.lines.count
|
||||
case entries
|
||||
when 0
|
||||
warn "Could not determine version of installed PostgreSQL by inspecting #{dir}"
|
||||
Inspec::Log.warn "Could not determine version of installed PostgreSQL by inspecting #{dir}"
|
||||
nil
|
||||
when 1
|
||||
dir_to_version(dirs)
|
||||
else
|
||||
warn "Multiple versions of PostgreSQL installed or incorrect base dir #{dir}"
|
||||
Inspec::Log.warn "Multiple versions of PostgreSQL installed or incorrect base dir #{dir}"
|
||||
first = dir_to_version(dirs.lines.first)
|
||||
warn "Using the first version found: #{first}"
|
||||
Inspec::Log.warn "Using the first version found: #{first}"
|
||||
first
|
||||
end
|
||||
end
|
||||
|
@ -172,13 +170,13 @@ module Inspec::Resources
|
|||
else
|
||||
dirs = inspec.command("ls -d #{dir}/*/").stdout.lines
|
||||
if dirs.empty?
|
||||
warn "No postgresql clusters configured or incorrect base dir #{dir}"
|
||||
Inspec::Log.warn "No postgresql clusters configured or incorrect base dir #{dir}"
|
||||
return nil
|
||||
end
|
||||
first = dirs.first.chomp.split("/").last
|
||||
if dirs.count > 1
|
||||
warn "Multiple postgresql clusters configured or incorrect base dir #{dir}"
|
||||
warn "Using the first directory found: #{first}"
|
||||
Inspec::Log.warn "Multiple postgresql clusters configured or incorrect base dir #{dir}"
|
||||
Inspec::Log.warn "Using the first directory found: #{first}"
|
||||
end
|
||||
first
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue