Commit graph

471 commits

Author SHA1 Message Date
Eli Young
8cf011d7a2 Revert "range: remove dead code"
This reverts commit 063c58a992, which
actually removed non-dead code. Specifically, it removed the ability to
make calls such as `range('2..3')`, `range('2...3')`, and
`range('2-3')`.

cf. https://github.com/puppetlabs/puppetlabs-stdlib/pull/443#commitcomment-11055565
2015-05-05 16:06:08 -07:00
Eli Young
7d7e905b54 pw_hash: Fix functionality on JRuby < 1.7.17
The previous change to this function broke it on JRuby before 1.7.17 by
attempting to use a variable that wasn't defined (`salt`). To fix this,
define `salt` ahead of time and use that instead of building the salt
later.

cf. https://github.com/puppetlabs/puppetlabs-stdlib/pull/443#discussion_r29718588
2015-05-05 15:53:34 -07:00
David Schmitt
d4f3d57f16 validate_augeas: fix URL to docs 2015-05-05 13:55:18 +01:00
David Schmitt
063c58a992 range: remove dead code
Since a ParseError is always thrown for zero arguments, the if and all
dependent code can be removed.
2015-05-05 13:30:57 +01:00
David Schmitt
9bae8356fd pw_hash: avoid ruby magic when running on java 2015-05-05 13:30:57 +01:00
David Schmitt
c27513463d fqdn_rand_string: fix argument error message 2015-04-17 14:24:40 -07:00
Morgan Haskel
8a1d1e2f34 Merge pull request #314 from amateo/feature/loadyaml_check_file
Check if file exists before loading with loadyaml. If not, return nil
2015-04-16 10:48:10 -07:00
Morgan Haskel
5ee6e960f6 Merge pull request #431 from bmjen/file-line-refactor
File_line checks provided after param if no match is found
2015-04-09 16:47:34 -07:00
Travis Fields
0af0d7e539 Add spec tests and pulled in PR #427
Changed append line to open in 'w' mode and have to rewrite lines in order to append new line
2015-04-09 15:24:39 -07:00
Bryan Jen
35303ce0f7 file_line honors after if match not found. 2015-04-09 14:44:52 -07:00
Gerrard Geldenhuis
ee2225b63c Clarifying behaviour of attributes and adding an extra example. 2015-04-09 11:13:42 -07:00
Hunter Haugen
8fba5c058b Merge pull request #405 from elyscape/feature/fqdn_rand_strings
(MODULES-1715) Add FQDN-based random string generator
2015-04-09 10:45:38 -07:00
Eli Young
23be4020dd (MODULES-1737) Add pw_hash() function 2015-04-05 17:21:17 -07:00
Eli Young
a82266c256 (MODULES-1715) Add fqdn_rand string generators 2015-03-31 17:33:04 -07:00
Rod Montgomery
ee13438d2a If present, top-level domain must be alphabetic
See RFC 1123, Section 2.1
http://tools.ietf.org/html/rfc1123#section-2
2015-03-05 21:51:12 -06:00
TP Honey
bf8e5b0573 Merge pull request #422 from cyberious/assert_private
Assert private
2015-03-05 19:15:41 +00:00
Travis Fields
4a68b224c4 Add private function back and forward to assert_private with deprecation warning 2015-03-05 11:12:51 -08:00
Hunter Haugen
668b3c31b5 Merge pull request #369 from rfugina/dirname_typecheck
Dirname typecheck
2015-03-05 11:00:36 -08:00
Franz Pletz
56d815bcfc Rename private() to assert_private()
As mentioned in #270, private is a reserved keyword in the future parser
which is to be released with Puppet 4. As it stands, this function is
not useable with the future parser so it needs to renamed.

