Commit graph

471 commits

Author SHA1 Message Date
Mark McKinstry
6de1a6e062 add functionality to bool2str to return strings of your choice for a boolean 2015-10-15 22:22:10 -04:00
Jesse Lovelace
6aa7f2db99 Add check to ensure regex does not throw for none type.
Add a quick check to ensure puppetversion value is not nil and supporting test.
2015-10-15 11:27:03 -05:00
Colleen Murphy
25410c4598 Let load_module_metadata succeed on empty file
Some modules or module versions don't have a metadata.json file, but we
might still want to use the load_module_metadata function on them. The
lack of a file can still give us important information. For example, it
might tell us that the version of the module installed is "very old"
even if we can't read the version number directly. This patch adds a
parameter to let the user specify if an empty file is acceptable. To
preserve backwards compatibility it does not change the current default
behavior, which is to raise an error if metadata.json does not exist.
2015-10-14 16:16:01 -07:00
David Schmitt
ad173f2d05 (MODULES-2421) improve description of file_line
This mostly needed extraction of the existing doc strings from
the type.
2015-10-13 15:03:26 +01:00
Martin Pfeifer
d73fd3c5ef prevent deprecation warning about the allow_virtual parameter 2015-10-13 10:08:01 +02:00
Bryan Jen
e1a9bf5063 Merge pull request #534 from asasfu/feature/package_provider_fact
Add package_provider fact
2015-10-01 10:27:51 -07:00
Roman Mueller
6f1d164da6 Check for numeric values as empty fails on those 2015-09-28 16:01:11 +01:00
Adam S
440245d40d fixup-PR#506 Speed improvements in facter resolution
This is to improve speed on Facter resolution of service_provider fact
that was just introduced in PR# 506.  The improvements go from 280ms
resolution time approx. down to 2ms resolution time approx. by adding
requires statements.
2015-09-25 18:06:00 -07:00
Adam S
ce6e8679b6 Add package_provider fact
This adds a package_provider fact for situations where we need to be
able to know the client's package provider in a simple way.  Situations
such as: package { 'name': install_options => [] }  As those tend to be
package provider specific options.
2015-09-25 17:55:21 -07:00
Hunter Haugen
4d1bca3359 Merge pull request #506 from binford2k/feature/service_provider_fact
Add a service_provider fact
2015-09-24 10:55:39 -07:00
Morgan Haskel
799c38e14e Fix backwards compatibility from #511
Maintain the old behavior in the case where the optional second
parameter isn't passed. Also, adding arity is backwards incompatible since
stdlib still supports 2.7, so remove that.
2015-09-21 11:11:21 -07:00
David Schmitt
55ece7815a (MAINT) validate_re: Clarify docs and error message 2015-09-17 18:48:32 +01:00
Ben Ford
169f8af506 Clarify what an empty intersection looks like. 2015-09-14 11:25:38 -07:00
Bryan Jen
0ea0e40228 Merge pull request #523 from DavidS/modules-2516-is_a
(MODULES-2561) add is_a function
2015-09-14 10:49:50 -07:00
Bryan Jen
c0df8192ee Merge pull request #511 from dmitryilyin/parseyaml_default
[MODULES-2462] Improve parseyaml function
2015-09-14 10:40:35 -07:00
David Schmitt
00c881d0da (MODULES-2516) Adds an is_a() function
The data type system is very hard to understand. Many people don't
understand why

    type_of([1,2,3]) == Array

will fail, but

    type_of([1,2,3]) <= Array

passes. This does a simpler validation that doesn't rely on explicit
data types. Instead, use

    $foo = [1,2,3]
    if $foo.is_a(Array) {
      notify { 'This is an array': }
    }

This is based on code by Ben Ford <ben.ford@puppetlabs.com>.

  * Added acceptance tests
  * Added dispatch
  * Improved unit tests
  * Added docs to README
2015-09-14 18:26:25 +01:00
Corey Osman
f2f2db4795 accept any case of boolean strings
* previously the str2bool function did not accept 'TRUE' as a bool
    type.  This causes the function to now accept TRUE, FALSE strings
    as a boolean type in order to be converted to a proper boolean.
  * This would also cause Y,N, YES, NO to be accepted as boolean types
    as well.
2015-09-04 08:09:26 -07:00
David Schmitt
64267eb650 Merge pull request #513 from dmitryilyin/fetch
Add a new function "try_get_value"
2015-09-02 09:23:46 +01:00
Dmitry Ilyin
823a352f0f Add a new function "try_get_value"
* Extracts a value from a deeply-nested data structure
* Returns default if a value could not be extracted
2015-09-01 21:45:44 +03:00
Jon Fautley
6c2a003f21 (MODULES-2478) Support root_home fact on AIX through "lsuser" command
Squashed, and amended test for comment lines.
2015-08-28 15:21:13 +01:00
fhats
2d4f5aa4d9 Adds a convert_base function, which can convert numbers between bases
Squashed, improved docs, updated error handling and unit tests by David S.
2015-08-27 10:42:13 +01:00
Dmitry Ilyin
eb948c4a0d [MODULES-2462] Improve parseyaml function
* Add default value support
  Second argument will be returned if yaml cannot be parsed
  instead of false value
* Update tests
2015-08-25 21:41:03 +03:00
Jetroid
1d9189d860 (MODULE-2456) Modify union to accept more than two arrays
Add spec tests to test the new functionality:
 *Case for 3 arrays.
 *Case for 4 arrays.
Modify README to note new functionality.

This is for issue MODULE-2456, follow the precedent of MODULE-444.

This change allows union to be much more useful, unioning many arrays
in one line rather than in n lines. Additionally, as this is only added
functionality, and does not affect the 2 array case that all modules
currently using array are using, it should not affect any existing
modules utilizing union.

This is now useful, for example, for merging many arrays of resources
(eg: packages.) to generate just one list with no duplicates, to avoid
duplicate resource declarations.
2015-08-24 14:24:10 +01:00
Ben Ford
66e118a92a Add a service_provider fact
This returns the default provider Puppet will choose to manage services
on this system by instantiating a dummy service resource type and
returning the provider chosen.

Co-Authored-By: Simon Fraser University <asa188@sfu.ca>
2015-08-19 15:05:47 -07:00
Nigel Gibbs
4cbe846750 (MODULES-2410) Add new functions dos2unix and unix2dos 2015-08-14 13:30:01 +01:00
Johnson Earls
9bacf14ca2 allow match parameter to influence ensure => absent behavior.
Split the `destroy` method of the file_type::ruby provider into two
private methods:  `handle_destroy_line` which is the same as the previous
`destroy` method, and `handle_destroy_with_match` which will destroy any
line which matches the `match` parameter, raising an error if multiple
lines match and the `multiple` parameter is not `true`.  This new
behavior is only used if the new boolean parameter `match_for_absence`
is `true` (it defaults to `false`).
2015-08-06 13:44:32 -07:00
Dominic Cleal
a7adcda803 (MODULES-2316) Change file_type boolean parameter to symbols
Puppet's boolean parameter type is only available in Puppet 3.3 and
higher, so change file_type's new "replace" parameter to a regular
parameter with true and false as possible values.  This matches the
existing "multiple" parameter.
2015-08-04 09:59:53 +01:00
Hunter Haugen
e815da5962 Merge pull request #483 from nibalizer/load_metadata_json
Add load_metadata_json function
2015-07-31 14:12:56 -07:00
Spencer Krum
f411ee7119 Add load_metadata_json function
This function loads the metadata.json into a puppet variable. This enables a number of neat things such as:

* Which version of the module am I using? 2.x? 3.x?
* Which author of the module am I using? puppetlabs? example42?
2015-07-30 15:51:54 -07:00
Zee Alexander
aca29129cb Remove colorful language from module. 2015-07-30 15:11:26 -07:00
Raymond Maika
35e92645f7 (MODULES-2024) Adding replace attribute to file_line 2015-07-30 14:55:32 -04:00
gcmalloc
5c79107863 adding support for hash in the size function 2015-07-22 12:11:52 +02:00
Dan Offord
939aceffad Fix documentation error in upcase
The documentation example shows an incorrect response when using the
function, this PR corrects the example to agree with what the function
actually does.
2015-07-20 18:00:09 +01:00
Morgan Haskel
07c38e518a Merge pull request #482 from DavidS/document_validate_slength_3rd_arg
Add validate_slength's optional 3rd arg to README
2015-07-09 10:20:37 -07:00
Alexander Fisher
c64ecfb0c3 Add validate_slength's optional 3rd arg to README 2015-07-09 18:13:19 +01:00
Mathias Klette
e96a818782 catch and rescue from looking up non-existent facts when looking for 'kind'
facter (2.x) only provides facts without interface suffix for
 * ipaddress
 * netmask

'macaddress' and 'network' facts will always have the related interface
name appended. in turns lookupvar throws errors when strict_variables is
enabled.
2015-06-24 15:02:02 +02:00
Tomas Doran
212c498df3 Also catch :undefined_variable as thrown by future parser 2015-06-05 12:43:01 +01:00
Hunter Haugen
ad4ca4cc34 Fix time() on 1.8.7
The time() function takes an argument of a timezone, and always returns
time in epoch format. The epoch format is the number of seconds that
have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap
seconds. This means that it is universally the same regardless of
timezones.

I don't know what the timezone argument is supposed to do, and it is not
documented. So lets just make 1.8.7 work like > 1.8.7
2015-06-04 09:40:52 -07:00
Eli Young
d7c8460353 fqdn_rotate: Improve documentation 2015-06-01 16:19:07 -07:00
Eli Young
601f681787 fqdn_rotate: Don't use the value itself as part of the random seed
Previously, the random number generator was seeded with the array or
string to be rotated in addition to any values specifically provided for
seeding. This behavior is potentially insecure in that it allows an
attacker who can modify the source data to choose the post-shuffle
order.
2015-06-01 16:19:07 -07:00
David Schmitt
f3e79ddcd5 Convert tests to use plain rspec-puppet
Tests in the new style produces the following documentation output:

abs
  should not eq nil
  should run abs() and raise an Puppet::ParseError
  should run abs(-34) and return 34
  should run abs("-34") and return 34
  should run abs(34) and return 34
  should run abs("34") and return 34
2015-06-01 18:02:22 +01:00
Igor Galić
687600c30c simplify mac address regex
let the computer do the counting and repetition and case
2015-05-29 20:13:21 +02:00
David Schmitt
4a8c0a57f2 Merge pull request #463 from CENGN/fix/master/file_line_multiple_after
(MODULES-2071) Patch file_line provider to use multiple with after
2015-05-29 10:21:41 +01:00
Raymond Maika
72089f3d13 (MODULES-2071) Refactor file_line provider to contain logic to handle parameter multiple in function handle_create_with_after
Without this, file_line resource without the `match` parameter but with the `after` param will throw an error if there are multiple matches for the after expression. This patch creates the handling for the `multiple` parameter in handle_create_with_after. This allows you to add a line after the `after` expression if it appears at multiple points in a file.

Updated reference to `file_line` in the README to reflect that the multiple parameter can be set when using `after` and/or `match` as the matching regex.
2015-05-29 00:30:44 -04:00
David Schmitt
cf9f7a6b7e validate_integer, validate_numeric: explicitely reject hashes in arrays
Without this patch, Ruby 1.8's Hash#to_s behaviour causes [{1=>2}] to be
treated as "12" when validating values.
2015-05-27 20:05:05 +01:00
David Schmitt
0dc0e0dbcf fqdn_rotate: reset srand seed correctly on old ruby versions
Without this, the global seed is reseeded on every use
of fqdn_rotate, which is a waste. Older rubies might even use a
time-base seed which adversly impacts the quality of the RNG.
2015-05-26 14:25:43 +01:00
Eli Young
3b8ded184d (FM-2130) Document new location of facts.d cache 2015-05-11 11:12:15 -07:00
David Schmitt
f49eb6b8e2 range(): fix TypeError(can't convert nil into Integer) when using range syntax 2015-05-06 10:13:27 +01:00
David Schmitt
cf251303be Merge pull request #447 from elyscape/fix_range
Restore removed functionality to range()
2015-05-06 09:48:31 +01:00
Eli Young
25ed4b43c4 range: Clean up and clarify function contents 2015-05-05 16:06:35 -07:00
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