Commit graph

51 commits

Author SHA1 Message Date
Stepan Stipl
4853927093 Implemented show_diff parameter, with similar behaviour as show_diff on
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.
2016-01-15 20:47:07 +00:00
Gary Larizza
d452e6ca1e Support a space as a key_val_separator
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).
2015-08-06 13:56:16 -07:00
Morgan Haskel
2ab47100c7 MODULES-2212 - Add use_exact_match parameter for subsettings
There's no way to distinguish between a subsetting with a value and a
subsetting with no value, so add a parameter to allow that to be
specified.
2015-07-31 16:11:27 -07:00
WhatsARanjit
b0fb47d4ec Added ability to specify section_prefix and section_suffix to accomodate files with sections that don't follow [section_name] format. AIX for example uses section_name: format. 2015-04-15 03:56:08 -04:00
Bryan Jen
69bee205c4 Adds acceptance testing for setting names containing white space in the middle 2015-03-31 15:28:42 -07:00
Michael Siroskey
a747f6656f Fixed SETTING_REGEX and COMMENTED_SETTING_REGEX to allow spaces in setting names. 2015-03-31 14:27:45 -07:00
Pete Johns
c4fa6a614a Fix spec: predicates return booleans 2014-12-18 10:22:20 -08:00
Igor Galić
3288d415e9 WIP: Allow changing key value separator beyond indentation
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.
2014-12-18 10:22:20 -08:00
Pete Johns
3e46c13dc2 Fix Ruby 1.9.3 build 2014-11-08 18:52:20 +11:00
Pete Johns
efeb174427 Add spec for #123
I may have made this configuration file up
2014-11-08 18:47:08 +11:00
Pete Johns
d98e9bcb77 Add failing spec for KDE Configuration with braces in setting names
Refer https://github.com/puppetlabs/puppetlabs-inifile/pull/131
2014-11-08 17:05:59 +11:00
Huan Do
f343c41cd8 modify test to compare to a hash which better tests the state of each setting
also update @@COMMENTED_SETTING_REGEX to be roughly equal to "(\s*)[#;]+" + @@SETTING_REGEX
2014-09-12 16:55:24 -07:00
Huan Do
681f5c0cb4 fix issue where single characters settings were not being saved.
see https://github.com/boxen/puppet-git/issues/30
2014-09-08 23:12:09 -07:00
Pete Johns
b3fed85b57 Spec for MODULES-1194
Ini_file module does not recognize section names with forward slashes in them

