Skip to content

Commit

Permalink
shibui-2341 better url encoding, utf8 encoding of names
Browse files Browse the repository at this point in the history
  • Loading branch information
sporth committed Sep 12, 2022
1 parent 7331279 commit 1f7a8ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bulk-upload/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ If you prefer to build the image yourself, `cd docker-build;docker build -t unic

### running without docker ###
The docker-build/shibui-md-upload.pl script can be run manually.
Depending on OS you may need to install some additional non dist Perl modules. REST::Client , XML::LibXML , JSON , Config::File
Depending on OS you may need to install some additional non dist Perl modules. REST::Client , XML::LibXML , JSON , Config::File , URI::Encode
`perl shibui-md-upload.pl -c <path to upload.conf> -m <path to metadata location> -e (enable metadata source after upload)`

2 changes: 1 addition & 1 deletion bulk-upload/docker-build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ MAINTAINER sporth@unicon.net

RUN apt-get clean \
&& apt-get -y update \
&& apt-get install -y librest-client-perl libconfig-file-perl jq libxml-libxml-perl libjson-perl
&& apt-get install -y librest-client-perl libconfig-file-perl jq libxml-libxml-perl libjson-perl liburi-encode-perl

WORKDIR /opt
COPY shibui-md-upload.pl /opt/shibui-md-upload.pl
Expand Down
14 changes: 9 additions & 5 deletions bulk-upload/docker-build/shibui-md-upload.pl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use XML::LibXML::XPathContext;
use Encode;
use JSON;
use URI::Encode;

##process arguments
our ($opt_e,$opt_m,$opt_c);
Expand Down Expand Up @@ -201,10 +202,13 @@ sub call_api {
my $xml = shift;
my $enable = shift;
my ($params,$code,$result);
my $encoder = URI::Encode->new({encode_reserved => 1});

my $utf8 = encode_utf8($xml);
my $utf8_name = encode_utf8($name);
my $ename = $encoder->encode($name);

$params = "?spName=$name";
$params = "?spName=$ename";
$params .= "&enableService=true" if ($enable);

$client->addHeader('Content-Type', "application/xml; charset='utf8'");
Expand All @@ -226,18 +230,18 @@ sub call_api {
my $eresult = $client->responseContent();

if ($ecode == 200 || $ecode == 201) {
print "$ecode: entity $name uploaded sucessfully and enabled\n";
print "$ecode: entity $utf8_name uploaded sucessfully and enabled\n";
} else {
print "$ecode: entity $name uploaded sucessfully but enabling failed:\n";
print "$ecode: entity $utf8_name uploaded sucessfully but enabling failed:\n";
open(my $pipe, '|-', "jq .");
print $pipe $eresult;
}

} else {
print "$code: entity $name uploaded sucessfully\n";
print "$code: entity $utf8_name uploaded sucessfully\n";
}
} elsif ($code == 409) {
print "$code: entity $name already exists\n";
print "$code: entity $utf8_name already exists\n";
} elsif ($code == 500) {
print "$code: $result\n";
} else {
Expand Down

0 comments on commit 1f7a8ff

Please sign in to comment.