Sha256: 1af67405101f1a899894672e4f9c84e777faf267bade96291e2cdbf6463fe577

Contents?: true

Size: 1.38 KB

Versions: 90

Compression:

Stored size: 1.38 KB

Contents

require "inspec/resources/docker"

module Inspec::Resources
  class DockerPlugin < Inspec.resource(1)
    name "docker_plugin"
    supports platform: "unix"
    desc "Retrieves info about docker plugins"
    example <<~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
    EXAMPLE

    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 do
        (name == opts[:name]) || (!id.nil? && !opts[:id].nil? && (id == opts[:id]))
      end
    end
  end
end

Version data entries

90 entries across 90 versions & 2 rubygems

Version Path
inspec-core-4.56.58 lib/inspec/resources/docker_plugin.rb
inspec-core-5.17.4 lib/inspec/resources/docker_plugin.rb
inspec-core-5.14.0 lib/inspec/resources/docker_plugin.rb
inspec-core-4.56.20 lib/inspec/resources/docker_plugin.rb
inspec-core-5.12.2 lib/inspec/resources/docker_plugin.rb
inspec-core-5.10.5 lib/inspec/resources/docker_plugin.rb
inspec-core-4.56.19 lib/inspec/resources/docker_plugin.rb
inspec-core-5.7.9 lib/inspec/resources/docker_plugin.rb
inspec-core-4.56.17 lib/inspec/resources/docker_plugin.rb
inspec-core-4.52.9 lib/inspec/resources/docker_plugin.rb
inspec-core-4.50.3 lib/inspec/resources/docker_plugin.rb
inspec-core-4.49.0 lib/inspec/resources/docker_plugin.rb
inspec-core-4.46.13 lib/inspec/resources/docker_plugin.rb
inspec-core-4.41.20 lib/inspec/resources/docker_plugin.rb
inspec-core-4.41.2 lib/inspec/resources/docker_plugin.rb
inspec-core-4.38.9 lib/inspec/resources/docker_plugin.rb
inspec-core-4.38.3 lib/inspec/resources/docker_plugin.rb
inspec-core-4.37.30 lib/inspec/resources/docker_plugin.rb
inspec-core-4.37.25 lib/inspec/resources/docker_plugin.rb
inspec-core-4.37.23 lib/inspec/resources/docker_plugin.rb