This is a breaking change.
2015-03-05 10:59:31 -08:00
Hunter Haugen
41965fd2c9 Merge pull request #375 from poikilotherm/feature/master/validate_integer_and_numeric
(MODULES-560) Add new functions validate_numeric() and validate_integer().
2015-03-05 10:57:43 -08:00
Stefan Goethals
0236cd51bc Add support for hashes in the prefix function
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2015-03-03 16:20:55 -08:00
Bryon Roché
41baef8502 URI.escape for the array case was incorrect.
The previous commit to uriescape() changed the implementation to use the ruby default escape list for URI.escape(), but did not change the call triggered when uriescape() was called on an array, triggering ruby errors.
2015-03-03 16:05:47 -08:00
Morgan Haskel
055083c117 Merge pull request #407 from adamcrews/ceiling_function
Add a ceiling function to complement the floor function.
2015-03-03 15:59:06 -08:00
Travis Fields
85e81f9bdf Loosen the restrictions of upcase and allow for recursion of the objects and only worry if the object responds to upcase 2015-03-02 10:45:43 -08:00
Travis Fields
419f51bdd9 Fix issue with Ruby 1.8.7 which did not allow for the return in an each_pair of the hash 2015-02-26 10:13:28 -08:00
Travis Fields
7021b1f55c Add Hash to upcase 2015-02-25 11:39:27 -08:00
Morgan Haskel
b693c870d2 Check for string before copying 2015-02-19 12:01:26 -08:00
Sean Millichamp
1321d586a8 (MODULES-1771) Don't modify input to is_domain_name()
Fix is_domain_name() so it dup's its incoming argument
to avoid changing the original with a later chomp!
2015-02-14 10:49:26 -05:00
Eli Young
84f866ffaf (MODULES-1738) Don't modify global seed in fqdn_rotate()
As per puppetlabs/puppet@292233c, this leaves the global seed in a
deterministic state, which is bad. Puppet::Util.deterministic_rand()
exists to avoid running into this issue, but is only present starting in
Puppet 3.2.0.
2015-02-12 14:04:47 -08:00
Adam Crews
53b1802a92 Add a ceiling function to complement the floor function. 2015-02-01 22:46:16 -08:00
Travis Fields
b11311ad65 FM-2130 Move cache file to non temp directory 2015-01-13 16:50:27 -08:00
Hunter Haugen
7c8ae311ca (MODULES-1473) Deprecate type() function for new parser
The `type()` function will cease to work on the new parser because 'type'
is a reserved keyword. The `type3x()` function may be used to continue
similar functionality, but will be deprecated in favor of the built-in
typing system.

The `type_of()` function has been included to introspect types in the
new parser.
2015-01-07 16:40:06 -08:00
Travis Fields
4700f16e82 Merge pull request #336 from mklette/master
ensure_resource: be more verbose in debug mode
2015-01-02 12:27:33 -08:00
Travis Fields
f6e20d2068 Update docs to reflect new behavior of delete function taking array in second argument 2014-12-19 10:41:07 -08:00
Travis Fields
8ec6f8dbfd MODULES-1606 add ability to pass array to delete for items to delete 2014-12-19 10:26:01 -08:00
Hunter Haugen
1ae0a10707 Merge pull request #388 from mhaskel/merge_4.5.x_into_master
Merge 4.5.x into master
2014-12-18 15:55:33 -08:00
Peter Souter
b3d007f1da (MODULES-1582) Improve % detection
Avoids any validate commands that have %'s in them other than "... % ..."
2014-12-18 23:35:24 +00:00
Peter Souter
165caa8be1 (MODULES-1582) Initial spike for % placeholder
This simply `gsub`'s the file path into where the % placeholder is.
2014-12-18 23:08:33 +00:00
Morgan Haskel
696c89de99 Merge pull request #372 from poikilotherm/feature/master/validate_absolute_path_allow_arrays
Allow array of pathes in validate_absolute_path
2014-12-17 14:19:30 -08:00
Morgan Haskel
841b0df210 Merge pull request #368 from rfugina/basename
Basename implementation
2014-12-17 11:00:23 -08:00
Rob Fugina
2a3babc348 Added type checks for dirname(), and additional tests 2014-12-17 12:55:48 -06:00
Rob Fugina
ef3d42f7bb Added basename() based on Ruby's File.basename
Based on dirname code.  Includes RSpec tests and docs.
2014-12-17 12:39:40 -06:00
Hunter Haugen
c6c203fca8 Remove line match validation
The `match` attribute was validated to match `line`, except that in many
cases (even the example given in the docs) a user would want to match a
line entirely different from the new line.

See comments on the original commit
a06c0d8115
and ask
https://ask.puppetlabs.com/question/14366/file_line-resource-match-problems/
for further examples of confusion.
2014-12-16 15:05:31 -08:00
Oliver Bertuch
3053427829 Fixing ruby 1.8 support. 2014-12-05 08:51:40 +01:00
Oliver Bertuch
260c1f4b92 Add new functions validate_numeric() and validate_integer(). 2014-12-04 22:33:15 +01:00
Peter Souter
84bd98645f (MODULES-444) - Real meat of the change
This is the core change, we now go through the array and add it to the first element, instead of just two arguments.
2014-12-04 14:34:25 +00:00
Peter Souter
594c2dd38d (MODULES-444) Change argument restriction to < 2 2014-12-04 14:33:23 +00:00
Peter Souter
75a6186512 (MODULES-444) Update docs with new functionality 2014-12-04 14:32:39 +00:00
Oliver Bertuch
89995e4db0 Allow array of pathes in validate_absolute_path 2014-11-25 12:45:23 +01:00
Morgan Haskel
c5467cc507 Need to convert strings and fixnums to arrays 2014-11-17 12:27:05 -08:00
Hunter Haugen
fb42396c75 Merge pull request #319 from Spredzy/member_array_in_array
(MODULES-1329) Allow member to look for array
2014-11-13 12:27:14 -08:00
Hunter Haugen
b6830f1ade Merge pull request #365 from dalen/range-integers
Make the range function work with integers
2014-11-13 10:16:21 -08:00
Yanis Guenane
c9f906f803 (MODULES-1329) Allow member function to look for array
Currently, the member function allows one to only find if a variable
is part of an array. Sometimes it is useful to find if an array is part
of a bigger array for validation purpose.
2014-11-12 14:40:34 -05:00
Erik Dalén
ce995e15d5 Make the range function work with integers
This is needed for the future parser which actually treats numbers as
numbers and strings as strings. With this patch you can use range(1,5)
instead of having to quote them like range('1','5').
2014-11-12 16:02:05 +01:00
Erik Dalén
e61f402283 (maint) Fix indentation of range function 2014-11-12 15:52:33 +01:00
Hunter Haugen
4949cfd21c Fix breaking out of .each loop
And some other small formatting fixes that don't belong in this patch.
2014-11-10 16:37:53 -08:00
Travis Fields
c52e262a17 Catch :undefined_variable thrown when Future Parser is enabled with 3.7.x 2014-11-10 16:33:18 -08:00
Morgan Haskel
850297b560 Merge pull request #354 from puppetlabs/4.3.x
4.3.x
2014-11-10 11:10:41 -08:00
Travis Fields
406e9dbda2 Merge pull request #343 from zacharyalexstern/fix_to_bytes
Added correct converstions for PB and EB.
2014-11-07 13:42:48 -08:00
Morgan Haskel
03f0ecd128 Merge pull request #350 from cyberious/modules1413
MODULES-1413 Add ability for member to take numeric objects
2014-11-04 15:29:25 -08:00
Travis Fields
f19aea5a75 MODULES-1413 Ability to for future parser to use member with FixNum types 2014-11-04 14:33:34 -08:00
Travis Fields
35c2dc7ca3 Merge branch '4.3.x' 2014-10-30 10:23:12 -07:00
Travis Fields
6c7da72c0f Fix validate_cmd, previous addition of SystemCallError only works for Puppet 3.7, previous version throw different exception. Wrapping in generic Exception catch all 2014-10-29 20:03:07 -07:00
Travis Fields
12f734476c Merge remote-tracking branch 'origin/4.3.x' 2014-10-29 12:52:52 -07:00
Travis Fields
328aae223f Add proper exception catching of Windows errors when CreateProcess does not succeed 2014-10-29 11:47:57 -07:00
Travis Fields
a6f3f781d1 Merge remote-tracking branch 'origin/4.3.x' back to master 2014-10-28 15:31:37 -07:00
Travis Fields
51f1d574d9 Fix testcases for Future Parser and resolve issue with values_at in assuming that it was dealing with a string 2014-10-28 15:27:24 -07:00
Zachary Alex Stern
9295d0d5ca Added correct converstions for PB and EB.
* We were converting Exabytes to bytes as Petabytes.
 * Updated tests to cover ever unit.
 * Added note that we're going by the old, inaccurate definitions of
   Kilobytes, Megabytes, etc, in that we treat them as powers of 2.
