Class: DockerImage

Inherits:
Object
  • Object
show all
Includes:
DockerObject
Defined in:
lib/inspec-docker-resources/resources/docker_image.rb

Instance Method Summary collapse

Methods included from DockerObject

#exist?, #id

Constructor Details

#initialize(opts = {}) ⇒ DockerImage

Returns a new instance of DockerImage.



31
32
33
34
35
36
# File 'lib/inspec-docker-resources/resources/docker_image.rb', line 31

def initialize(opts = {})
  # do sanitizion of input values
  o = opts.dup
  o = { image: opts } if opts.is_a?(String)
  @opts = sanitize_options(o)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*hash_keys) ⇒ Object

method_missing handles when hash_keys are invoked to check information obtained on docker inspect [image_name]



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/inspec-docker-resources/resources/docker_image.rb', line 51

def method_missing(*hash_keys)
  # User can test the low-level inspect information in three ways:
  # Way 1: Serverspec style: its(['Config.Cmd']) { should include some_value }
  #        here, the value for hash_keys recieved is [:[], "Config.Cmd"]
  # Way 2: InSpec style: its(['Config','Cmd']) { should include some_value }
  #        here, the value for hash_keys recieved is [:[], "Config", "Cmd"]
  # Way 3: Mix of both: its(['GraphDriver.Data','MergedDir']) { should include some_value }
  #        here, the value for hash_keys recieved is [:[], "GraphDriver.Data", "MergedDir"]

  # hash_keys are passed to this method to evaluate the value
  image_hash_inspection(hash_keys)
end

Instance Method Details

#imageObject



38
39
40
# File 'lib/inspec-docker-resources/resources/docker_image.rb', line 38

def image
  "#{repo}:#{tag}" if object_info.entries.size == 1
end

#inspectionObject

inspection property allows to test any of the hash key-value pairs as part of the image_inspect_info



65
66
67
# File 'lib/inspec-docker-resources/resources/docker_image.rb', line 65

def inspection
  image_inspect_info
end

#repoObject



42
43
44
# File 'lib/inspec-docker-resources/resources/docker_image.rb', line 42

def repo
  object_info.repositories[0] if object_info.entries.size == 1
end

#resource_idObject



74
75
76
# File 'lib/inspec-docker-resources/resources/docker_image.rb', line 74

def resource_id
  object_info.ids[0] || @opts[:id] || @opts[:image] || ""
end

#tagObject



46
47
48
# File 'lib/inspec-docker-resources/resources/docker_image.rb', line 46

def tag
  object_info.tags[0] if object_info.entries.size == 1
end

#to_sObject



69
70
71
72
# File 'lib/inspec-docker-resources/resources/docker_image.rb', line 69

def to_s
  img = @opts[:image] || @opts[:id]
  "Docker Image #{img}"
end