mirror of
https://github.com/inspec/inspec
synced 2025-02-16 22:18:38 +00:00
reimplement command resource
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
e0459c4116
commit
554accdedc
2 changed files with 29 additions and 11 deletions
|
@ -1,14 +1,32 @@
|
|||
# encoding: utf-8
|
||||
# copyright: 2015, Vulcano Security GmbH
|
||||
# encoding: utf-8
|
||||
# license: All rights reserved
|
||||
|
||||
module Serverspec::Type
|
||||
class Command < Base
|
||||
# Check if a given command (executable) exists
|
||||
# in the default path
|
||||
def exists?
|
||||
cmd = @name
|
||||
Command.new("type \"#{cmd}\" > /dev/null").exit_status == 0
|
||||
end
|
||||
class Command < Vulcano.resource(1)
|
||||
name 'command'
|
||||
def initialize(cmd)
|
||||
@command = cmd
|
||||
end
|
||||
end
|
||||
|
||||
def result
|
||||
@result ||= @vulcano.run_command(@command)
|
||||
end
|
||||
|
||||
def stdout
|
||||
result.stdout
|
||||
end
|
||||
|
||||
def stderr
|
||||
result.stderr
|
||||
end
|
||||
|
||||
def exit_status
|
||||
result.exit_status.to_i
|
||||
end
|
||||
|
||||
def exists?
|
||||
res = @vulcano.run_command("type \"#{@command}\" > /dev/null")
|
||||
res.exit_status.to_i == 0
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -40,7 +40,7 @@ module Vulcano::Backend::Mock
|
|||
end
|
||||
|
||||
class Command
|
||||
attr_reader :stdout, :stderr, :exit_code
|
||||
attr_reader :stdout, :stderr, :exit_status
|
||||
def initialize(runtime, cmd)
|
||||
@exit_code = (rand < 0.7) ? 0 : (100 * rand).to_i
|
||||
@stdout = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
|
||||
|
|
Loading…
Add table
Reference in a new issue