mirror of
https://github.com/inspec/inspec
synced 2024-11-23 21:23:29 +00:00
Merge pull request #237 from chef/osenv
api: don't force root on os_env
This commit is contained in:
commit
6b2d4e2306
4 changed files with 26 additions and 7 deletions
|
@ -11,15 +11,16 @@
|
|||
# its(:split) { should_not include('.') }
|
||||
# end
|
||||
|
||||
require 'utils/simpleconfig'
|
||||
|
||||
class OsEnv < Inspec.resource(1)
|
||||
name 'os_env'
|
||||
|
||||
attr_reader :content
|
||||
def initialize(env)
|
||||
def initialize(env = nil)
|
||||
@osenv = env
|
||||
cmd = inspec.command("su - root -c 'echo $#{env}'")
|
||||
@content = cmd.stdout.chomp
|
||||
@content = nil if cmd.exit_status != 0
|
||||
@content = nil
|
||||
@content = params[env] unless env.nil?
|
||||
end
|
||||
|
||||
def split
|
||||
|
@ -29,6 +30,24 @@ class OsEnv < Inspec.resource(1)
|
|||
end
|
||||
|
||||
def to_s
|
||||
"Environment Variable #{@osenv}"
|
||||
if @osenv.nil?
|
||||
'Environment variables'
|
||||
else
|
||||
"Environment variable #{@osenv}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def params
|
||||
return @params if defined? @params
|
||||
out = inspec.command('env')
|
||||
out = inspec.command('printenv') unless out.exit_status == 0
|
||||
unless out.exit_status == 0
|
||||
skip_resource "Can't read environment variables on #{os[:family]}. "\
|
||||
"Tried `env` and `printenv` which returned #{out.exit_status}"
|
||||
end
|
||||
|
||||
@params = SimpleConfig.new(out.stdout).params
|
||||
end
|
||||
end
|
||||
|
|
|
@ -108,7 +108,7 @@ class MockLoader
|
|||
'type win_secpol.cfg' => cmd.call('secedit-export'),
|
||||
'secedit /export /cfg win_secpol.cfg' => cmd.call('success'),
|
||||
'del win_secpol.cfg' => cmd.call('success'),
|
||||
'su - root -c \'echo $PATH\'' => cmd.call('PATH'),
|
||||
'env' => cmd.call('env'),
|
||||
'(Get-Item \'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule\').GetValue(\'Start\')' => cmd.call('reg_schedule'),
|
||||
'Auditpol /get /subcategory:\'User Account Management\' /r' => cmd.call('auditpol'),
|
||||
'/sbin/auditctl -l' => cmd.call('auditctl'),
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
1
test/unit/mock/cmd/env
Normal file
1
test/unit/mock/cmd/env
Normal file
|
@ -0,0 +1 @@
|
|||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
Loading…
Reference in a new issue