mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
9d3beb8d41
* Fixing tests and squashing * Updating as per some PR comments * PR comments Signed-off-by: Noel Georgi <18496730+frezbo@users.noreply.github.com>
63 lines
1.3 KiB
Ruby
63 lines
1.3 KiB
Ruby
# encoding: utf-8
|
|
|
|
module Inspec::Resources
|
|
class DockerPlugin < Inspec.resource(1)
|
|
name 'docker_plugin'
|
|
supports platform: 'unix'
|
|
desc 'Retrieves info about docker plugins'
|
|
example "
|
|
describe docker_plugin('rexray/ebs') do
|
|
it { should exist }
|
|
its('id') { should_not eq '0ac30b93ad40' }
|
|
its('version') { should eq '0.11.1' }
|
|
it { should be_enabled }
|
|
end
|
|
|
|
describe docker_plugin('alpine:latest') do
|
|
it { should exist }
|
|
end
|
|
|
|
describe docker_plugin(id: '4a415e366388') do
|
|
it { should exist }
|
|
end
|
|
"
|
|
|
|
def initialize(opts = {})
|
|
# do sanitizion of input values
|
|
o = opts.dup
|
|
o = { name: opts } if opts.is_a?(String)
|
|
@opts = o
|
|
end
|
|
|
|
def exist?
|
|
object_info.entries.size == 1
|
|
end
|
|
|
|
def enabled?
|
|
object_info.enabled[0]
|
|
end
|
|
|
|
def id
|
|
object_info.ids[0] if object_info.entries.size == 1
|
|
end
|
|
|
|
def version
|
|
object_info.versions[0] if object_info.entries.size == 1
|
|
end
|
|
|
|
def to_s
|
|
plugin = @opts[:name] || @opts[:id]
|
|
"Docker plugin #{plugin}"
|
|
end
|
|
|
|
private
|
|
|
|
def object_info
|
|
return @info if defined?(@info)
|
|
opts = @opts
|
|
@info = inspec.docker.plugins.where {
|
|
(name == opts[:name]) || (!id.nil? && !opts[:id].nil? && (id == opts[:id]))
|
|
}
|
|
end
|
|
end
|
|
end
|