• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hercules-team / augeasproviders_syslog / 62

pending completion
62

push

travis-ci-com

raphink
chore: remove FUNDING

87 of 219 relevant lines covered (39.73%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.46
/lib/puppet/provider/syslog/augeas.rb
1
# coding: utf-8
2
# Alternative Augeas-based providers for Puppet
3
#
4
# Copyright (c) 2012 Raphaƫl Pinson
5
# Licensed under the Apache License, Version 2.0
6

7
raise("Missing augeasproviders_core dependency") if Puppet::Type.type(:augeasprovider).nil?
1✔
8
Puppet::Type.type(:syslog).provide(:augeas, :parent => Puppet::Type.type(:augeasprovider).provider(:default)) do
1✔
9
  desc "Uses Augeas API to update a syslog.conf entry"
1✔
10

11
  default_file { '/etc/syslog.conf' }
1✔
12

13
  lens do |resource|
1✔
14
    if resource and resource[:lens]
×
15
      resource[:lens]
×
16
    else
17
      'Syslog.lns'
×
18
    end
19
  end
20

21
  confine :feature => :augeas
1✔
22

23
  resource_path do |resource|
1✔
24
    entry_path(resource)
×
25
  end
26

27
  def protocol_supported
1✔
28
    return @protocol_supported unless @protocol_supported.nil?
×
29
    if Puppet::Util::Package.versioncmp(aug_version, '1.2.0') >= 0
×
30
      @protocol_supported = :stock
×
31
    else
32
      if parsed_as?("*.* @syslog.far.away:123\n", 'entry/action/protocol')
×
33
        @protocol_supported = :stock
×
34
      elsif parsed_as?("*.* @@syslog.far.away:123\n", 'entry/action/protocol')
×
35
        @protocol_supported = :el7
×
36
      else
37
        @protocol_supported = false
×
38
      end
39
    end
40
  end
41

42
  # We need to define an entry_path method
43
  # so the rsyslog provider can use it
44
  def self.entry_path(resource)
1✔
45
    facility = resource[:facility]
×
46
    level = resource[:level]
×
47
    action_type = resource[:action_type]
×
48
    action = resource[:action]
×
49

50
    # TODO: make it case-insensitive
51
    "$target/entry[selector/facility='#{facility}' and selector/level='#{level}' and action/#{action_type}='#{action}']"
×
52
  end
53

54
  def self.instances
1✔
55
    augopen do |aug|
×
56
      resources = []
×
57

58
      aug.match("$target/entry").each do |apath|
×
59
        aug.match("#{apath}/selector").each do |snode|
×
60
          aug.match("#{snode}/facility").each do |fnode|
×
61
            facility = aug.get(fnode) 
×
62
            level = aug.get("#{snode}/level")
×
63
            no_sync = aug.match("#{apath}/action/no_sync").empty? ? :false : :true
×
64
            action_type_node = aug.match("#{apath}/action/*[label() != 'no_sync']")
×
65
            action_type = path_label(aug, action_type_node[0])
×
66
            action_port = aug.get("#{apath}/action/port")
×
67
            action_protocol = aug.get("#{apath}/action/protocol")
×
68
            action = aug.get("#{apath}/action/#{action_type}")
×
69
            name = "#{facility}.#{level} "
×
70
            name += "-" if no_sync == :true
×
71
            name += action_protocol if action_type == "hostname"
×
72
            name += "#{action}"
×
73
            entry = {:ensure => :present, :name => name,
×
74
                     :facility => facility, :level => level,
75
                     :no_sync => no_sync,
76
                     :action_type => action_type,
77
                     :action_port => action_port,
78
                     :action_protocol => action_protocol,
79
                     :action => action}
80
            resources << new(entry)
×
81
          end
82
        end
83
      end
84

85
      resources
×
86
    end
87
  end
88

89
  def create 
1✔
90
    facility = resource[:facility]
×
91
    level = resource[:level]
×
92
    no_sync = resource[:no_sync]
×
93
    action_type = resource[:action_type]
×
94
    action_port = resource[:action_port]
×
95
    action_protocol = resource[:action_protocol]
×
96
    action = resource[:action]
×
97
    augopen! do |aug|
×
98
      # TODO: make it case-insensitive
99
      aug.defnode('resource', resource_path, nil)
×
100
      aug.set('$resource/selector/facility', facility)
×
101
      aug.set('$resource/selector/level', level)
×
102
      if no_sync == :true and action_type == 'file'
×
103
        aug.clear('$resource/action/no_sync')
×
104
      end
105
      if action_protocol
×
106
        case protocol_supported
×
107
          when :stock
108
            aug.set('$resource/action/protocol', action_protocol)
×
109
          when :el7
110
            aug.set('$resource/action/protocol', action_protocol) if action_protocol == '@@'
×
111
          else
112
            raise(Puppet::Error, 'Protocol is not supported in this lens')
×
113
        end
114
      end
115
      aug.set("$resource/action/#{action_type}", action)
×
116
      aug.set('$resource/action/port', action_port) if action_port
×
117
    end
118
  end
119

120
  def no_sync
1✔
121
    augopen do |aug|
×
122
      if aug.match('$resource/action/no_sync').empty?
×
123
        :false
×
124
      else
125
        :true
×
126
      end
127
    end
128
  end
129

130
  def no_sync=(no_sync)
1✔
131
    augopen! do |aug|
×
132
      if no_sync == :true
×
133
        if aug.match('$resource/action/no_sync').empty?
×
134
          # Insert a no_sync node before the action/file node
135
          aug.insert('$resource/action/file', "no_sync", true)
×
136
        end
137
      else
138
        # Remove the no_sync tag
139
        aug.rm('$resource/action/no_sync')
×
140
      end
141
    end
142
  end
143
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc