class Inspec::Resources::DockerContainer

Public Class Methods

new(opts = {}) click to toggle source
# File lib/inspec/resources/docker_container.rb, line 33
def initialize(opts = {})
  # if a string is provided, we expect it is the name
  if opts.is_a?(String)
    @opts = { name: opts }
  else
    @opts = opts
  end
end

Public Instance Methods

command() click to toggle source
# File lib/inspec/resources/docker_container.rb, line 58
def command
  return unless object_info.entries.length == 1

  cmd = object_info.commands[0]
  cmd.slice(1, cmd.length - 2)
end
image() click to toggle source
# File lib/inspec/resources/docker_container.rb, line 65
def image
  object_info.images[0] if object_info.entries.length == 1
end
labels() click to toggle source
# File lib/inspec/resources/docker_container.rb, line 50
def labels
  object_info.labels
end
ports() click to toggle source
# File lib/inspec/resources/docker_container.rb, line 54
def ports
  object_info.ports[0] if object_info.entries.length == 1
end
repo() click to toggle source
# File lib/inspec/resources/docker_container.rb, line 69
def repo
  parse_components_from_image(image)[:repo] if object_info.entries.size == 1
end
running?() click to toggle source
# File lib/inspec/resources/docker_container.rb, line 42
def running?
  status.downcase.start_with?("up") if object_info.entries.length == 1
end
status() click to toggle source
# File lib/inspec/resources/docker_container.rb, line 46
def status
  object_info.status[0] if object_info.entries.length == 1
end
tag() click to toggle source
# File lib/inspec/resources/docker_container.rb, line 73
def tag
  parse_components_from_image(image)[:tag] if object_info.entries.size == 1
end
to_s() click to toggle source
# File lib/inspec/resources/docker_container.rb, line 77
def to_s
  name = @opts[:name] || @opts[:id]
  "Docker Container #{name}"
end

Private Instance Methods

object_info() click to toggle source
# File lib/inspec/resources/docker_container.rb, line 84
def object_info
  return @info if defined?(@info)

  opts = @opts
  @info = inspec.docker.containers.where { names == opts[:name] || (!id.nil? && !opts[:id].nil? && (id == opts[:id] || id.start_with?(opts[:id]))) }
end