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);
use List::MoreUtils qw(pairwise);
use MIME::Base64;
use Template;
use Template::Stash;
sub encrypt {
my ($string, $key) = @_;
......@@ -94,6 +95,18 @@ sub generate_secret {
sub update_ssp_authsources {
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({
ENCODING => 'utf8',
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 configuration file loaded in simpleSamlPhp authsources.php file
$validTestAccounts = array (
......@@ -20,18 +5,38 @@ $validTestAccounts = array (
[% FOREACH account IN accounts -%]
'user[% account.id() %]:{SHA256}[% account.password_hash() %]=' => array(
[% print_attribute(account, 'internal_uid') -%]
[% print_attribute(account, 'cn') -%]
[% print_attribute(account, 'displayName') -%]
[% print_attribute(account, 'givenName') -%]
[% print_attribute(account, 'sn') -%]
[% print_attribute(account, 'mail') -%]
[% print_multivalued_attribute(account, 'eduPersonAffiliation') -%]
[% print_multivalued_attribute(account, 'eduPersonScopedAffiliation') -%]
[% print_attribute(account, 'eduPersonPrincipalName') -%]
[% print_attribute(account, 'schacHomeOrganization') -%]
[% print_attribute(account, 'schacHomeOrganizationType') -%]
[% print_attribute(account, 'associatedSP') -%]
'internal_uid' => array([% account.internal_uid().quote %]),
'associatedSP' => array([% account.associatedSP().quote %]),
[% IF account.cn() -%]
'cn' => array([% account.cn().quote %]),
[% END -%]
[% IF account.sn() -%]
'sn' => array([% account.sn().quote %]),
[% END -%]
[% IF account.displayName() -%]
'displayName' => array([% account.displayName().quote %]),
[% END -%]
[% 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 -%]
......
......@@ -49,9 +49,14 @@ provider.</p>
<div>
<table>
<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>
<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>
[% END %]
<tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment