Codebase list libconfig-model-backend-augeas-perl / 0e031d8
Update upstream source from tag 'upstream/0.126' Update to upstream version '0.126' with Debian dir d43fae4f9b13ceb32cfef427e381b49a7fcfee6e Dominique Dumont 2 years ago
6 changed file(s) with 62 addition(s) and 51 deletion(s). Raw diff Collapse all Expand all
4545 'Test::More' => 0,
4646 'Test::Exception' => 0,
4747 'Test::Differences' => 0,
48 'Test::Warn' => '0.11', # tests fail with 0.08
4948 'version' => '0.77'
5049 },
5150
0 2021-12-29 Dominique Dumont <domi.dumont@free.fr> v0.126
1
2 * fix doc related to backend configuration
3 * fix grammar errors in doc
4 * fix tests broken by Augeas 1.13.0
5 * rm dependency on Test::Warn
6
07 2018-02-26 Dominique Dumont <domi.dumont@free.fr> v0.125
18
29 * fix wiki url
2121 "Test::Differences" : "0",
2222 "Test::Exception" : "0",
2323 "Test::More" : "0",
24 "Test::Warn" : "0.11",
2524 "version" : "0.77"
2625 }
2726 },
4241 "provides" : {
4342 "Config::Model::Backend::Augeas" : {
4443 "file" : "lib/Config/Model/Backend/Augeas.pm",
45 "version" : "0.125"
44 "version" : "0.126"
4645 }
4746 },
4847 "release_status" : "stable",
5150 "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt"
5251 ]
5352 },
54 "version" : "0.125",
53 "version" : "0.126",
5554 "x_serialization_backend" : "JSON::PP version 4.04"
5655 }
88 Test::Differences: '0'
99 Test::Exception: '0'
1010 Test::More: '0'
11 Test::Warn: '0.11'
1211 version: '0.77'
1312 configure_requires:
1413 Module::Build: '0.36'
2221 provides:
2322 Config::Model::Backend::Augeas:
2423 file: lib/Config/Model/Backend/Augeas.pm
25 version: '0.125'
24 version: '0.126'
2625 requires:
2726 Config::Augeas: '0.303'
2827 Config::Model: '2.117'
3029 Mouse: '0'
3130 resources:
3231 license: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
33 version: '0.125'
32 version: '0.126'
3433 x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
3232 eval { require Config::Augeas; };
3333 $has_augeas = 0 if $@;
3434
35 our $VERSION = '0.125';
35 our $VERSION = '0.126';
3636
3737 my $logger = get_logger('Backend::Augeas');
3838
4646 {
4747 config_class_name => 'OpenSsh::Sshd',
4848
49 # try Augeas and fall-back with custom method
50 read_config => [ { backend => 'augeas' ,
51 file => '/etc/ssh/sshd_config',
52 # declare "seq" Augeas elements
53 sequential_lens => [/AcceptEnv AllowGroups [etc]/],
54 },
55 { backend => 'custom' , # dir hardcoded in custom class
56 class => 'Config::Model::Sshd'
57 }
58 ],
59 # write_config will be written using read_config specifications
60
49 read_config => {
50 backend => 'augeas' ,
51 file => '/etc/ssh/sshd_config',
52 # declare "seq" Augeas elements
53 sequential_lens => [/AcceptEnv AllowGroups [etc]/],
54 },
55
56 # config is written back using read_config specifications
6157
6258 element => ...
6359 }
6662
6763 This class provides a way to load or store configuration data through
6864 L<Config::Augeas>. This way, the structure and comments of the
69 original configuration file will preserved.
65 original configuration file are preserved.
7066
7167 To use Augeas as a backend, you must specify the following
7268 C<read_config> parameters:
9692
9793 For instance:
9894
99 read_config => [ { backend => 'augeas' ,
100 save => 'backup',
101 file => '/etc/ssh/sshd_config',
102 # declare "seq" Augeas elements
103 sequential_lens => [/AcceptEnv AllowGroups/],
104 },
105 ],
106
95 read_config => {
96 backend => 'augeas' ,
97 save => 'backup',
98 file => '/etc/ssh/sshd_config',
99 # declare "seq" Augeas elements
100 sequential_lens => [/AcceptEnv AllowGroups/],
101 },
107102
108103 =head2 Sequential lens
109104
150145 /files/etc/ssh/sshd_config/AcceptEnv[2]/4
151146 /files/etc/ssh/sshd_config/AcceptEnv[2]/5
152147
153 Note that the first index between squarekeeps track of how are grouped
154 the C<AcceptEnv> data, but the I<real> list index is after the slash.
148 Note that the first index between square brackets keeps track of how
149 the C<AcceptEnv> items are grouped, but the I<real> list index is
150 after the slash.
155151
156152 Augeas does not require new elements to create C<AcceptEnv[3]>. A new
157153 element can be added as :
250246 # the model. I.e if the file "root" matches a list element (like
251247 # for /etc/hosts), get this element name from "set_in" parameter
252248 my $set_in = $args{set_in} || '';
253 map {
254 s!$mainpath!!;
255 $_ = "/$set_in/$_" if $set_in;
256 s!/+!/!g;
257 } @cm_path;
249 foreach my $path (@cm_path) {
250 $path =~ s!$mainpath!!;
251 $path = "/$set_in/$path" if $set_in;
252 $path =~ s!/+!/!g;
253 }
258254
259255 # Create a hash of sequential lenses
260256 my %is_seq_lens = map { ( $_ => 1 ); } @{ $args{sequential_lens} || [] };
500496 # fail. But Augeas does return foo/1 if only one element is
501497 # present in the tree :-/
502498 my $replace = $element_name . '[1]';
503 map { s/$element_name(?!\[)/$replace/ } @matches;
499 foreach (@matches) {
500 s/$element_name(?!\[)/$replace/;
501 }
504502 }
505503
506504 my $logger = get_logger("Data::Write");
584582 # the tree :-/
585583 if ($is_seq) {
586584 my $replace = $element_name . '[1]';
587 map { s/$element_name(?!\[)/$replace/ } @matches;
585 foreach (@matches) {
586 s/$element_name(?!\[)/$replace/;
587 }
588588 }
589589
590590 my $logger = get_logger('Data::Write');
665665
666666 # cleanup indexes are we don't handle them now with element
667667 # (later in lists and hashes)
668 map { s/\[\d+\]+$//; } @matches;
668 foreach (@matches) {
669 s/\[\d+\]+$//;
670 }
669671 $logger->debug( "copy_in_augeas: Node path $p matches:\n\t" . join( "\n\t", @matches ), );
670672
671673 # store elements found in Augeas and their corresponding path
00 # -*- cperl -*-
1
2 use warnings;
3 use strict;
14
25 # test augeas backend
36
1821
1922 use lib 't/lib';
2023 use LoadTest;
21
22 use warnings;
23 use strict;
2424
2525 eval { require Config::Augeas ;} ;
2626 if ( $@ ) {
148148 #my @aug_content = $ssh_augeas_obj->match("/files/etc/ssh/sshd_config/*") ;
149149 #print join("\n",@aug_content) ;
150150
151 my $assign = $Config::Model::VERSION >= 2.052 ? ':=' : ':' ;
152
153 $expect = qq(AcceptEnv${assign}LC_PAPER,LC_NAME,LC_ADDRESS,LC_TELEPHONE,LC_MEASUREMENT,LC_IDENTIFICATION,LC_ALL
154 AllowUsers${assign}foo,"bar\@192.168.0.*"
151 $expect = qq(AcceptEnv:=LC_PAPER,LC_NAME,LC_ADDRESS,LC_TELEPHONE,LC_MEASUREMENT,LC_IDENTIFICATION,LC_ALL
152 AllowUsers:=foo,"bar\@192.168.0.*"
155153 HostbasedAuthentication=no
156 HostKey${assign}/etc/ssh/ssh_host_key,/etc/ssh/ssh_host_rsa_key,/etc/ssh/ssh_host_dsa_key
154 HostKey:=/etc/ssh/ssh_host_key,/etc/ssh/ssh_host_rsa_key,/etc/ssh/ssh_host_dsa_key
157155 Subsystem:rftp=/usr/lib/openssh/rftp-server
158156 Subsystem:sftp=/usr/lib/openssh/sftp-server
159157 Subsystem:tftp=/usr/lib/openssh/tftp-server
222220 splice @mod, 32,2, @lines ;
223221 pop @mod ;
224222
223 my $sarko = "Match User sarko Group pres.*\n";
224 if (version->parse($aug_version) ge version->parse('1.13.0')) {
225 # tweak quotes added by augeas since version 1.13.0
226 $mod[32] =~ s/(white.house.\*)/"$1"/;
227 $sarko =~ s/(sarko|pres.\*)/"$1"/g;
228 }
229
225230 is_deeply([$sshd_config->lines],\@mod,"check content of $sshd_config after Match~1") ;
226231
227232 $sshd_root->load("Match:2 Condition User=sarko Group=pres.* -
230235 $i_sshd->write_back ;
231236
232237
233 push @mod,"Match User sarko Group pres.*\n","Banner /etc/bienvenue2.txt\n";
234
235 my @got = map {s/^[\t ]+//; $_; } $sshd_config->lines;
238 push @mod, $sarko, "Banner /etc/bienvenue2.txt\n";
239
240 my @got = map {my $t=$_; $t =~ s/^[\t ]+//; $t; } $sshd_config->lines;
236241 eq_or_diff(\@got,\@mod,"check content of $sshd_config after Match:2 ...") ;
237242
238243 $sshd_root->load("Match:2 Condition User=sarko Group=pres.* -
244249 print "mod--\n",map { $i++ . ': '. $_} @mod,"---\n" if $trace ;
245250 splice @mod,37,0,"AllowTcpForwarding yes\n";
246251
247 @got = map {s/^[\t ]+//; $_; } $sshd_config->lines;
252 @got = map {my $t=$_; $t =~ s/^[\t ]+//; $t; } $sshd_config->lines;
248253 eq_or_diff( \@got,\@mod,"check content of $sshd_config after Match:2 AllowTcpForwarding=yes") ;
249254
250255 } # end SKIP section