Skip to content
Snippets Groups Projects
Commit dc8a17d6 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

formmat multi-valued attributes in templates

parent 1b180ce8
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ use List::Util qw(shuffle); ...@@ -10,6 +10,7 @@ use List::Util qw(shuffle);
use List::MoreUtils qw(pairwise); use List::MoreUtils qw(pairwise);
use MIME::Base64; use MIME::Base64;
use Template; use Template;
use Template::Stash;
sub encrypt { sub encrypt {
my ($string, $key) = @_; my ($string, $key) = @_;
...@@ -94,6 +95,18 @@ sub generate_secret { ...@@ -94,6 +95,18 @@ sub generate_secret {
sub update_ssp_authsources { sub update_ssp_authsources {
my ($templates_dir, $output, $accounts) = @_; my ($templates_dir, $output, $accounts) = @_;
# scalar virtual method to return a quoted value
$Template::Stash::SCALAR_OPS->{ quote } = sub {
my $scalar = shift;
return "'" . $scalar . "'";
};
# list virtual method to return a list of quoted values
$Template::Stash::LIST_OPS->{ quote } = sub {
my $list = shift;
return [ map { "'" . $_ . "'" } @$list ];
};
my $tt2 = Template->new({ my $tt2 = Template->new({
ENCODING => 'utf8', ENCODING => 'utf8',
INCLUDE_PATH => $templates_dir . '/accounts' INCLUDE_PATH => $templates_dir . '/accounts'
......
[% MACRO enumerate(list) BLOCK -%]
[% FOREACH item IN list -%]
'[% item %]'[% IF ! loop.last -%], [% END -%]
[% END -%]
[% END -%]
[% MACRO print_attribute(account, attribute) BLOCK -%]
[% IF account.$attribute -%]
'[% attribute %]' => '[% account.$attribute %]',
[% END -%]
[% END -%]
[% MACRO print_multivalued_attribute(account, attribute) BLOCK -%]
[% IF account.$attribute -%]
'[% attribute %]' => [ [% enumerate(account.$attribute) -%] ],
[% END -%]
[% END -%]
<?php <?php
// PhP configuration file loaded in simpleSamlPhp authsources.php file // PhP configuration file loaded in simpleSamlPhp authsources.php file
$validTestAccounts = array ( $validTestAccounts = array (
...@@ -20,18 +5,38 @@ $validTestAccounts = array ( ...@@ -20,18 +5,38 @@ $validTestAccounts = array (
[% FOREACH account IN accounts -%] [% FOREACH account IN accounts -%]
'user[% account.id() %]:{SHA256}[% account.password_hash() %]=' => array( 'user[% account.id() %]:{SHA256}[% account.password_hash() %]=' => array(
[% print_attribute(account, 'internal_uid') -%] 'internal_uid' => array([% account.internal_uid().quote %]),
[% print_attribute(account, 'cn') -%] 'associatedSP' => array([% account.associatedSP().quote %]),
[% print_attribute(account, 'displayName') -%] [% IF account.cn() -%]
[% print_attribute(account, 'givenName') -%] 'cn' => array([% account.cn().quote %]),
[% print_attribute(account, 'sn') -%] [% END -%]
[% print_attribute(account, 'mail') -%] [% IF account.sn() -%]
[% print_multivalued_attribute(account, 'eduPersonAffiliation') -%] 'sn' => array([% account.sn().quote %]),
[% print_multivalued_attribute(account, 'eduPersonScopedAffiliation') -%] [% END -%]
[% print_attribute(account, 'eduPersonPrincipalName') -%] [% IF account.displayName() -%]
[% print_attribute(account, 'schacHomeOrganization') -%] 'displayName' => array([% account.displayName().quote %]),
[% print_attribute(account, 'schacHomeOrganizationType') -%] [% END -%]
[% print_attribute(account, 'associatedSP') -%] [% IF account.givenName() -%]
'givenName' => array([% account.givenName().quote %]),
[% END -%]
[% IF account.mail() -%]
'mail' => array([% account.mail().quote %]),
[% END -%]
[% IF account.eduPersonAffiliation() -%]
'eduPersonAffiliation' => array([% account.eduPersonAffiliation().quote.join(', ') %]),
[% END -%]
[% IF account.eduPersonScopedAffiliation() -%]
'eduPersonScopedAffiliation' => array([% account.eduPersonScopedAffiliation().quote.join(', ') %]),
[% END -%]
[% IF account.eduPersonPrincipalName() -%]
'eduPersonPrincipalName' => array([% account.eduPersonPrincipalName().quote %]),
[% END -%]
[% IF account.schacHomeOrganization() -%]
'schacHomeOrganization' => array([% account.schacHomeOrganization().quote %]),
[% END -%]
[% IF account.schacHomeOrganizationType() -%]
'schacHomeOrganizationType' => array([% account.schacHomeOrganizationType().quote %]),
[% END -%]
), ),
[% END -%] [% END -%]
......
...@@ -49,9 +49,14 @@ provider.</p> ...@@ -49,9 +49,14 @@ provider.</p>
<div> <div>
<table> <table>
<caption>List of user attributes</caption> <caption>List of user attributes</caption>
[% FOREACH attribute IN [ 'cn', 'displayName', 'givenName', 'sn', 'mail', 'schacHomeOrganization', 'schacHomeOrganizationType', 'eduPersonPrincipalName', 'eduPersonAffiliation', 'eduPersonScopedAffiliation' ] -%] [% FOREACH attribute IN [ 'cn', 'displayName', 'givenName', 'sn', 'mail', 'schacHomeOrganization', 'schacHomeOrganizationType', 'eduPersonPrincipalName' ] -%]
<tr> <tr>
<th>[% attribute %]</th><td> [% account.$attribute %]</td> <th>[% attribute %]</th><td> [% account.$attribute() %]</td>
</tr>
[% END %]
[% FOREACH attribute IN [ 'eduPersonAffiliation', 'eduPersonScopedAffiliation' ] -%]
<tr>
<th>[% attribute %]</th><td> [% account.$attribute().join(', ') %]</td>
</tr> </tr>
[% END %] [% END %]
<tr> <tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment