Archived
1
0

Generate token before saving butler.xml

This commit is contained in:
Mercier Pierre-Olivier 2013-09-14 18:35:08 +02:00
parent 9b53b5d7e8
commit d9bc49c5d7

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use v5.10;
use Digest::SHA qw(sha1_base64);
use File::Basename;
use ACU::API::Projects;
@ -57,7 +58,7 @@ sub check_xml
else {
open $fh, "|xmllint --noout -";
}
print $fh $content;
print $fh ${ $content };
close $fh;
return $?;
@ -134,13 +135,32 @@ sub tag_project
}
# Check DTD validity
if (check_xml($content, "http://acu.epita.fr/dtd/project.dtd")) {
if (check_xml(\$content, "http://acu.epita.fr/dtd/project.dtd")) {
log ERROR, "Corrigez les erreurs du fichier project.xml avant de lancer la création du projet.";
}
# TODO: check user permissions
# Generate token for VCS submission
my $dom = XML::LibXML->load_xml(string => (\$content));
my $mod = 0;
for $vcs ($dom->documentElement()->getElementsByTagName("vcs"))
{
if (! $vcs->hasAttribute("token"))
{
my $token;
do {
$token = sha1_base64(rand);
$token =~ s/[^a-zA-Z0-9]//g;
} while (length $token >= 12);
$vcs->setAttribute("token", $token);
$mod = 1;
}
}
if ($mod) {
$content = $dom->toString();
}
# Send data to intradata
log INFO, "Attente d'un processus de publication...";