Skip to content

Commit

Permalink
Merge pull request #1 from bastelfreak/rubocop
Browse files Browse the repository at this point in the history
Rubocop
  • Loading branch information
alexjfisher authored Sep 26, 2016
2 parents da5d112 + 3037bd7 commit ed6907c
Show file tree
Hide file tree
Showing 40 changed files with 100 additions and 112 deletions.
10 changes: 5 additions & 5 deletions lib/puppet/provider/ini_setting/splunk.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Puppet::Type.type(:ini_setting).provide(
:splunk,
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
parent: Puppet::Type.type(:ini_setting).provider(:ruby)
) do

confine :true => false # Never automatically select this provider
confine true: false # Never automatically select this provider

@file_path = nil

def self.file_path
raise Puppet::Error, "file_path must be set with splunk_config type before provider can be used" if @file_path.nil?
raise Puppet::Error, "Child provider class does not support a file_name method" unless self.respond_to?(:file_name)
raise Puppet::Error, 'file_path must be set with splunk_config type before provider can be used' if @file_path.nil?
raise Puppet::Error, 'Child provider class does not support a file_name method' unless self.respond_to?(:file_name)
File.join(@file_path, file_name)
end

def self.set_file_path(path)
@file_path=path
@file_path = path
end
end
2 changes: 1 addition & 1 deletion lib/puppet/provider/splunk_authentication/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunk_authentication).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/authentication.conf'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/splunk_authorize/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunk_authorize).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/authorize.conf'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/splunk_distsearch/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunk_distsearch).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/distsearch.conf'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/splunk_indexes/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunk_indexes).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/indexes.conf'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/splunk_input/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunk_input).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/inputs.conf'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/splunk_limits/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunk_limits).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/limits.conf'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/splunk_output/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunk_output).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/outputs.conf'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/splunk_props/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunk_props).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/props.conf'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/splunk_server/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunk_server).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/server.conf'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/splunk_transforms/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunk_transforms).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/transforms.conf'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/splunk_web/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunk_web).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/web.conf'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/splunkforwarder_input/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunkforwarder_input).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/inputs.conf'
Expand Down
5 changes: 2 additions & 3 deletions lib/puppet/provider/splunkforwarder_output/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
Puppet::Type.type(:splunkforwarder_output).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
"system/local/outputs.conf"
'system/local/outputs.conf'
end
end

2 changes: 1 addition & 1 deletion lib/puppet/provider/splunkforwarder_props/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunkforwarder_props).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/props.conf'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunkforwarder_transforms).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/transforms.conf'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/splunkforwarder_web/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Puppet::Type.type(:splunkforwarder_web).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
parent: Puppet::Type.type(:ini_setting).provider(:splunk)
) do
def self.file_name
'system/local/web.conf'
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/type/splunk_authentication.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type')

Puppet::Type.newtype(:splunk_authentication) do
@doc = "Manage splunk authentication settings in authentication.conf"
@doc = 'Manage splunk authentication settings in authentication.conf'
PuppetX::Puppetlabs::Splunk::Type.clone_type(self)
end

2 changes: 1 addition & 1 deletion lib/puppet/type/splunk_authorize.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type')

Puppet::Type.newtype(:splunk_authorize) do
@doc = "Manage splunk authorize settings in authorize.conf"
@doc = 'Manage splunk authorize settings in authorize.conf'
PuppetX::Puppetlabs::Splunk::Type.clone_type(self)
end
70 changes: 34 additions & 36 deletions lib/puppet/type/splunk_config.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Require all of our types so the class names are resolvable for purging
Dir[File.dirname(__FILE__) + '/*.rb'].each do |file|
unless file == __FILE__
require file
end
Dir[File.dirname(__FILE__) + '/*.rb'].each do |file|
unless file == __FILE__
require file
end
end

Puppet::Type.newtype(:splunk_config) do
newparam(:name, :namevar => true) do
newparam(:name, namevar: true) do
desc 'splunk config'
end

Expand All @@ -23,26 +23,26 @@
end

## Generate purge parameters for the splunk_config type
[
:purge_inputs,
:purge_outputs,
:purge_authentication,
:purge_authorize,
:purge_distsearch,
:purge_indexes,
:purge_limits,
:purge_props,
:purge_server,
:purge_transforms,
:purge_web,
:purge_forwarder_inputs,
:purge_forwarder_outputs,
:purge_forwarder_props,
:purge_forwarder_transforms,
:purge_forwarder_web
[
:purge_inputs,
:purge_outputs,
:purge_authentication,
:purge_authorize,
:purge_distsearch,
:purge_indexes,
:purge_limits,
:purge_props,
:purge_server,
:purge_transforms,
:purge_web,
:purge_forwarder_inputs,
:purge_forwarder_outputs,
:purge_forwarder_props,
:purge_forwarder_transforms,
:purge_forwarder_web
].each do |p|
newparam(p) do
newvalues(:true,:false)
newvalues(:true, :false)
defaultto :false
end
end
Expand All @@ -53,7 +53,7 @@
def generate
set_provider_paths

resources = Array.new
resources = []

{
Puppet::Type::Splunk_output => self[:purge_outputs],
Expand All @@ -71,14 +71,13 @@ def generate
Puppet::Type::Splunkforwarder_props => self[:purge_forwarder_props],
Puppet::Type::Splunkforwarder_transforms => self[:purge_forwarder_transforms],
Puppet::Type::Splunkforwarder_web => self[:purge_forwarder_web]
}.each do |k,purge|
}.each do |k, purge|
resources.concat(purge_splunk_resources(k)) if purge == :true
end

