Class: Inspec::Resources::PodmanImage

Inherits:
Object
  • Object
show all
Includes:
DockerObject, Utils::Podman
Defined in:
lib/inspec/resources/podman_image.rb

Constant Summary collapse

LABELS =
{
  "id" => "ID",
  "repo_tags" => "RepoTags",
  "size" => "Size",
  "digest" => "Digest",
  "created_at" => "Created",
  "version" => "Version",
  "names_history" => "NamesHistory",
  "repo_digests" => "RepoDigests",
  "architecture" => "Architecture",
  "os" => "Os",
  "virtual_size" => "VirtualSize",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Podman

#generate_go_template, #parse_command_output, #podman_running?

Methods included from DockerObject

#id

Constructor Details

#initialize(opts) ⇒ PodmanImage

Returns a new instance of PodmanImage.



38
39
40
41
42
43
44
45
# File 'lib/inspec/resources/podman_image.rb', line 38

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

Instance Attribute Details

#image_infoObject (readonly)

Returns the value of attribute image_info.



36
37
38
# File 'lib/inspec/resources/podman_image.rb', line 36

def image_info
  @image_info
end

#optsObject (readonly)

Returns the value of attribute opts.



36
37
38
# File 'lib/inspec/resources/podman_image.rb', line 36

def opts
  @opts
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/inspec/resources/podman_image.rb', line 68

def exist?
  ! image_info.empty?
end

#kObject

This creates all the required properties methods dynamically.



62
63
64
65
66
# File 'lib/inspec/resources/podman_image.rb', line 62

LABELS.each do |k, v|
  define_method(k) do
    image_info[k.to_s]
  end
end

#resource_idObject



72
73
74
# File 'lib/inspec/resources/podman_image.rb', line 72

def resource_id
  opts[:id] || opts[:image] || ""
end

#to_sObject



76
77
78
# File 'lib/inspec/resources/podman_image.rb', line 76

def to_s
  "podman_image #{resource_id}"
end