Class: Inspec::Resources::Yum

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/yum.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object

alias for yum.repo(‘reponame’)



88
89
90
# File 'lib/inspec/resources/yum.rb', line 88

def method_missing(name)
  repo(name.to_s) unless name.nil?
end

Instance Method Details

#repo(repo) ⇒ Object



83
84
85
# File 'lib/inspec/resources/yum.rb', line 83

def repo(repo)
  YumRepo.new(self, repo)
end

#reposObject



79
80
81
# File 'lib/inspec/resources/yum.rb', line 79

def repos
  repositories.map { |repo| repo["id"] }
end

#repositoriesObject

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

parse data in hashmap
store data in object

until n



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 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

#resource_idObject



92
93
94
# File 'lib/inspec/resources/yum.rb', line 92

def resource_id
  "Yum repository"
end

#to_sObject



96
97
98
# File 'lib/inspec/resources/yum.rb', line 96

def to_s
  "Yum Repository"
end