return resources
end


def set_provider_paths
[
:splunk_authentication,
Expand All @@ -104,37 +103,36 @@ def set_provider_paths
Puppet::Type.type(res_type).provider(:ini_setting).set_file_path(self[:forwarder_confdir])
end
end

def purge_splunk_resources(klass)
type_name = klass.name
purge_resources = Array.new
puppet_resources = Array.new
purge_resources = []
puppet_resources = []

# Search the catalog for resource types matching the provided class
# type and build an array of puppet resources matching the namevar
# as section/setting
#
catalog_resources = catalog.resources.select { |r| r.is_a?(klass) }
catalog_resources.each do |res|
puppet_resources << res[:section] + "/" + res[:setting]
puppet_resources << res[:section] + '/' + res[:setting]
end


# Search the configured instances of the class type and purge them if
# the instance name (setion/setting) isn't found in puppet_resources
#
Puppet::Type.type(type_name).instances.each do |instance|
unless puppet_resources.include?(instance.name)
purge_resources << Puppet::Type.type(type_name).new(
:name => instance.name,
:section => instance[:section],
:setting => instance[:setting],
:ensure => :absent
name: instance.name,
section: instance[:section],
setting: instance[:setting],
ensure: :absent
)
end
end

return purge_resources
end

end
3 changes: 1 addition & 2 deletions lib/puppet/type/splunk_distsearch.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type')

Puppet::Type.newtype(:splunk_distsearch) do
@doc= "Manage distsearch entries in distsearch.conf"
@doc = 'Manage distsearch entries in distsearch.conf'
PuppetX::Puppetlabs::Splunk::Type.clone_type(self)
end

3 changes: 1 addition & 2 deletions lib/puppet/type/splunk_indexes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type')

Puppet::Type.newtype(:splunk_indexes) do
@doc = "Manage splunk index settings in indexes.conf"
@doc = 'Manage splunk index settings in indexes.conf'
PuppetX::Puppetlabs::Splunk::Type.clone_type(self)
end

2 changes: 1 addition & 1 deletion lib/puppet/type/splunk_input.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type')

Puppet::Type.newtype(:splunk_input) do
@doc = "Manage splunk input settings in inputs.conf"
@doc = 'Manage splunk input settings in inputs.conf'
PuppetX::Puppetlabs::Splunk::Type.clone_type(self)
end
2 changes: 1 addition & 1 deletion lib/puppet/type/splunk_limits.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type')

Puppet::Type.newtype(:splunk_limits) do
@doc = "Manage splunk limits settings in limits.conf"
@doc = 'Manage splunk limits settings in limits.conf'
PuppetX::Puppetlabs::Splunk::Type.clone_type(self)
end
2 changes: 1 addition & 1 deletion lib/puppet/type/splunk_output.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type')

Puppet::Type.newtype(:splunk_output) do
@doc = "Manage splunk output settings in outputs.conf"
@doc = 'Manage splunk output settings in outputs.conf'
PuppetX::Puppetlabs::Splunk::Type.clone_type(self)
end
2 changes: 1 addition & 1 deletion lib/puppet/type/splunk_props.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type')

Puppet::Type.newtype(:splunk_props) do
@doc = "Manage splunk prop settings in props.conf"
@doc = 'Manage splunk prop settings in props.conf'
PuppetX::Puppetlabs::Splunk::Type.clone_type(self)
end
2 changes: 1 addition & 1 deletion lib/puppet/type/splunk_server.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type')

Puppet::Type.newtype(:splunk_server) do
@doc = "Manage splunk server settings in server.conf"
@doc = 'Manage splunk server settings in server.conf'
PuppetX::Puppetlabs::Splunk::Type.clone_type(self)
end
2 changes: 1 addition & 1 deletion lib/puppet/type/splunk_transforms.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type')

Puppet::Type.newtype(:splunk_transforms) do
@doc = "Manage splunk transforms settings in transforms.conf"
@doc = 'Manage splunk transforms settings in transforms.conf'
PuppetX::Puppetlabs::Splunk::Type.clone_type(self)
end
2 changes: 1 addition & 1 deletion lib/puppet/type/splunk_web.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type')

Puppet::Type.newtype(:splunk_web) do
@doc = "Manage splunk web settings in web.conf"
@doc = 'Manage splunk web settings in web.conf'
PuppetX::Puppetlabs::Splunk::Type.clone_type(self)
end
2 changes: 1 addition & 1 deletion lib/puppet/type/splunkforwarder_input.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type')

Puppet::Type.newtype(:splunkforwarder_input) do
@doc = "Manage splunkforwarder input settings in inputs.conf"
@doc = 'Manage splunkforwarder input settings in inputs.conf'
PuppetX::Puppetlabs::Splunk::Type.clone_type(self)
end
3 changes: 1 addition & 2 deletions lib/puppet/type/splunkforwarder_output.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type')


Puppet::Type.newtype(:splunkforwarder_output) do
@doc = "Manage splunkforwarder output settings in outputs.conf"
@doc = 'Manage splunkforwarder output settings in outputs.conf'
PuppetX::Puppetlabs::Splunk::Type.clone_type(self)
end
Loading

0 comments on commit ed6907c

Please sign in to comment.