Class: Inspec::Resources::Docker

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/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



132
133
134
# File 'lib/inspec/resources/docker.rb', line 132

def containers
  DockerContainerFilter.new(parse_containers)
end

#imagesObject



136
137
138
# File 'lib/inspec/resources/docker.rb', line 136

def images
  DockerImageFilter.new(parse_images)
end

#infoObject



159
160
161
162
163
164
165
166
167
168
169
# File 'lib/inspec/resources/docker.rb', line 159

def info
  return @info if defined?(@info)

  data = {}
  # docke info format is only supported for Docker 17.03+
  cmd = inspec.command("docker info --format '{{ json . }}'")
  data = JSON.parse(cmd.stdout) if cmd.exit_status == 0
  @info = Hashie::Mash.new(data)
rescue JSON::ParserError => _e
  Hashie::Mash.new({})
end

#object(id) ⇒ Object

returns information about docker objects



172
173
174
175
176
177
178
179
180
# File 'lib/inspec/resources/docker.rb', line 172

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
  Hashie::Mash.new({})
end

#pluginsObject



140
141
142
# File 'lib/inspec/resources/docker.rb', line 140

def plugins
  DockerPluginFilter.new(parse_plugins)
end

#servicesObject



144
145
146
# File 'lib/inspec/resources/docker.rb', line 144

def services
  DockerServiceFilter.new(parse_services)
end

#to_sObject



182
183
184
# File 'lib/inspec/resources/docker.rb', line 182

def to_s
  "Docker Host"
end

#versionObject



148
149
150
151
152
153
154
155
156
157
# File 'lib/inspec/resources/docker.rb', line 148

def version
  return @version if defined?(@version)

  data = {}
  cmd = inspec.command("docker version --format '{{ json . }}'")
  data = JSON.parse(cmd.stdout) if cmd.exit_status == 0
  @version = Hashie::Mash.new(data)
rescue JSON::ParserError => _e
  Hashie::Mash.new({})
end