Skip to content

Commit 54ece81

Browse files
committed
Allow redirecting of settings into custom contexts
Add a new resource parameter that allows redirection of settings into contexts other than system/local. In prarticular this allows to customize (and even create) apps with context => "apps/<app>/{default,local}". Incidentally this centralises redundant occurences of system/local as the parameter default.
1 parent a2a0075 commit 54ece81

File tree

20 files changed

+48
-36
lines changed

20 files changed

+48
-36
lines changed

lib/puppet/provider/ini_setting/splunk.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class << self
1414
def self.file_path
1515
raise Puppet::Error, 'file_path must be set with splunk_config type before provider can be used' if @file_path.nil?
1616
raise Puppet::Error, 'Child provider class does not support a file_name method' unless respond_to?(:file_name)
17-
File.join(@file_path, file_name)
17+
@file_path
18+
end
19+
20+
def file_path
21+
File.join(self.class.file_path, resource[:context], self.class.file_name)
1822
end
1923
end

lib/puppet/provider/splunk_authentication/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/authentication.conf'
6+
'authentication.conf'
77
end
88
end

lib/puppet/provider/splunk_authorize/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/authorize.conf'
6+
'authorize.conf'
77
end
88
end

lib/puppet/provider/splunk_distsearch/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/distsearch.conf'
6+
'distsearch.conf'
77
end
88
end

lib/puppet/provider/splunk_indexes/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/indexes.conf'
6+
'indexes.conf'
77
end
88
end

lib/puppet/provider/splunk_input/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/inputs.conf'
6+
'inputs.conf'
77
end
88
end

lib/puppet/provider/splunk_limits/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/limits.conf'
6+
'limits.conf'
77
end
88
end

lib/puppet/provider/splunk_output/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/outputs.conf'
6+
'outputs.conf'
77
end
88
end

lib/puppet/provider/splunk_props/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/props.conf'
6+
'props.conf'
77
end
88
end

lib/puppet/provider/splunk_server/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/server.conf'
6+
'server.conf'
77
end
88
end

lib/puppet/provider/splunk_transforms/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/transforms.conf'
6+
'transforms.conf'
77
end
88
end

lib/puppet/provider/splunk_web/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/web.conf'
6+
'web.conf'
77
end
88
end

lib/puppet/provider/splunkforwarder_input/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/inputs.conf'
6+
'inputs.conf'
77
end
88
end

lib/puppet/provider/splunkforwarder_output/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/outputs.conf'
6+
'outputs.conf'
77
end
88
end

lib/puppet/provider/splunkforwarder_props/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/props.conf'
6+
'props.conf'
77
end
88
end

lib/puppet/provider/splunkforwarder_transforms/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/transforms.conf'
6+
'transforms.conf'
77
end
88
end

lib/puppet/provider/splunkforwarder_web/ini_setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
44
) do
55
def self.file_name
6-
'system/local/web.conf'
6+
'web.conf'
77
end
88
end

lib/puppet_x/puppetlabs/splunk/type.rb

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ def self.clone_type(type)
3636
v.to_s.strip
3737
end
3838
end
39+
type.newparam(:context) do
40+
desc 'The context in which to define the setting.'
41+
munge do |v|
42+
v.to_s.strip
43+
end
44+
defaultto('system/local')
45+
end
3946
type.newparam(:name)
4047
end
4148
end

spec/splunk_data.rb

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11

22
SPLUNK_SERVER_TYPES = {
3-
splunk_authentication: 'system/local/authentication.conf',
4-
splunk_authorize: 'system/local/authorize.conf',
5-
splunk_distsearch: 'system/local/distsearch.conf',
6-
splunk_indexes: 'system/local/indexes.conf',
7-
splunk_input: 'system/local/inputs.conf',
8-
splunk_limits: 'system/local/limits.conf',
9-
splunk_output: 'system/local/outputs.conf',
10-
splunk_props: 'system/local/props.conf',
11-
splunk_server: 'system/local/server.conf',
12-
splunk_transforms: 'system/local/transforms.conf',
13-
splunk_web: 'system/local/web.conf'
3+
splunk_authentication: 'authentication.conf',
4+
splunk_authorize: 'authorize.conf',
5+
splunk_distsearch: 'distsearch.conf',
6+
splunk_indexes: 'indexes.conf',
7+
splunk_input: 'inputs.conf',
8+
splunk_limits: 'limits.conf',
9+
splunk_output: 'outputs.conf',
10+
splunk_props: 'props.conf',
11+
splunk_server: 'server.conf',
12+
splunk_transforms: 'transforms.conf',
13+
splunk_web: 'web.conf'
1414
}.freeze
1515

1616
SPLUNK_FORWARDER_TYPES = {
17-
splunkforwarder_input: 'system/local/inputs.conf',
18-
splunkforwarder_output: 'system/local/outputs.conf',
19-
splunkforwarder_props: 'system/local/props.conf',
20-
splunkforwarder_transforms: 'system/local/transforms.conf',
21-
splunkforwarder_web: 'system/local/web.conf'
17+
splunkforwarder_input: 'inputs.conf',
18+
splunkforwarder_output: 'outputs.conf',
19+
splunkforwarder_props: 'props.conf',
20+
splunkforwarder_transforms: 'transforms.conf',
21+
splunkforwarder_web: 'web.conf'
2222
}.freeze
2323

2424
SPLUNK_TYPES = SPLUNK_SERVER_TYPES.merge(SPLUNK_FORWARDER_TYPES)

spec/unit/puppet/type/splunk_config_spec.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
#
2121
SPLUNK_TYPES.each do |type, file_name|
2222
if SPLUNK_SERVER_TYPES.key?(type)
23-
file_path = File.join('/opt/splunk/etc', file_name)
23+
file_path = File.join('/opt/splunk/etc/system/local', file_name)
2424
elsif SPLUNK_FORWARDER_TYPES.key?(type)
25-
file_path = File.join('/opt/splunkforwarder/etc', file_name)
25+
file_path = File.join('/opt/splunkforwarder/etc/system/local', file_name)
2626
end
2727

2828
it "should configure the #{type} type with file path #{file_path}" do
29-
provider = Puppet::Type.type(type).provider(:ini_setting)
29+
resource = Puppet::Type.type(type).new(name: 'foo', setting: 'foo', section: 'foo')
30+
provider = Puppet::Type.type(type).provider(:ini_setting).new(resource)
3031
expect(provider.file_path).to eq(file_path)
3132
end
3233
end

0 commit comments

Comments
 (0)