class Quayio::Scanner::Image

Constants

QUAY_IO_REPO_NAME
RELEVANT_SEVERITIES

Attributes

name[R]
repository[R]
whitelist[R]

Public Class Methods

new(name, quayio_token, whitelist) click to toggle source
# File lib/quayio/scanner/image.rb, line 9
def initialize(name, quayio_token, whitelist)
  @name = name
  @whitelist = whitelist

  @name.match(QUAY_IO_REPO_NAME) do |r|
    org, repo, tag = r.captures
    @repository = Repository.new(quayio_token, org, repo, tag)
  end
end

Public Instance Methods

vulnerable?() click to toggle source
# File lib/quayio/scanner/image.rb, line 19
def vulnerable?
  quayio? && scanned? && vulnerabilities_present?
end

Private Instance Methods

quayio?() click to toggle source
# File lib/quayio/scanner/image.rb, line 25
def quayio?
  # safe guard, do not trust QUAY_IO_REPO_NAME regex match
  !!name.match(%r{^quay.io\/})
end
raw_scan() click to toggle source
# File lib/quayio/scanner/image.rb, line 42
def raw_scan
  @raw_scan ||= repository.scan
end
scanned?() click to toggle source
# File lib/quayio/scanner/image.rb, line 30
def scanned?
  raw_scan['status'] == 'scanned'
end
vulnerabilities_present?() click to toggle source
# File lib/quayio/scanner/image.rb, line 34
def vulnerabilities_present?
  !!raw_scan['data']['Layer']['Features'].detect do |f|
    f['Vulnerabilities']&.detect do |v|
      RELEVANT_SEVERITIES.include?(v['Severity']) && !whitelist.include?(v['Name'])
    end
  end
end