Empty sections hanging around are not useful, so if the last line in a
section is removed then remove the section. If the section still has
comments, then just leave it be.
This does not add the ability to remove sections that do not have
settings to begin with; only allows cleaning a file as puppet makes
changes to it.
Puppet 4.0 and 4.1 are affected by PUP-4709 which raises duplicate
resource errors when using create_ini_settings(), due to the inclusion
of square brackets in the resource titles.
Error while evaluating a Function Call, Duplicate
declaration: Ini_setting[[foo] bar] is already declared; cannot
redeclare
Removing these from the function allows it to work on these Puppet
versions without error.
type file
show_diff => true (default) prints diff to logs
show_diff => md5 prints only md5 hashes instead of actual values
show_diff => false redacts any information about values
Global show_diff config takes priotiry over this one.
Currently the create_ini_settings function creates an ini_setting with a
title comprised of the section and setting names. This means that we
run into resource conflicts when defining the same section/setting
combinations but in different files. Since the path parameter is
required, we can safely add this to the title of the ini_setting
resource created by the create_ini_settings function. This commit does
just that.
Previously, trying to use a space as a key_val_separator in the ini_setting
type would fail because #strip is being called on the key_val_separator
attribute, which completely kills the space. This commit checks to see
if key_val_separator has been set as a space, and, if so, sets the `k_v_s`
variable in the library to be ' ' instead of ''. This in turn allows the
provider to check for existing values (instead of inserting the value every
time Puppet is run).
The previous match for \s would also match on newlines. This caused
existing settings with blank values to have the newline considered part
of the whitespace surrounding the separator. When such settings are
set with a value, the value ends up on the next line.
Also adding acceptance test for this particular situation.
Our documentation says to use "" for section if you want top of file
global settings, this defaults to that assumption if the user doesn't
provide a section parameter at all.
create_ini_settings is a function that allows you to create
ini_setting resources from a simple hash:
$settings = { section1 => {
setting1 => val1
},
section2 => {
setting2 => val2,
setting3 => {
ensure => absent
}
}
}
$defaults = {
path => '/tmp/foo.ini'
}
create_ini_settings($settings,$defaults)
Will create the following resources
ini_setting{'[section1] setting1':
ensure => present,
section => 'section1',
setting => 'setting1',
value => 'val1',
path => '/tmp/foo.ini',
}
ini_setting{'[section2] setting2':
ensure => present,
section => 'section2',
setting => 'setting2',
value => 'val2',
path => '/tmp/foo.ini',
}
ini_setting{'[section2] setting3':
ensure => absent,
section => 'section2',
setting => 'setting3',
path => '/tmp/foo.ini',
}
This allows one to create much easier classes
that should be able to manage an arbritary set of
ini-style settings without having to specify each
one of them.
We have many ini-style configuration files which use : as key value
separator. We'd like to be able to manage them with ini_setting as well.
This here is a naïve first attempt in that direction.
Please note that despite the fact that this *should* match, it's failing
unit tests.. This is a work in progress.
This should fix the build.
If this change isn't desired,
./spec/unit/puppet/provider/ini_setting/ruby_spec.rb:1044 could be
changed to:
```ruby
provider.exists?.should be_nil
```
The section name appears on a line by itself, in square brackets (`[` and
`]`), all characters between the opening `[` and the closing `]` should
be considered to form the section name.
Replace with `be true` and `be false` and make predicate return a
boolean.
> Methods that don't return a boolean, shouldn't end in a question mark.
-- https://github.com/bbatsov/ruby-style-guide#naming
The quote_char is used to quote the entire setting when it is modified
as a result of changes to some subsettings.
For an example let's assume we have a setting of this form:
JAVA_ARGS=-Xmx256m
and we want to add the '-Xms' parameter to the setting, for that purpose
we define a resource like this:
ini_subsetting { '-Xms':
ensure => present,
path => '/some/config/file',
section => '',
setting => 'JAVA_ARGS',
subsetting => '-Xms'
value => '256m',
}
which results into the following setting:
JAVA_ARGS=-Xmx256m -Xms256m
But this is not what we intended - if this setting is read by the bash
shell the '-Xms256m' parameter is interpreted as a command to be
executed rather than a value to be assigned to the JAVA_ARGS variable.
To fix this problem the quote_char parameter was added to the
ini_subsetting resource type, and we'll take advantage of it to fix the
problem in the above example like so:
ini_subsetting { '-Xms':
ensure => present,
path => '/some/config/file',
section => '',
setting => 'JAVA_ARGS',
quote_char => '"',
subsetting => '-Xms'
value => '256m',
}
which will result into:
JAVA_ARGS="-Xmx256m -Xms256m"
which is what we intended.
The default type would always have a section as part of its namevar, but if
you're inheriting from ini_setting you may be modelling a flat file with no
sections.
This pushes the formation of the namevar from the section_name and setting into
a method, then demonstrates overriding it so that inherited_ini_setting can just
be
inherited_ini_file { 'setting':
value => '12',
}
and continue to be purgable.
If you follow the example in the README you may not have implemented the
:key_value_separator parameter in your type, and you get the wonderful failure
case:
Puppet::Error: Invalid parameter key_val_separator(:key_val_separator)
This change looks first, and if the user hasn't specified that attribute in
their type in their type, it falls back to '='
smb.conf contains settings names with white spaces, for example
[globel]
server role = active directory domain controller
check password script = Disable
It is a legitimate use case to set empty values; to override a
default when an empty value is acceptable for instance. This patch
changes the regex in three ways: it 1) removes the requirement for
a non-whitespace terminator on a setting value, 2) makes the value
match non-greedy so that the \s*$ at the end can catch the newline
and 3) changes the \s*=\s* to [ \t]*=[ \t]* because we don't want
that to capture *any* whitespace (like a newline).
Our new state variable `@quote_char` was not being initialized
property if you used `ini_subsetting` for a setting that did
not yet exist. This fixes that bug.
Prior to this commit, the `ini_subsetting` type assumed that
all of the settings strings were quoted, and always wrote
out the modified value with double-quotes around it.
This commit adds tests for the case where the original setting
is not quoted, and intelligently writes the modified setting
with the same quote character (or lack thereof) that the
original setting used.
Because of the way that puppet's autoloader and pluginsync work,
modules on the master get loaded twice, which means that
you can't use Ruby constants at all w/o getting warning messages.
This commit changes all of the constants in `ini_file` to class
variables, which will avoid the warning messages.
This commit is intended to resolves an issue where the indentation
value can be nil (which leads to a run time exception)
This occurrs in cases where a section is following by only one of more
comments.
The proposed fix is to guard against potential nil values where the
error occurs. This fix is idential to code used at line 125 of the same file.
This commit adds purging to ini file native types.
Purging will only work for child providers that
implement the method: self.file_path. This is
because collecting all instances of the type (
which is a requirement for purging) is only possible
when the path of the file that is being managed
can be accessed by the class instance (in the
method self.instances.)
This commit adds the following method to the internal
of the ini_file:
- get_settings - has of all settings/values for
a given section
It also adds the following method to the section
class:
- setting_names - list of all setting names in a
section.
These methods are required for the instances method
to be able to list the values for all settings of
each section.
This commit adds support for detecting commented versions of
settings in an existing version of an inifile. If you are
setting a value for a setting that isn't currently set
in the file, but a commented version is found, then we
add the new setting immediately following the commented
version, rather than at the end of the section.
The `save` method was previously relying on some really
specific implementation details of the `section` class
(when the start/end_line would be nil, etc.). This made
the code a bit hard to follow.
This commit introduces a few utility methods in the
`section` class (`is_new_section?`, `is_global?`), and
refactors the `save` method to use them... this makes
the logic a little easier to follow and should hopefully
make it easier to maintain.
This is another bit of cosmetic functionality; prior to
this commit, when adding a new setting to a section, we'd
write it on the very last line before the next section,
even if there was a chunk of trailing whitespace lines
at the end of the existing section. This was functional,
but the output was not always particularly pleasant for
human consumption.
This commit tweaks things so that we insert new settings
just before the final chunk of whitespace lines in an
existing section. This keeps things a bit cleaner.
This commit adds some cosmetic functionality. The main two
improvements are:
* We'll now pay attention to indentation within existing
sections, and when we write new settings or update
existing ones, we'll match the existing indentation.
* When modifying existing settings, the regex now captures
a greater portion of the original line and preserves it.
Basically, the original whitespacing in the line should
remain intact and only the value should be modified.
This commit makes some minor changes to how we handle removing
settings. In particular, it updates all of the line numbers
of the various 'section' objects to correspond to the new
state of the world based on the removal of a line that appeared
before them.
Also adds one more test related to setting removal.
This commit converts value to a property so that it
can be managed and modified when a file already has
a value set.
It was previously treating the line creation state
the same as the update case, which is not in
alignment with Puppet's model.