class Inspec::Resources::Yum

Public Instance Methods

method_missing(name) click to toggle source

alias for yum.repo('reponame')

# File lib/inspec/resources/yum.rb, line 88
def method_missing(name)
  repo(name.to_s) unless name.nil?
end
repo(repo) click to toggle source
# File lib/inspec/resources/yum.rb, line 83
def repo(repo)
  YumRepo.new(self, repo)
end
repos() click to toggle source
# File lib/inspec/resources/yum.rb, line 79
def repos
  repositories.map { |repo| repo["id"] }
end
repositories() click to toggle source

returns all repositories works as following: search for Repo-id

parse data in hashmap
store data in object

until n

# File lib/inspec/resources/yum.rb, line 48
def repositories
  return @cache if defined?(@cache)

  # parse the repository data from yum
  # we cannot use -C, because this is not reliable and may lead to errors
  @command_result = inspec.command("yum -v repolist all")
  @content = @command_result.stdout
  @cache = []
  repo = {}
  in_repo = false
  @content.each_line do |line|
    # detect repo start
    in_repo = true if line =~ /^\s*Repo-id\s*:\s*(.*)\b/
    # detect repo end
    if (line == "\n" || line =~ /\s*Total packages:/) && in_repo
      in_repo = false
      @cache.push(repo)
      repo = {}
    end
    # parse repo content
    if in_repo == true
      val = /^\s*([^:]*?)\s*:\s*(.*?)\s*$/.match(line)
      repo[repo_key(strip(val[1]))] = strip(val[2])
    end
  end

  @cache.push(repo) if in_repo

  @cache
end
to_s() click to toggle source
# File lib/inspec/resources/yum.rb, line 92
def to_s
  "Yum Repository"
end

Private Instance Methods

repo_key(key) click to toggle source

Optimize the key value

# File lib/inspec/resources/yum.rb, line 104
def repo_key(key)
  return key if key.nil?

  key.gsub("Repo-", "").downcase
end
strip(value) click to toggle source

Removes lefthand and righthand whitespace

# File lib/inspec/resources/yum.rb, line 99
def strip(value)
  value&.strip
end