mirror of
https://github.com/inspec/inspec
synced 2024-11-26 14:40:26 +00:00
CFINSPEC-86: Enhance docker_image with image inspect information
Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
parent
4f691564e4
commit
fbe78d0c93
1 changed files with 23 additions and 0 deletions
|
@ -48,6 +48,23 @@ module Inspec::Resources
|
|||
object_info.tags[0] if object_info.entries.size == 1
|
||||
end
|
||||
|
||||
def [](hashkeys)
|
||||
hash_value = image_inspect_info
|
||||
keys = hashkeys.split(".")
|
||||
keys.each do |k|
|
||||
if hash_value.include?(k.to_sym)
|
||||
hash_value = hash_value[k.to_sym]
|
||||
else
|
||||
raise Inspec::Exceptions::ResourceFailed, "#{hashkeys} is not a valid key for your image, #{k} not found."
|
||||
end
|
||||
end
|
||||
hash_value
|
||||
end
|
||||
|
||||
def inspection
|
||||
image_inspect_info
|
||||
end
|
||||
|
||||
def to_s
|
||||
img = @opts[:image] || @opts[:id]
|
||||
"Docker Image #{img}"
|
||||
|
@ -80,5 +97,11 @@ module Inspec::Resources
|
|||
(repository == opts[:repo] && tag == opts[:tag]) || (!id.nil? && !opts[:id].nil? && (id == opts[:id] || id.start_with?(opts[:id])))
|
||||
end
|
||||
end
|
||||
|
||||
def image_inspect_info
|
||||
return @inspect_info if defined?(@inspect_info)
|
||||
|
||||
@inspect_info = inspec.docker.object(@opts[:image] || (!opts[:id].nil? && @opts[:id]))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue