class Inspec::Resources::DockerImage
Public Class Methods
new(opts = {})
click to toggle source
# File lib/inspec/resources/docker_image.rb, line 32 def initialize(opts = {}) # do sanitizion of input values o = opts.dup o = { image: opts } if opts.is_a?(String) @opts = sanitize_options(o) end
Public Instance Methods
image()
click to toggle source
# File lib/inspec/resources/docker_image.rb, line 39 def image "#{repo}:#{tag}" if object_info.entries.size == 1 end
repo()
click to toggle source
# File lib/inspec/resources/docker_image.rb, line 43 def repo object_info.repositories[0] if object_info.entries.size == 1 end
tag()
click to toggle source
# File lib/inspec/resources/docker_image.rb, line 47 def tag object_info.tags[0] if object_info.entries.size == 1 end
to_s()
click to toggle source
# File lib/inspec/resources/docker_image.rb, line 51 def to_s img = @opts[:image] || @opts[:id] "Docker Image #{img}" end
Private Instance Methods
object_info()
click to toggle source
# File lib/inspec/resources/docker_image.rb, line 75 def object_info return @info if defined?(@info) opts = @opts @info = inspec.docker.images.where do (repository == opts[:repo] && tag == opts[:tag]) || (!id.nil? && !opts[:id].nil? && (id == opts[:id] || id.start_with?(opts[:id]))) end end
sanitize_options(opts)
click to toggle source
# File lib/inspec/resources/docker_image.rb, line 58 def sanitize_options(opts) opts.merge!(parse_components_from_image(opts[:image])) # assume a "latest" tag if we don't have one opts[:tag] ||= "latest" # if the ID isn't nil and doesn't contain a hash indicator (indicated by the presence # of a colon, which separates the indicator from the actual hash), we assume it's sha256. opts[:id] = "sha256:" + opts[:id] unless opts[:id].nil? || opts[:id].include?(":") # Assemble/reassemble the image from the repo and tag opts[:image] = "#{opts[:repo]}:#{opts[:tag]}" unless opts[:repo].nil? # return the santized opts back to the caller opts end