Class: PodmanImage

Inherits:
Object
  • Object
show all
Includes:
PodmanObject, Utils::Podman
Defined in:
lib/inspec-podman-resources/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 PodmanObject

#id

Constructor Details

#initialize(opts) ⇒ PodmanImage

Returns a new instance of PodmanImage.

Raises:

  • (Inspec::Exceptions::ResourceFailed)


36
37
38
39
40
41
42
43
# File 'lib/inspec-podman-resources/resources/podman_image.rb', line 36

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.



34
35
36
# File 'lib/inspec-podman-resources/resources/podman_image.rb', line 34

def image_info
  @image_info
end

#optsObject (readonly)

Returns the value of attribute opts.



34
35
36
# File 'lib/inspec-podman-resources/resources/podman_image.rb', line 34

def opts
  @opts
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/inspec-podman-resources/resources/podman_image.rb', line 66

def exist?
  ! image_info.empty?
end

#kObject

This creates all the required properties methods dynamically.



60
61
62
63
64
# File 'lib/inspec-podman-resources/resources/podman_image.rb', line 60

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

#resource_idObject



70
71
72
# File 'lib/inspec-podman-resources/resources/podman_image.rb', line 70

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

#to_sObject



74
75
76
# File 'lib/inspec-podman-resources/resources/podman_image.rb', line 74

def to_s
  "podman_image #{resource_id}"
end