Class: PuppetAuditor::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_auditor/cli.rb

Constant Summary collapse

@@path =
''

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Cli

Returns a new instance of Cli.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/puppet_auditor/cli.rb', line 10

def initialize(args)
  @checks = []

  OptionParser.new do |opts|
    opts.banner = "Usage: puppet_auditor [options]"

    host_default = true
    user_default = true
    project_default = true
    specific_yaml_rules = nil
  
    opts.on("--with-rules FILE", "Supply more rules from a specific yaml file") do |file|
      specific_yaml_rules = file
    end

    opts.on("--no-host-defaults", "Do not atempt to load yaml rules from /etc/puppet_auditor.yaml") do
      host_default = false
    end

    opts.on("--no-user-defaults", "Do not atempt to load yaml rules from ~/.puppet_auditor.yaml") do
      user_default = false
    end

    opts.on("--no-project-defaults", "Do not atempt to load yaml rules from .puppet_auditor.yaml") do
      project_default = false
    end

    load_checks('/etc/puppet_auditor.yaml') if host_default
    load_checks('~/.puppet_auditor.yaml')   if user_default && ENV.key?('HOME')
    load_checks('.puppet_auditor.yaml')     if project_default
    load_checks(specific_yaml_rules)        if specific_yaml_rules

    @@path = File.expand_path('.')

  end.parse!
end

Class Method Details

.pathObject



6
7
8
# File 'lib/puppet_auditor/cli.rb', line 6

def self.path
  @@path
end

Instance Method Details

#load_checks(filepath) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/puppet_auditor/cli.rb', line 47

def load_checks(filepath)
  File.open(filepath) { |file| @checks << Loader.new(file).generate_checks } if File.readable?(filepath)
rescue PuppetAuditor::Error => err
  puts "There was an error parsing rules from #{filepath}"
  puts err.message
  exit 1
end

#run!Object



55
56
57
# File 'lib/puppet_auditor/cli.rb', line 55

def run!
  PuppetLint::Bin.new([File.expand_path('.'), "--only-checks=#{@checks.join(',')}"]).run
end