mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
File existence check and other null checks
Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
parent
cb31cefaa2
commit
f3633aa096
3 changed files with 23 additions and 10 deletions
|
@ -20,7 +20,7 @@ This resource is distributed along with Chef InSpec itself. You can use it autom
|
|||
### Requirements
|
||||
|
||||
- You must have sufficient permission to access listener settings defined in `listener.ora` file.
|
||||
- Value for environment variable `$ORACLE_HOME` should be set in the system.
|
||||
- Value for environment variable `ORACLE_HOME` should be set in the system.
|
||||
|
||||
## Syntax
|
||||
|
||||
|
|
|
@ -26,24 +26,37 @@ module Inspec::Resources
|
|||
private
|
||||
|
||||
def determine_conf_dir_and_path_in_linux
|
||||
oracle_home = inspec.command("echo $ORACLE_HOME").stdout&.chomp
|
||||
if oracle_home.empty?
|
||||
warn "No oracle listener settings found in $ORACLE_HOME/network/admin directory"
|
||||
oracle_home = inspec.command("echo $ORACLE_HOME").stdout.lines.first&.chomp
|
||||
if oracle_home.nil? || oracle_home.empty?
|
||||
warn "$ORACLE_HOME env value not set in the system"
|
||||
nil
|
||||
else
|
||||
@conf_path = oracle_home + "/network/admin/listener.ora"
|
||||
conf_path = "#{oracle_home}/network/admin/listener.ora"
|
||||
if !inspec.file(conf_path).exist?
|
||||
warn "No oracle listener settings found in $ORACLE_HOME/network/admin directory"
|
||||
nil
|
||||
else
|
||||
@conf_path = conf_path
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
fail_resource "Errors reading listener settings: #{e}"
|
||||
end
|
||||
|
||||
def determine_conf_dir_and_path_in_windows
|
||||
oracle_home = inspec.powershell("echo $Env:ORACLE_HOME").stdout&.chomp
|
||||
if oracle_home.empty?
|
||||
warn "No oracle listener settings found in $ORACLE_HOME\\network\\admin directory"
|
||||
oracle_home = inspec.powershell("$Env:ORACLE_HOME").stdout.lines.first&.chomp
|
||||
|
||||
if oracle_home.nil? || oracle_home.empty?
|
||||
warn "ORACLE_HOME env value not set in the system"
|
||||
nil
|
||||
else
|
||||
@conf_path = oracle_home + "\\network\\admin\\listener.ora"
|
||||
conf_path = "#{oracle_home}\\network\\admin\\listener.ora"
|
||||
if !inspec.file(conf_path).exist?
|
||||
warn "No oracle listener settings found in ORACLE_HOME\\network\\admin directory"
|
||||
nil
|
||||
else
|
||||
@conf_path = conf_path
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
fail_resource "Errors reading listener settings: #{e}"
|
||||
|
|
|
@ -486,7 +486,7 @@ class MockLoader
|
|||
"sh -c 'type \"sqlplus\"'" => cmd.call("oracle-cmd"),
|
||||
"1998da5bc0f09bd5258fad51f45447556572b747f631661831d6fcb49269a448" => cmd.call("oracle-result"),
|
||||
"echo $ORACLE_HOME" => cmd.call("fetch-oracle-listener-in-linux"),
|
||||
"echo $Env:ORACLE_HOME" => cmd.call("fetch-oracle-listener-in-windows"),
|
||||
"$Env:ORACLE_HOME" => cmd.call("fetch-oracle-listener-in-windows"),
|
||||
# nginx mock cmd
|
||||
%{nginx -V 2>&1} => cmd.call("nginx-v"),
|
||||
%{/usr/sbin/nginx -V 2>&1} => cmd.call("nginx-v"),
|
||||
|
|
Loading…
Reference in a new issue