Class: Inspec::Resources::Docker

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/docker.rb

Overview

This resource helps to parse information from the docker host For compatability with Serverspec we also offer the following resouses:

  • docker_container

  • docker_image

Instance Method Summary collapse

Instance Method Details

#containersObject



100
101
102
# File 'lib/resources/docker.rb', line 100

def containers
  DockerContainerFilter.new(parse_containers)
end

#imagesObject



104
105
106
# File 'lib/resources/docker.rb', line 104

def images
  DockerImageFilter.new(parse_images)
end

#infoObject



116
117
118
119
120
121
122
# File 'lib/resources/docker.rb', line 116

def info
  return @info if defined?(@info)
  data = JSON.parse(inspec.command('docker info --format \'{{ json . }}\'').stdout)
  @info = Hashie::Mash.new(data)
rescue JSON::ParserError => _e
  return Hashie::Mash.new({})
end

#object(id) ⇒ Object

returns information about docker objects



125
126
127
128
129
130
131
132
# File 'lib/resources/docker.rb', line 125

def object(id)
  return @inspect if defined?(@inspect)
  data = JSON.parse(inspec.command("docker inspect #{id}").stdout)
  data = data[0] if data.is_a?(Array)
  @inspect = Hashie::Mash.new(data)
rescue JSON::ParserError => _e
  return Hashie::Mash.new({})
end

#to_sObject



134
135
136
# File 'lib/resources/docker.rb', line 134

def to_s
  'Docker Host'
end

#versionObject



108
109
110
111
112
113
114
# File 'lib/resources/docker.rb', line 108

def version
  return @version if defined?(@version)
  data = JSON.parse(inspec.command('docker version --format \'{{ json . }}\'').stdout)
  @version = Hashie::Mash.new(data)
rescue JSON::ParserError => _e
  return Hashie::Mash.new({})
end