Skip to content

Commit 51fdefb

Browse files
authored
Merge branch 'main' into fix-readjson
2 parents 4f56e45 + 76e9ddc commit 51fdefb

File tree

6 files changed

+207
-22
lines changed

6 files changed

+207
-22
lines changed

CHANGELOG.md

+32-20
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,23 @@ All notable changes to this project will be documented in this file.
55

66
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).
77

8-
## [v9.4.1](https://github.com./puppetlabs/puppetlabs-stdlib/tree/v9.4.1) - 2023-11-08
8+
## [v9.5.0](https://github.com./puppetlabs/puppetlabs-stdlib/tree/v9.5.0) - 2024-03-11
9+
10+
[Full Changelog](https://github.com./puppetlabs/puppetlabs-stdlib/compare/v9.4.1...v9.5.0)
11+
12+
### Added
13+
14+
- Add function stdlib::sort_by [#1384](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1384) ([XMol](https://github.com./XMol))
15+
16+
### Fixed
17+
18+
- (#1389) - pw_hash with bcrypt not working on puppet master [#1410](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1410) ([TuningYourCode](https://github.com./TuningYourCode))
19+
20+
### Other
21+
22+
- Deprecate `time` function [#1417](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1417) ([alexjfisher](https://github.com./alexjfisher))
23+
24+
## [v9.4.1](https://github.com./puppetlabs/puppetlabs-stdlib/tree/v9.4.1) - 2023-11-09
925

1026
[Full Changelog](https://github.com./puppetlabs/puppetlabs-stdlib/compare/v9.4.0...v9.4.1)
1127

@@ -21,10 +37,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
2137

2238
- Modernise `fqdn_rotate` function [#1341](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1341) ([alexjfisher](https://github.com./alexjfisher))
2339

24-
### Other
25-
26-
- Remove unused parser deprecation function [#1392](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1392) ([ekohl](https://github.com./ekohl))
27-
2840
## [v9.3.0](https://github.com./puppetlabs/puppetlabs-stdlib/tree/v9.3.0) - 2023-08-01
2941

3042
[Full Changelog](https://github.com./puppetlabs/puppetlabs-stdlib/compare/v9.2.0...v9.3.0)
@@ -68,11 +80,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6880

6981
[Full Changelog](https://github.com./puppetlabs/puppetlabs-stdlib/compare/v8.6.0...v9.0.0)
7082

71-
### Added
72-
73-
- Namespace Puppet 4.x functions [#1356](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1356) ([smortex](https://github.com./smortex))
74-
- Add a function to update / regenerate deprecated shims [#1349](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1349) ([smortex](https://github.com./smortex))
75-
7683
### Changed
7784
- Deprecate the `validate_legacy()` function [#1353](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1353) ([smortex](https://github.com./smortex))
7885
- Remove deprecated functions [#1352](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1352) ([smortex](https://github.com./smortex))
@@ -108,6 +115,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
108115
- Remove deprecated type and type3x functions [#1309](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1309) ([MartyEwings](https://github.com./MartyEwings))
109116
- (CONT-801) Puppet 8 support / Drop Puppet 6 support [#1307](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1307) ([LukasAud](https://github.com./LukasAud))
110117

118+
### Added
119+
120+
- Namespace Puppet 4.x functions [#1356](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1356) ([smortex](https://github.com./smortex))
121+
- Add a function to update / regenerate deprecated shims [#1349](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1349) ([smortex](https://github.com./smortex))
122+
111123
### Fixed
112124

113125
- Remove deprecated File.exists? [#1357](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1357) ([ekohl](https://github.com./ekohl))
@@ -226,18 +238,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
226238

227239
[Full Changelog](https://github.com./puppetlabs/puppetlabs-stdlib/compare/v7.1.0...v8.0.0)
228240

241+
### Changed
242+
- Flip installed and present in Function ensure_packages [#1196](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1196) ([cocker-cc](https://github.com./cocker-cc))
243+
229244
### Added
230245

231246
- New function to_python() / to_ruby() [#1200](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1200) ([smortex](https://github.com./smortex))
232247
- pdksync - (IAC-1709) - Add Support for Debian 11 [#1199](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1199) ([david22swan](https://github.com./david22swan))
233248
- Stdlib::Http::Method: Add new type for http methods [#1192](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1192) ([b4ldr](https://github.com./b4ldr))
234249

235-
### Changed
236-
- Flip installed and present in Function ensure_packages [#1196](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1196) ([cocker-cc](https://github.com./cocker-cc))
237-
238250
### Fixed
239251

240-
- (MODULES-11099) Make merge parameter data types actually backwards compatible [#1191](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1191) ([SimonPe](https://github.com./SimonPe))
252+
- (MODULES-11099) Make merge parameter data types actually backwards compatible [#1191](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1191) ([LadyNamedLaura](https://github.com./LadyNamedLaura))
241253

242254
## [v7.1.0](https://github.com./puppetlabs/puppetlabs-stdlib/tree/v7.1.0) - 2021-05-17
243255

@@ -259,13 +271,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
259271

260272
[Full Changelog](https://github.com./puppetlabs/puppetlabs-stdlib/compare/v6.6.0...v7.0.0)
261273

274+
### Changed
275+
- pdksync - Remove Puppet 5 from testing and bump minimal version to 6.0.0 [#1164](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1164) ([carabasdaniel](https://github.com./carabasdaniel))
276+
262277
### Added
263278

264279
- Stdlib::Email type [#1160](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1160) ([b4ldr](https://github.com./b4ldr))
265280

266-
### Changed
267-
- pdksync - Remove Puppet 5 from testing and bump minimal version to 6.0.0 [#1164](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1164) ([carabasdaniel](https://github.com./carabasdaniel))
268-
269281
### Fixed
270282

271283
- (bugfix) Setting stricter email validation [#1163](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1163) ([pmcmaw](https://github.com./pmcmaw))
@@ -367,14 +379,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
367379

368380
[Full Changelog](https://github.com./puppetlabs/puppetlabs-stdlib/compare/5.2.0...v6.0.0)
369381

382+
### Changed
383+
- pdksync - (MODULES-8444) - Raise lower Puppet bound [#1011](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1011) ([david22swan](https://github.com./david22swan))
384+
370385
### Added
371386

372387
- (MODULES-8760) Add iterative feature to merge() function [#1008](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1008) ([hlindberg](https://github.com./hlindberg))
373388
- Add a stdlib::ip_in_range() function [#1003](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1003) ([iglov](https://github.com./iglov))
374389

375-
### Changed
376-
- pdksync - (MODULES-8444) - Raise lower Puppet bound [#1011](https://github.com./puppetlabs/puppetlabs-stdlib/pull/1011) ([david22swan](https://github.com./david22swan))
377-
378390
## [5.2.0](https://github.com./puppetlabs/puppetlabs-stdlib/tree/5.2.0) - 2019-01-18
379391

380392
[Full Changelog](https://github.com./puppetlabs/puppetlabs-stdlib/compare/5.1.0...5.2.0)

REFERENCE.md

+70
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ Puppet structure
139139
* [`stdlib::seeded_rand_string`](#stdlib--seeded_rand_string): Generates a consistent random string of specific length based on provided seed.
140140
* [`stdlib::sha256`](#stdlib--sha256): Run a SHA256 calculation against a given value.
141141
* [`stdlib::shell_escape`](#stdlib--shell_escape): Escapes a string so that it can be safely used in a Bourne shell command line.
142+
* [`stdlib::sort_by`](#stdlib--sort_by): Sort an Array, Hash or String by mapping values through a given block.
142143
* [`stdlib::start_with`](#stdlib--start_with): Returns true if str starts with one of the prefixes given. Each of the prefixes should be a String.
143144
* [`stdlib::str2resource`](#stdlib--str2resource): This converts a string to a puppet resource.
144145
* [`stdlib::time`](#stdlib--time): This function is deprecated. It implements the functionality of the original non-namespaced stdlib `time` function.
@@ -4003,6 +4004,75 @@ Data type: `Any`
40034004

40044005
The string to escape
40054006

4007+
### <a name="stdlib--sort_by"></a>`stdlib::sort_by`
4008+
4009+
Type: Ruby 4.x API
4010+
4011+
Sort an Array, Hash or String by mapping values through a given block.
4012+
4013+
#### Examples
4014+
4015+
##### Sort local devices according to their used space.
4016+
4017+
```puppet
4018+
$facts['mountpoints'].stdlib::sort_by |$m| { $m.dig(1, 'used_bytes') }
4019+
```
4020+
4021+
#### `stdlib::sort_by(Array $ary, Callable[1,1] &$block)`
4022+
4023+
The stdlib::sort_by function.
4024+
4025+
Returns: `Array` Returns an ordered copy of ary.
4026+
4027+
##### `ary`
4028+
4029+
Data type: `Array`
4030+
4031+
The Array to sort.
4032+
4033+
##### `&block`
4034+
4035+
Data type: `Callable[1,1]`
4036+
4037+
The block for transforming elements of ary.
4038+
4039+
#### `stdlib::sort_by(String $str, Callable[1,1] &$block)`
4040+
4041+
The stdlib::sort_by function.
4042+
4043+
Returns: `String` Returns an ordered copy of str.
4044+
4045+
##### `str`
4046+
4047+
Data type: `String`
4048+
4049+
The String to sort.
4050+
4051+
##### `&block`
4052+
4053+
Data type: `Callable[1,1]`
4054+
4055+
The block for transforming elements of str.
4056+
4057+
#### `stdlib::sort_by(Hash $hsh, Variant[Callable[1,1], Callable[2,2]] &$block)`
4058+
4059+
The stdlib::sort_by function.
4060+
4061+
Returns: `Hash` Returns an ordered copy of hsh.
4062+
4063+
##### `hsh`
4064+
4065+
Data type: `Hash`
4066+
4067+
The Hash to sort.
4068+
4069+
##### `&block`
4070+
4071+
Data type: `Variant[Callable[1,1], Callable[2,2]]`
4072+
4073+
The block for transforming elements of hsh.
4074+
The block may have arity of one or two.
4075+
40064076
### <a name="stdlib--start_with"></a>`stdlib::start_with`
40074077

40084078
Type: Ruby 4.x API
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# frozen_string_literal: true
2+
3+
# @summary Sort an Array, Hash or String by mapping values through a given block.
4+
#
5+
# @example Sort local devices according to their used space.
6+
# $facts['mountpoints'].stdlib::sort_by |$m| { $m.dig(1, 'used_bytes') }
7+
#
8+
Puppet::Functions.create_function(:'stdlib::sort_by') do
9+
# @param ary The Array to sort.
10+
# @param block The block for transforming elements of ary.
11+
# @return [Array] Returns an ordered copy of ary.
12+
dispatch :sort_by_array do
13+
param 'Array', :ary
14+
block_param 'Callable[1,1]', :block
15+
end
16+
17+
# @param str The String to sort.
18+
# @param block The block for transforming elements of str.
19+
# @return [String] Returns an ordered copy of str.
20+
dispatch :sort_by_string do
21+
param 'String', :str
22+
block_param 'Callable[1,1]', :block
23+
end
24+
25+
# @param hsh The Hash to sort.
26+
# @param block The block for transforming elements of hsh.
27+
# The block may have arity of one or two.
28+
# @return [Hash] Returns an ordered copy of hsh.
29+
dispatch :sort_by_hash do
30+
param 'Hash', :hsh
31+
block_param 'Variant[Callable[1,1], Callable[2,2]]', :block
32+
end
33+
34+
def sort_by_iterable(iterable, &block)
35+
Puppet::Pops::Types::Iterable.asserted_iterable(self, iterable).sort_by(&block)
36+
end
37+
38+
def sort_by_array(ary, &block)
39+
sort_by_iterable(ary, &block)
40+
end
41+
42+
def sort_by_string(str, &block)
43+
sort_by_iterable(str, &block).join
44+
end
45+
46+
def sort_by_hash(hsh, &block)
47+
sort_by_iterable(hsh, &block).to_h
48+
end
49+
end

lib/puppet/parser/functions/pw_hash.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
# handle weak implementations of String#crypt
7878
# dup the string to get rid of frozen status for testing
79-
if RUBY_PLATFORM == 'java'
79+
if RUBY_PLATFORM == 'java' && !args[1].downcase.start_with?('bcrypt')
8080
# puppetserver bundles Apache Commons Codec
8181
org.apache.commons.codec.digest.Crypt.crypt(password.to_java_bytes, salt)
8282
elsif (+'test').crypt('$1$1') == '$1$1$Bp8CU9Oujr9SSEw53WV6G.'

metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "puppetlabs-stdlib",
3-
"version": "9.4.1",
3+
"version": "9.5.0",
44
"author": "puppetlabs",
55
"summary": "Standard library of resources for Puppet modules.",
66
"license": "Apache-2.0",

spec/functions/sort_by_spec.rb

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'stdlib::sort_by' do
6+
it { is_expected.not_to be_nil }
7+
8+
describe 'raise exception with inappropriate parameters' do
9+
it { is_expected.to run.with_params.and_raise_error(ArgumentError, Regexp.new('expects 1 argument, got none')) }
10+
it { is_expected.to run.with_params([]).and_raise_error(ArgumentError, Regexp.new('expects a block')) }
11+
it { is_expected.to run.with_params(:undef).and_raise_error(ArgumentError, Regexp.new("rejected: parameter 'ary' expects an Array value, got Undef")) }
12+
it { is_expected.to run.with_params(true).and_raise_error(ArgumentError, Regexp.new("rejected: parameter 'ary' expects an Array value, got Boolean")) }
13+
it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, Regexp.new("rejected: parameter 'ary' expects an Array value, got Integer")) }
14+
it { is_expected.to run.with_params({}).with_lambda { 1 }.and_raise_error(ArgumentError, Regexp.new('block expects between 1 and 2 arguments, got none')) }
15+
end
16+
17+
# Puppet's each iterator considers Integers, Strings, Arrays and Hashes to be Iterable.
18+
unordered_array = ['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']
19+
ordered_array = ['The', 'brown', 'dog', 'fox', 'jumps', 'lazy', 'over', 'quick', 'the']
20+
unordered_hash = { 'The' => 'quick', 'brown' => 'fox', 'jumps' => 'over', 'the' => 'lazy', 'dog' => '.' }
21+
ordered_hash = { 'dog' => '.', 'brown' => 'fox', 'the' => 'lazy', 'jumps' => 'over', 'The' => 'quick' }
22+
unordered_string = 'The quick brown fox jumps over the lazy dog.'
23+
ordered_string = ' .Tabcdeeefghhijklmnoooopqrrstuuvwxyz'
24+
25+
describe 'with sane input' do
26+
it 'does sort Array' do
27+
expect(subject).to run \
28+
.with_params(unordered_array) \
29+
.with_lambda { |e| e } \
30+
.and_return(ordered_array)
31+
end
32+
33+
it 'does sort Hash by entry' do
34+
expect(subject).to run \
35+
.with_params(unordered_hash) \
36+
.with_lambda { |e| e[1] } \
37+
.and_return(ordered_hash)
38+
end
39+
40+
it 'does sort Hash by key-value pairs' do
41+
expect(subject).to run \
42+
.with_params(unordered_hash) \
43+
.with_lambda { |_, v| v } \
44+
.and_return(ordered_hash)
45+
end
46+
47+
it 'does sort String' do
48+
expect(subject).to run \
49+
.with_params(unordered_string) \
50+
.with_lambda { |e| e } \
51+
.and_return(ordered_string)
52+
end
53+
end
54+
end

0 commit comments

Comments
 (0)