1 require File.expand_path('../../../util/ini_file', __FILE__)
3 Puppet::Type.type(:ini_setting).provide(:ruby) do
6 # this code is here to support purging and the query-all functionality of the
7 # 'puppet resource' command, on a per-file basis. Users
8 # can create a type for a specific config file with a provider that uses
9 # this as its parent and implements the method
10 # 'self.file_path', and that will provide the value for the path to the
11 # ini file (rather than needing to specify it on each ini setting
12 # declaration). This allows 'purging' to be used to clear out
13 # all settings from a particular ini file except those included in
15 if self.respond_to?(:file_path)
16 # figure out what to do about the seperator
17 ini_file = Puppet::Util::IniFile.new(file_path, '=')
19 ini_file.section_names.each do |section_name|
20 ini_file.get_settings(section_name).each do |setting, value|
23 :name => namevar(section_name, setting),
32 raise(Puppet::Error, 'Ini_settings only support collecting instances when a file path is hard coded')
36 def self.namevar(section_name, setting)
37 "#{section_name}/#{setting}"
41 !ini_file.get_value(section, setting).nil?
45 ini_file.set_value(section, setting, resource[:value])
51 ini_file.remove_setting(section, setting)
57 ini_file.get_value(section, setting)
61 ini_file.set_value(section, setting, resource[:value])
66 # this method is here so that it can be overridden by a child provider
71 # this method is here so that it can be overridden by a child provider
76 # this method is here to support purging and sub-classing.
77 # if a user creates a type and subclasses our provider and provides a
78 # 'file_path' method, then they don't have to specify the
79 # path as a parameter for every ini_setting declaration.
80 # This implementation allows us to support that while still
81 # falling back to the parameter value when necessary.
82 if self.class.respond_to?(:file_path)
90 if resource.class.validattr?(:key_val_separator)
91 resource[:key_val_separator] || '='
98 if resource.class.validattr?(:section_prefix)
99 resource[:section_prefix] || '['
106 if resource.class.validattr?(:section_suffix)
107 resource[:section_suffix] || ']'
115 @ini_file ||= Puppet::Util::IniFile.new(file_path, separator, section_prefix, section_suffix)