diff --git a/scripts/rest-clients/README b/scripts/rest-clients/README new file mode 100644 index 000000000..0dc764518 --- /dev/null +++ b/scripts/rest-clients/README @@ -0,0 +1,28 @@ ++ Check you have "tidy" available from the command line. + ++ Check you have "/usr/bin/ruby". + ++ chmod u+x *.sh + ++ When working with the local application: + + * [Optional] For clarity: remove "navaldev" database + reload Jetty. + + * Import criterion types: + + - post-criterions-types.sh criterion-types-sample.xml + (authenticate with wswriter/wswriter) + + - Check the returned errors are consistent with the comments in + criterion-types-sample.xml. + + * Export criterion types: + + - get-criterion-types.sh (authenticate with wsreader/wsreader) + ++ When working with the online demo: + + * post-criterions-types.sh --prod criterion-types-sample.xml + (authenticate with wswriter/wswriter) + + * get-criterion-types.sh --prod (authenticate with wsreader/wsreader) diff --git a/scripts/rest-clients/base64.sh b/scripts/rest-clients/base64.sh new file mode 100755 index 000000000..a40993e4e --- /dev/null +++ b/scripts/rest-clients/base64.sh @@ -0,0 +1,4 @@ +#!/usr/bin/ruby + +require 'base64' +puts Base64.encode64("#{ARGV[0]}"); diff --git a/scripts/rest-clients/criterion-types-sample.xml b/scripts/rest-clients/criterion-types-sample.xml new file mode 100644 index 000000000..337f946d6 --- /dev/null +++ b/scripts/rest-clients/criterion-types-sample.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/rest-clients/get-criterion-types.sh b/scripts/rest-clients/get-criterion-types.sh new file mode 100755 index 000000000..548829b1f --- /dev/null +++ b/scripts/rest-clients/get-criterion-types.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +. ./rest-common-env.sh + +printf "Login name: " +read loginName +printf "Password: " +read password + +if [ "$1" = "--prod" ]; then + baseServiceURL=$PRODUCTION_BASE_SERVICE_URL + certificate=$PRODUCTION_CERTIFICATE +else + baseServiceURL=$DEVELOPMENT_BASE_SERVICE_URL + certificate=$DEVELOPMENT_CERTIFICATE +fi + +authorization=`./base64.sh $loginName:$password` + +curl -sv -X GET $certificate --header "Authorization: Basic $authorization" \ + $baseServiceURL/criteriontypes | tidy -xml -i -q -utf8 diff --git a/scripts/rest-clients/post-criterions-types.sh b/scripts/rest-clients/post-criterions-types.sh new file mode 100755 index 000000000..6436a63e9 --- /dev/null +++ b/scripts/rest-clients/post-criterions-types.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +. ./rest-common-env.sh + +printf "Login name: " +read loginName +printf "Password: " +read password + +baseServiceURL=$DEVELOPMENT_BASE_SERVICE_URL +certificate=$DEVELOPMENT_CERTIFICATE + +for i in "$@" +do + if [ "$i" = "--prod" ]; then + baseServiceURL=$PRODUCTION_BASE_SERVICE_URL + certificate=$PRODUCTION_CERTIFICATE + else + file=$i + fi +done + +if [ "$file" = "" ]; then + printf "Missing file\n" 1>&2 + exit -1 +fi + +authorization=`./base64.sh $loginName:$password` + +curl -sv -X POST $certificate -d @$file \ + --header "Content-type: application/xml" \ + --header "Authorization: Basic $authorization" \ + $baseServiceURL/criteriontypes | tidy -xml -i -q -utf8 diff --git a/scripts/rest-clients/rest-common-env.sh b/scripts/rest-clients/rest-common-env.sh new file mode 100755 index 000000000..d839556d8 --- /dev/null +++ b/scripts/rest-clients/rest-common-env.sh @@ -0,0 +1,8 @@ +DEVELOPMENT_BASE_SERVICE_URL=http://localhost:8080/navalplanner-webapp/ws/rest +PRODUCTION_BASE_SERVICE_URL=https://naval.igalia.com/navalplanner-webapp/ws/rest + +DEVELOPMENT_CERTIFICATE="" +# FIXME: Until we have a valid production certificate, accept any +# server-provided certificate. +PRODUCTION_CERTIFICATE=-k +#PRODUCTION_CERTIFICATE=--cacert igalia-certificate.pem