mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
Merge pull request #1706 from chef/chris-rock/improve-docker-error-handling
handle json parse errors in docker resource
This commit is contained in:
commit
5f9d1980f7
1 changed files with 12 additions and 0 deletions
|
@ -109,12 +109,16 @@ module Inspec::Resources
|
|||
return @version if defined?(@version)
|
||||
data = JSON.parse(inspec.command('docker version --format \'{{ json . }}\'').stdout)
|
||||
@version = Hashie::Mash.new(data)
|
||||
rescue JSON::ParserError => _e
|
||||
return Hashie::Mash.new({})
|
||||
end
|
||||
|
||||
def info
|
||||
return @info if defined?(@info)
|
||||
data = JSON.parse(inspec.command('docker info --format \'{{ json . }}\'').stdout)
|
||||
@info = Hashie::Mash.new(data)
|
||||
rescue JSON::ParserError => _e
|
||||
return Hashie::Mash.new({})
|
||||
end
|
||||
|
||||
# returns information about docker objects
|
||||
|
@ -123,6 +127,8 @@ module Inspec::Resources
|
|||
data = JSON.parse(inspec.command("docker inspect #{id}").stdout)
|
||||
data = data[0] if data.is_a?(Array)
|
||||
@inspect = Hashie::Mash.new(data)
|
||||
rescue JSON::ParserError => _e
|
||||
return Hashie::Mash.new({})
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
@ -144,6 +150,9 @@ module Inspec::Resources
|
|||
ps.push(j)
|
||||
}
|
||||
ps
|
||||
rescue JSON::ParserError => _e
|
||||
warn 'Could not parse `docker ps` output'
|
||||
[]
|
||||
end
|
||||
|
||||
def parse_images
|
||||
|
@ -154,6 +163,9 @@ module Inspec::Resources
|
|||
c_images.push(JSON.parse(entry))
|
||||
}
|
||||
c_images
|
||||
rescue JSON::ParserError => _e
|
||||
warn 'Could not parse `docker images` output'
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue