class Inspec::Resources::PodmanImage
def exist?
def exist? ! image_info.empty? end
def get_image_info
def get_image_info current_image = opts[:id] || opts[:image] || opts[:repo] + ":" + opts[:tag] json_key_label = generate_go_template(LABELS) podman_inspect_cmd = inspec.command("podman image inspect #{current_image} --format '{#{json_key_label}}'") if podman_inspect_cmd.exit_status == 0 parse_command_output(podman_inspect_cmd.stdout) elsif podman_inspect_cmd.stderr =~ /failed to find image/ {} else raise Inspec::Exceptions::ResourceFailed, "Unable to retrieve podman image information for #{current_image}.\nError message: #{podman_inspect_cmd.stderr}" end end
def initialize(opts)
def initialize(opts) skip_resource "The `podman_image` resource is not yet available on your OS." unless inspec.os.unix? opts = { image: opts } if opts.is_a?(String) @opts = sanitize_options(opts) raise Inspec::Exceptions::ResourceFailed, "Podman is not running. Please make sure it is installed and running." unless podman_running? @image_info = get_image_info end
def resource_id
def resource_id opts[:id] || opts[:image] || "" end
def sanitize_options(opts)
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" # Assemble/reassemble the image from the repo and tag opts[:image] = "#{opts[:repo]}:#{opts[:tag]}" unless opts[:repo].nil? opts end
def to_s
def to_s "podman_image #{resource_id}" end