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



118
119
120
121
122
123
124
125
126
127
# File 'lib/resources/docker.rb', line 118

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

#object(id) ⇒ Object

returns information about docker objects



130
131
132
133
134
135
136
137
# File 'lib/resources/docker.rb', line 130

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



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

def to_s
  'Docker Host'
end

#versionObject



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

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