Skip to content

Commit bc072c1

Browse files
committed
New CLI command for PATCH requests
1 parent e48c10e commit bc072c1

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

bin/patch.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
3+
print_usage()
4+
{
5+
printf "Patches an RDF document using SPARQL update.\n"
6+
printf "\n"
7+
printf "Usage: cat update.rq | %s options TARGET_URI\n" "$0"
8+
printf "\n"
9+
printf "Options:\n"
10+
printf " -f, --cert-pem-file CERT_FILE .pem file with the WebID certificate of the agent\n"
11+
printf " -p, --cert-password CERT_PASSWORD Password of the WebID certificate\n"
12+
printf " --proxy PROXY_URL The host this request will be proxied through (optional)\n"
13+
}
14+
15+
hash turtle 2>/dev/null || { echo >&2 "turtle not on \$PATH. Aborting."; exit 1; }
16+
hash curl 2>/dev/null || { echo >&2 "curl not on \$PATH. Aborting."; exit 1; }
17+
18+
unknown=()
19+
while [[ $# -gt 0 ]]
20+
do
21+
key="$1"
22+
23+
case $key in
24+
-f|--cert-pem-file)
25+
cert_pem_file="$2"
26+
shift # past argument
27+
shift # past value
28+
;;
29+
-p|--cert-password)
30+
cert_password="$2"
31+
shift # past argument
32+
shift # past value
33+
;;
34+
--proxy)
35+
proxy="$2"
36+
shift # past argument
37+
shift # past value
38+
;;
39+
*) # unknown option
40+
unknown+=("$1") # save it in an array for later
41+
shift # past argument
42+
;;
43+
esac
44+
done
45+
set -- "${unknown[@]}" # restore args
46+
47+
if [ -z "$cert_pem_file" ] ; then
48+
print_usage
49+
exit 1
50+
fi
51+
if [ -z "$cert_password" ] ; then
52+
print_usage
53+
exit 1
54+
fi
55+
if [ "$#" -ne 1 ]; then
56+
print_usage
57+
exit 1
58+
fi
59+
60+
url="$1"
61+
62+
if [ -n "$proxy" ]; then
63+
# rewrite target hostname to proxy hostname
64+
url_host=$(echo "$url" | cut -d '/' -f 1,2,3)
65+
proxy_host=$(echo "$proxy" | cut -d '/' -f 1,2,3)
66+
final_url="${url/$url_host/$proxy_host}"
67+
else
68+
final_url="$url"
69+
fi
70+
71+
# resolve SPARQL update from stdin against base URL and PATCH it to the server
72+
# uparse currently does not support --base: https://github.com/apache/jena/issues/3296
73+
cat - | curl -v -k -E "$cert_pem_file":"$cert_password" --data-binary @- -H "Content-Type: application/sparql-update" -X PATCH -o /dev/null "$final_url"

src/main/java/com/atomgraph/linkeddatahub/resource/Graph.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public Response patch(UpdateRequest updateRequest, @QueryParam("graph") URI grap
318318
if (log.isDebugEnabled()) log.debug("PATCH request on named graph with URI: {}", getURI());
319319
if (log.isDebugEnabled()) log.debug("PATCH update string: {}", updateRequest.toString());
320320

321-
if (updateRequest.getOperations().size() > 1)
321+
if (updateRequest.getOperations().size() != 1)
322322
throw new WebApplicationException("Only a single SPARQL Update is supported by PATCH", UNPROCESSABLE_ENTITY.getStatusCode()); // 422 Unprocessable Entity
323323

324324
Update update = updateRequest.getOperations().get(0);

0 commit comments

Comments
 (0)