2014-10-28 13:14:06 -07:00
Travis Fields
9dea092979 Merge branch '4.3.x', add tempfile back for resource validate_cmd and validate_augeas 2014-10-24 16:41:05 -07:00
Travis Fields
624ccbd22c add require 'tempfile' to resolve a previously autorequired resource 2014-10-24 16:35:34 -07:00
Travis Fields
f0b207c035 Merge branch '4.3.x'
Conflicts:
	README.markdown
	lib/puppet/parser/functions/has_interface_with.rb
2014-10-24 14:30:01 -07:00
Mathias Klette
0d11bde507 ensure_resource: be more verbose in debug mode
helps discovering duplication issues, especially when figthing boolean vs. string arguments
2014-10-10 22:57:26 +02:00
Morgan Haskel
0c0f7e13cd Merge pull request #262 from tremble/MODULES-707
Modules 707
2014-10-09 13:33:06 -04:00
Travis Fields
8ad7f68eca ENTERPRISE-281 fixes issue with has_interfaces and case mismatch causing us not to return some interfaces 2014-10-08 10:14:10 -07:00
Tomas Doran
032f93af1d Fix strict_variables = true 2014-09-22 14:43:27 -07:00
Mark Chappell
23bc7d51bd Re-use existing str2bool code rather than doing a copy and paste 2014-09-22 19:49:50 +02:00
Mark Chappell
e2d7f3bb89 (MODULES-707) chomp() fails because generate() no longer returns a string
We need to use

  unless value.is_a?(String) || value.is_a?(Array)

rather than

  klass = value.class
  unless [String, Array].include?(klass)

because the klass version enforces type checking which is too strict, and does
not allow us to accept objects wich have extended String (or Array).

For example, generate() function now returns Puppet::Util::Execution::ProcessOutput
which is just a very simple extension of String.  While this in it's self was
not intentional (PUP-2306) it is not unreasonable to cope with objects which
extend Strings
2014-09-22 19:49:50 +02:00
Travis Fields
acf435d1ce MODULES-1248 Fix issue with not properly counting regex matches with legacy versions of ruby 2014-09-16 13:41:39 -07:00
Alexander Pánek
6631934df8 Note that also future parser does not work 2014-09-16 19:03:02 +02:00
Alexander Pánek
448e66b8bb Updated docs of validate_string to reflect bug
See: https://tickets.puppetlabs.com/browse/MODULES-457
2014-09-16 17:55:26 +02:00
Angel L. Mateo
b9560df899 Check if file exists before loading with loadyaml. If not, return nil 2014-09-02 11:35:42 +02:00
Hunter Haugen
2ba0e375e2 Merge branch '4.3.x' 2014-08-05 10:55:58 -07:00
Colleen Murphy
85d5eadbab Concatenate arrays without modifying the first array 2014-07-31 11:22:18 -07:00
Thomas Linkin
9fd13be825 (MODULES-1221) Add file_line autorequire documentation
This commit adds additional documentation to the file_line resource
explaining how it will autorequire file resources when present.
2014-07-16 11:45:36 -04:00
Travis Fields
64f0ae2269 Increase resilience if lookup var comes back with nil object 2014-06-23 22:47:03 -07:00
Raphaël Pinson
2062f9734b Add private() function 2014-06-11 16:35:32 +02:00
Ashley Penney
0cda858744 Merge pull request #258 from mckern/enhancement/master/camelcasedembools
(MODULES-905) Narrow the confinement in bool2str
2014-05-15 21:48:40 -04:00
Ryan McKern
93c4151edf (MODULES-905) Narrow the confinement in bool2str
Previously, bool2str() accepted a broad array of boolean values and
bare strings, without any attempt to validate that the strings in any
way resembled "true" or "false" (or any of the other values bool2num()
accepts). This commit narrows the input confinement to TrueClass and
FalseClass, which means that bool2str() will only interpolate
strict boolean values now.
2014-05-15 15:01:14 -07:00
Ashley Penney
c5b06f9bbc Revert "Merge pull request #256 from stbenjam/2571-before"
This reverts commit 8499ebdb7f, reversing
changes made to 08b00d9229.
2014-05-15 17:28:59 -04:00
Ashley Penney
430d821ad3 Merge pull request #255 from mckern/enhancement/master/camelcasedembools
(MODULES-905) Add bool2str() and camelcase() for string manipulation
2014-05-15 17:03:18 -04:00
Stephen Benjamin
6eaa592cd8 (PUP-2571) add 'before' functionality to file_line
file_line supports adding lines after a match, but there are use cases when
having "before" would be useful. For example, in Debian-based OS's, the last
line of /etc/rc.local is "exit 0" it's an incredible pain to deal with
that scenario today.

This commit adds a 'before' parameter to the file_line type, and implements
it for the ruby provider.
2014-05-14 20:33:57 +02:00
Ryan McKern
42743614cb (MODULES-905) Add bool2str() and camelcase() for string manipulation
Python likes to have its constants Capitalized, and the capitalize
function only understands strings... so I shave a yak.

bool2str will convert a boolean to its equivalent string value,
and camelcase extends on uppercase & downcase to convert an underscore
delimited string into a camelcased string.
2014-05-13 15:46:40 -07:00
Hunter Haugen
0804121719 Fix the stdlib functions that fail tests 2014-05-08 14:55:23 -07:00
Ashley Penney
0b59dfe642 Merge pull request #222 from mfoo/fix/master/concat-primitives
Allow concat to take non-array second parameters
2014-04-24 13:41:42 -04:00
Ashley Penney
f42fc4bfd8 Merge pull request #238 from Spredzy/add_default_ensure_packages
(MODULES-603) Add defaults arguments to ensure_packages()
2014-04-24 13:38:07 -04:00
Ashley Penney
68acb59bf7 Adjust the regular expression for facts.
Previously this was incorrectly handling facts that were of the form
foo=1+1=2 due to the ='s in the actual fact contents.  Fix this and
add tests to try and prevent regressions.
2014-04-22 23:15:16 +02:00
Yanis Guenane
d9b5e912bb (MODULES-603) Add defaults arguments to ensure_packages()
Without this patch one can not specify package resource specific
parameters. All the ensure_packages() function does it makes sure
the named packages are installed. This patch allows one to pass
default as a second argument and allow greater flexibility on
packages installations.

Use case like the following are now possible :
  * ensure_packages(['r10k', 'serverspec'], {'provider' => 'gem'})
  * ensure_packages(['ntp'], {'require' => 'Exec[foobar]'})
2014-03-30 18:47:36 -04:00
Martin Foot
35bf5fd8c9 Allow concat to take non-array second parameters
Also improve and extend concat tests to lock down functionality
2014-02-21 15:48:27 +00:00
Justin Burnham
c12e9afc97 PUP-1724 Don't modify the paramaters to deep_merge
Instead of modifying the first paramater of deep_merge due to the
use of the merge! function, instead use merge to return a copy of
the merged object. This allows one to continue to use the original
first parameter after the call to deep_merge.
2014-02-17 12:19:40 -08:00
Sharif Nassar
a972e0645b Remove trailing whitespace 2014-02-05 15:01:45 -08:00
David Schmitt
52fcef573f (PUP-638) Add a pick_default() function that always returns a value.
This version of pick() does not error out, instead always returning at least
the last argument, even if that too has no "real" value.
2014-01-29 09:26:35 -08:00
Andrew Parker
a2e9d005c7 Merge pull request #215 from blkperl/add_root_home_to_mavericks
(PUP-1459) Add support for root_home on OS X 10.9
2014-01-28 10:52:58 -08:00
Henrik Lindberg
2c8450d830 (PUP-1195) Rephrase documentation for is_integer and is_numeric
The documentation contained references to future decisions about
functionality. 
Text rephrased for clarity.
2014-01-24 00:22:09 +01:00
Simon Effenberg
264dc9bbde (PUP-1195) Fix is_numeric/is_integer when checking non-string parameters
I expect a function called "is_numeric" or "is_integer" to check if a
variable is an integer or a number even if the variable passed by isn't
a string nor a number at all. Otherwise we should call them
is_string_a_number and is_string_an_integer and we have then to remove
the check for .is_a?(Number) and .is_a?(FixNum)

now checking also if it is a hex or octal number

improved/corrected checking for integer

* checking against Integer instead of Fixnum so that
  also Bignum is matching
* now .is_a? Integer is done first so this is quiet fast

Now many types of numerics are recognized.

1. Float/Integer values (signed or unsigned, with exponent or without)
2. octal and hex check
3. except hex numbers and the "0." in a float lower than 1 can be prefixed
   with a '0'.