https://tickets.puppetlabs.com/browse/MODULES-1194
2014-07-04 14:31:39 +10:00
Pete Johns
bd99244353 Test allowing $ signs in section names
Verifying that this PR addresses https://github.com/puppetlabs/puppetlabs-inifile/pull/98
2014-06-28 13:22:01 +10:00
Pete Johns
cabc678131 Merge branch 'deprecation-warnings' into handle-quotation-marks-in-section-names
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
```
2014-06-26 21:55:30 +10:00
Pete Johns
49960e1c5e Handle quotation marks in section names
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.
2014-06-26 21:42:45 +10:00
Pete Johns
41fc8bfbf5 Failing spec to describe my problem 2014-06-26 21:42:06 +10:00
Pete Johns
961447dfdf be_true and be_false are deprecated
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
2014-06-26 20:04:33 +10:00
Michal Růžička
77854d55f8 Tests for the quote_char parameter. 2014-05-07 23:52:07 +02:00
Rob Braden
6870dfed7d Add tests to cover settings with square brackets and quotes in the name 2013-12-04 17:16:19 -08:00
Jesse Newland
c058ee5d40 support spaces in sections 2013-12-02 12:57:02 -05:00
Richard Clamp
756e7ab166 .instances isn't stable between puppet versions
Extract the names from all the instances, and check they don't have the form
`[ '/green', '/red' ]` which they would if the inheritance doesn't work.
2013-07-16 14:38:45 +01:00
Richard Clamp
6f7b28bd59 fix syntax for 1.8.7 2013-07-16 13:42:38 +01:00
Richard Clamp
b0c8d5c34a allow for the namevar construction
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.
2013-07-16 10:18:15 +01:00
Richard Clamp
e5898439c5 add a test for creating subclassed instances 2013-07-16 10:18:15 +01:00
Terry Wilson
5904c6f7b4 Allow empty values
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).
2013-07-10 10:26:37 -05:00
Chris Price
cbea5dcd72 Fix bug in subsetting handling for new settings
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.
2013-05-28 14:56:57 -07:00
Chris Price
1aa7e601f4 Better handling of quotes for subsettings
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.
2013-05-22 11:50:12 -07:00
Chris Price
6e318317fb Merge pull request #32 from bodepd/fix_test_failures
fix unit test failures
2013-04-01 17:36:49 -07:00
Dan Bode
f48cae87a0 fix unit test failures
the previous tests were stubbing global class instances
in a way that was causing other tests to fail.

This commit updates the tests, and introdcuces child classes which
can safely be stubbed (and more closely test the real behavior intended to
be tested here)
2013-04-01 17:27:10 -07:00
Chris Price
e824ab2aba Merge pull request #29 from kbrezina/subsetting
Added 'ini_subsetting' custom resource type
2013-03-25 11:00:41 -07:00
Karel Brezina
4351d8b9c8 Added 'ini_subsetting' custom resource type 2013-03-25 11:34:37 +01:00
Chris Price
8064df6d00 Merge pull request #30 from bodepd/fix_nil_indentation
guard against nil indentation values
2013-03-12 11:11:09 -07:00
Dan Bode
5f71d7f0bd guard against nil indentation values
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.
2013-03-11 17:42:08 -07:00
Dan Bode
2f22483c87 Add purging support to ini 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.
2013-03-04 15:38:58 -08:00
Chris Price
a45ab65930 Add detection for commented versions of settings
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.
2012-10-26 17:24:37 -07:00
Chris Price
845fa707be Better handling of whitespace lines at ends of sections
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.
2012-10-20 01:43:19 -07:00
Chris Price
c2c26de9b1 Respect indentation / spacing for existing sections and settings
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.
2012-10-20 00:08:06 -07:00
Chris Price
cda30a6ab9 Minor tweaks to handling of removing settings
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.
2012-10-17 13:27:28 -07:00
Dan Bode
1106d70e88 Add support for removing lines
This commit adds the ability to ensure that lines are absent.
2012-10-10 17:40:38 -07:00
Dan Bode
cbc90d3834 Make value a property
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.
2012-10-02 18:53:53 -07:00
Reid Vandewiele
3829e20c49 Allow values with spaces to be parsed and set
Previously, the following stanza would fail as a result of the
ini_setting type not being able to parse spaces in setting values.

  ini_setting { 'main_config_version':
    ensure  => present,
    path    => '/etc/puppetlabs/puppet/puppet.conf',
    section => 'main',
    setting => 'config_version',
    value   => '/etc/puppetlabs/puppet/config_version.sh $environment',
  }

This commit modifes the SETTING_REGEX to account for spaces in setting values.
2012-09-29 12:39:00 -07:00
Chris Price
e527908b7c Add validation for key_val_separator
For now, the key_val_separator is required to contain
exactly one '=' character.  This commit simply validates
that that is the case.
2012-09-20 11:35:45 -07:00
Chris Price
8d1fdc5c29 Allow overriding separator string between key/val pairs
This introduces a new parameter, 'key_val_separator', which
can be set in order to override the string that is used
as a separator between the key/value pair of a setting line.
The default is ' = ', but you could set the param to '=' if
you don't want to include whitespace in your settings file.
2012-09-19 15:42:16 -07:00
Joe Topjian
4d3acd8fae Added tests for sections with colons 2012-09-04 17:16:05 +00:00
Chris Price
c57dab4903 Add support for "global" section at beginning of file
This commit does the following:

* Fixes a bug in ExternalIterator
* Adds support for a "global" section before the first named
  section at the beginning of the INI file
* Improves test coverage
2012-08-17 04:48:28 -07:00
Chris Price
4f0e7264e3 final commit for 0.0.1 release
* Updated README
* Fixed a small bug that would be triggered if the file specified
  by `path` didn't exist.
* Added a smoke test manifest
2012-08-16 21:50:20 -07:00
Stephen
d2c1e07e80 Fixed regex to match sections and settings with non alphanumeric
characters. Fixed writing to file without any sections at all.
Fixed exists checking for variable type by always casting to string
and added all the tests for the above items.
2012-08-14 13:38:08 +01:00
Chris Price
9c76b6af12 First (basic) working version of ini_setting provider 2012-07-28 21:59:54 -07:00