whitespaces shouldn't be allowed as prefix/suffix

string representation of numbers should not contain any type of
whitespace.. the user is responsible to clean a string before checking
it..

fix documentation and added more checks

tried to be 99.9% backward compatible

* for now the decission is post poned if hex and octal numbers
  should be allowed or not (is_numeric)
* native Bignum is now also a valid integer class

fix problem with old 1.8 ruby and Hash.to_s/Array.to_s

In ruby < 1.9 array and hashes would be recognized as numeric
if they have a special format:

1.8:

  [1,2,3,4].to_s = "1234"
  {1=>2}.to_s    = "12"

1.9:

  [1,2,3,4].to_s = "[1, 2, 3, 4]"
  {1=>2}.to_s    = "{1=>2}"
2014-01-23 23:59:28 +01:00
William Van Hevelingen
fe676f0ac4 (PUP-1459) Add support for root_home on OS X 10.9
getent does not exist on 10.9 so this commit uses
dscacheutil to query the homedir for the root user.
2014-01-22 22:54:34 -08:00
Adrien Thebo
686a05aea2 (maint) refactor ensure_packages for clarity 2014-01-15 11:03:49 -08:00
Tomas Doran
735db82bef Allow a single argument, rather than an array 2014-01-15 11:03:33 -08:00
Franco Catena
7991dd2073 Fix prefix exception message (Closes #23364) 2013-12-20 14:50:57 -08:00
Joshua Hoblitt
1077881873 (#23381) add is_bool() function 2013-12-09 11:50:03 -07:00
Justin Burnham
199ca9c78b (#20200) Add a recursive merge function.
Issue #20200 notes that the merge function does not
support nested hashes.

To prevent unintended side effects with changing merge,
add a deep_merge function instead.
2013-10-29 12:22:49 -07:00
Matthew Haughton
57a5c0b3e3 (Main) fix typo in pick error message
Update pick error message "at least one non empty value"
2013-10-29 12:01:25 -07:00
Tehmasp Chaudhri
753801537f Fixed 'separator' typos 2013-10-25 15:26:21 -06:00
Adrien Thebo
d60d872c1a Merge branch 'pull-180'
This closes GH-180
2013-09-18 21:56:16 -07:00
sgzijl
9e0d8a8e0a (#22214): close content file before executing checkscript
Right now validation seems to be done against zero byte generated temp
files. We need to close the file before executing validation against it.
2013-09-18 21:32:07 -07:00
Adrien Thebo
7ccf8cf09b Merge pull request #184 from lmello/fix_bug_20681_delete_undef_values
delete_undef_values function fix bug #20681
2013-09-18 10:08:49 -07:00
Leonardo Rodrigues de Mello
80a8b7bd1f (#20681) fix behaviour of delete_undef_values
The issue #20681 describe the error of delete() function
removing the elements from the origin array/hash/string.

This issue affected other delete functions. Because
ruby delete and delete_if functions make destructive
changes to the origin array/hash.

The delete_undef_values removed elements from the
origin array/hash and this is not the desired behaviour.

To solve this, we should dup or clone the array/hash
before using the delete or delete_if ruby functions.

We should also check if args[0] is not nil before using
dup, since dup on nil raises exception.

This fix the problem and add unit tests, so we could
enforce this behaviour and prevent regressions.
2013-09-18 11:19:52 -03:00
Adrien Thebo
1011670bad Merge pull request #182 from lmello/fix_bug_20681_delete_values
delete_values() fix bug #20681.
2013-09-17 11:35:57 -07:00
Adrien Thebo
5cc5e293cf Merge pull request #178 from lmello/fix_bug_20681
bug # 20681 delete() function should not remove elements from original list
2013-09-17 11:07:21 -07:00
Leonardo Rodrigues de Mello
51d96088c1 (#20681) fix behaviour of delete_values
The issue #20681 describe the error of delete() function
removing the elements from the origin array/hash/string.

This issue affected other delete functions. Because
ruby delete and delete_if functions make destructive
changes to the origin array/hash.

The delete_undef_values removed elements from the
origin hash and this is not the desired behaviour.

To solve this, we should dup or clone the hash
before using the delete or delete_if ruby functions.

This fix the problem and add unit tests, so we could
enforce this behaviour and prevent regressions.
2013-09-17 12:05:23 -03:00
Adrien Thebo
ebec9de534 Merge pull request #179 from lmello/function_pick_error_msg
enhanced the error message of pick function.
2013-09-16 13:45:24 -07:00
Leonardo Rodrigues de Mello
c14cbf31e2 bug # 20681 delete() function should not remove elements from original list
The setup: list with 3 elements, delete one:
$test_list = [‘a’, ‘b’, ‘c’]
$test_deleted = delete($test_list, ‘a’)

Print out the elements in ‘test_deleted’:
notify { ‘group_output2’:  withpath => true, name     => “$cfeng::test_deleted”, }
Notice: /Stage[main]/Syslog/Notify[group_output2]/message: bc

Good!  Run-on output shows that ‘a’ was deleted

Print out the elements in ‘test_list’:
notify { ‘group_output1’: withpath => true, name     => “$cfeng::test_list”, }
Notice: /Stage[main]/Syslog/Notify[group_output1]/message: bc

WHAT!?  'a' was deleted from ‘test_list’ as well! Expected abc as output!

This behaviour is confirmed for string, hash and array.
This is fixed on this commit, I had  added two spec tests to cover that cases.

bug #20681 spec test for delete() function.

I had forgot in the last commit the spec test for hash in the
delete function.

bug # 20681 delete() function change aproach.

Instead of rejecting elements from the original list, we use
collection = arguments[0].dup .
then latter we could continue to use delete and gsub! on collection
without impact on original argument.

this is a better solution than the previous one, and works on ruby
1.8.7, 1.9.3 and 2.0.0.

The previous solution does not work on ruby 1.8.7.

delete function remove typo whitespace.

fix typo whitespaces.
2013-09-16 10:19:35 -03:00
Leonardo Rodrigues de Mello
30e994fb6e enhanced the error message of pick function.
When pick function fail return a better error message like
the other stdlib functions, indicating that the error
is on function pick.

This would help people that see the error to identity it is
related to a incorrect use of stdlib function pick, instead of having
to grep all puppet libraries and manifests source for the old message.

I had also changed the spec test.

pick function change spec  as suggested GH-179

Fix the spec test to use expect {}.to instead of lambda {}.should
as explained by Adrienthebo.

"Using expect { }.to is preferred over lambda { }.should.
 In addition it's best practice to do a string match against the
error message to ensure that we're catching the right error,
instead of any error of the right type."

Also fixed a typo on the error message, it was missing one space.

pick function stylish fix as suggested on GH179
2013-09-16 10:03:20 -03:00
Jeff McCune
948be0bb99 (maint) Improve the tests and readability of file_line
Without this patch the implementation of the file_line provider is a bit
convoluted with respect to the newly introduced "after" parameter.

This patch addresses the problem by separating out the concerns of each
case into their own methods of handling the behavior with the match
parameter, handling the behavior with the after parameter, or simply
appending the line.
2013-08-29 16:27:27 -07:00
Dan Prince
221277e852 Update file_line resource to support 'after'.
When adding new lines to a file the 'after' option can be useful
when you need to insert file lines into the middle of a file.

This is particularly helpful when using file_line with sectioned
config files.

NOTE: the after option only works when adding new lines. If you are
updating an existing (matched) line it will simply modify it in place.
This assumes it was in the right place to begin with.
2013-08-29 15:07:29 -07:00
Adrien Thebo
2a78cbfaad Merge pull request #170 from ptomulik/fix_delete_values
minor corrections to delete_values()
2013-08-13 10:27:42 -07:00
Adrien Thebo
24911db44c (maint) Validate input argument in a single location 2013-08-12 12:56:00 -07:00
Adrien Thebo
1950b605fb (maint) reindent case statement to match standard indentation 2013-08-12 12:55:46 -07:00
Adrien Thebo
b41883933c (maint) collapse String/Array validation into shared lambda 2013-08-12 12:55:46 -07:00
Adrien Thebo
6df05cbc2d (maint) clean up validate_slength argument validation 2013-08-12 12:55:46 -07:00
Adrien Thebo
e63715ddaf (maint) reword error messages for validate_slength 2013-08-12 11:20:46 -07:00
Adrien Thebo
2cfa408909 (maint) Explicitly unpack validate_slength args 2013-08-12 11:13:46 -07:00
Adrien Thebo
4ad1da83f9 (maint) Remove unneeded parens around exceptions 2013-08-12 11:00:27 -07:00
Paweł Tomulik
2ba5404b16 minor corrections to delete_values() 2013-08-08 16:56:32 +02:00
Hubert
77625e6d8f Fix validate_slength, arg.length should be args[0].length
During a puppet run an error will be thrown and a puppet run will fail completely (when using validate_slength):
undefined local variable or method `arg' for #<Puppet::Parser::Scope:0x7f243c236948>
2013-08-08 12:56:12 +02:00
Adrien Thebo
0a02295c42 Merge pull request #167 from mhellmic/minlength
extend the validate_slength function to accept a minimum length
2013-08-06 09:48:44 -07:00
Martin Hellmich
0206d367c0 changed the validate_slength function to accept a min length
An optional third parameter can be given a min length. The function
then only passes successfully, if all strings are in the range
min_length <= string <= max_length

update and fix function and unit tests

the check for the minlength has to be written differently
because 0 values should be possible. We now check
a) if the input is convertible, and throw a ParseError and
b) if the input .is_a?(Numeric) and ask for a positive number
it's not as clean as for maxlength, but keeps a similar behaviour

refined the error checking for the min length

try to convert to Integer(args[2]) and fail,
if it's not possible

changed the tests accordingly to the new parameter checking
2013-08-06 10:05:16 +02:00
Paweł Tomulik
2069415204 added delete_values() and delete_undef_values() functions 2013-08-05 22:12:26 +02:00
Tomas Doran
b2e23dc65b Adjust to use default URI.escape escape list
Conform to RFC per comments on: https://github.com/puppetlabs/puppetlabs-stdlib/pull/164

Conflicts:
	lib/puppet/parser/functions/uriescape.rb
	spec/unit/puppet/parser/functions/uriescape_spec.rb
2013-07-22 13:12:28 -07:00
Adrien Thebo
e0d4588bd2 Merge branch 'pull-163'
This closes GH-163
2013-07-11 16:26:45 -07:00
Alex O'Rielly
964a9ad619 (#21416) Allow file_line to match multiple lines
Without this commit the file_line type will outright fail if multiple
lines match the given regex. This commit allows the file_line type and
provider to optionally match and modify all matching lines.

Changeset rebased into a single commit by Adrien Thebo <adrien@puppetlabs.com>
2013-07-11 16:25:56 -07:00
Chris Boot
7f98203f18 ensure_resource: fix documentation typo 2013-06-27 17:51:36 +01:00
Adrien Thebo
ca7633c0e4 Merge pull request #158 from wfarr/validate_ip
[#20862] Add functions to validate ipv4 and ipv6 addresses
2013-06-07 15:06:41 -07:00
Adrien Thebo
0f2d69fdfd Merge remote-tracking branch 'pr/56' into pull-56
Conflicts:
	lib/puppet/parser/functions/range.rb
	spec/unit/puppet/parser/functions/range_spec.rb
2013-05-28 11:07:41 -07:00
fiddyspence
3707c47dcd Adding base64 function
Adding base64 function and spec test.  Included a bonus fix to
validate_slength_spec.rb to put the expectation message in the right
place.
2013-05-24 16:33:24 +01:00
Will Farrington
9a41f07e3b Ruby 2.0 introduces IPAddr::InvalidAddressError 2013-05-22 17:21:38 -07:00
Will Farrington
cf37a128a0 Add functions to validate ipv4 and ipv6 addresses 2013-05-22 17:10:45 -07:00
Hailee Kenney
a2abfb9894 Merge pull request #155 from AlexCline/feature/master/array_comparison_functions
(#20684) Add array comparison functions, difference, intersection and union
2013-05-15 13:56:15 -07:00
Adrien Thebo
dad3a2948f Merge pull request #147 from mhellmic/master
don't fail on undef variable in merge
2013-05-15 10:58:04 -07:00
Alex Cline
737aa31546 (#20684) Add array comparison functions, difference, intersection and union.
Included is code, tests and documentation for the difference, intersection
and union functions for comparing arrays.
2013-05-13 12:14:15 -04:00
Martin Hellmich
f496005bf3 fix in merge.rb: refine the checking if an argument is an empty string 2013-05-08 18:24:07 +02:00