-
Notifications
You must be signed in to change notification settings - Fork 2
/
define.sh
1117 lines (997 loc) · 39.8 KB
/
define.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /bin/bash
# http api tests : run-time environment initialization
# intended to be sourced
#
# environment :
# STORE_HOST : http host name
# STORE_ACCOUNT : account name : default "openrdf-sesame"
# STORE_REPOSITORY : individual repository : default "mem-rdf"
# STORE_TOKEN : the authentication token
# STORE_COLLABORTOR : the collaborator account : default "jhacker"
#
# in order to run it behind nginx to target a local host
# define STORE_TOKEN, STORE_TOKEN_ADMIN and STORE_HOST
# source define.sh
# redefine STORE_URL to use http rather than https
#
# this defines several operators for RDF|SPARQL access to the given store
#
# curl_sparql_request
# curl_sparql_query
# curl_sparql_update
# curl_sparql_view
# graph_store_get
# graph_store_update
#
#
# in order for the tests to run, the following must be present for the default settings
#
# openrdf-sesame/mem-rdf
# openrdf-sesame/mem-rdf
export PATH=`pwd`/bin:${PATH}
# export STORE_URL=https://dydra.com:81 # 20170705 server version is just http
# export STORE_URL=http://dydra.com
# export STORE_URL=http://stage.dydra.com
if [[ "" == "${STORE_HOST}" ]]
then
if [[ "" == "${STORE_URL}" ]]
then
export STORE_URL="http://localhost"
fi
# strip the protocol and possible user authentication to yield the actual host
case ${STORE_URL} in
http:*) export STORE_HOST=${STORE_URL#*http://} ;;
https:*) export STORE_HOST=${STORE_URL#*https://} ;;
*) echo "invalid store url: '${STORE_URL}'"; return 1;;
esac
# strip a possible port
export STORE_HOST=${STORE_HOST%:*}
else
export STORE_URL="https://${STORE_HOST}"
fi
export STORE_SITE="dydra.com" # the abstract site name
if [[ "" == "${STORE_ACCOUNT}" ]]
then export STORE_ACCOUNT="test"
fi
if [[ "" == "${STORE_REPOSITORY}" ]]
then export STORE_REPOSITORY="test"
fi
if [[ "" == "${STORE_COLLABORATOR}" ]]
then export STORE_COLLABORATOR="jhacker"
fi
export STORE_REPOSITORY_WRITABLE="${STORE_REPOSITORY}-write"
export STORE_REPOSITORY_PROVENANCE="${STORE_REPOSITORY}-provenance"
export STORE_REPOSITORY_PUBLIC="${STORE_REPOSITORY}-public"
export STORE_REPOSITORY_REVISIONED="${STORE_REPOSITORY}-revisioned"
if [[ "" == "${GRAPH_STORE_PATCH_LEGACY}" ]]
then export GRAPH_STORE_PATCH_LEGACY=true
fi
export STORE_CLIENT_IP="127.0.0.1"
export STORE_PREFIX="rdf"
export STORE_DGRAPH="sesame"
export STORE_IGRAPH="http://example.org"
# the _url form is used as the curl location while the other is the quad term
export STORE_NAMED_GRAPH="http://${STORE_SITE}/${STORE_ACCOUNT}/${STORE_REPOSITORY}/graph-name"
export STORE_NAMED_GRAPH_URL="${STORE_URL}/${STORE_ACCOUNT}/${STORE_REPOSITORY}/graph-name"
# accept json by default for use with jq
export STORE_SPARQL_RESULTS_MEDIA_TYPE="application/sparql-results+json"
export STORE_GRAPH_MEDIA_TYPE="application/n-quads"
export STORE_ACCEPT="Accept: application/sparql-results+json"
export STORE_ACCEPT_GRAPH="Accept: application/n-triples"
export STORE_SPARQL_QUERY_MEDIA_TYPE="application/sparql-query"
export STORE_SPARQL_UPDATE_MEDIA_TYPE="application/sparql-update"
export STORE_GRAPH_CONTENT_TYPE="Content-Type: text/turtle"
export STORE_IS_LOCAL=false
fgrep 127.0.0.1 /etc/hosts | fgrep -q ${STORE_HOST} && export STORE_IS_LOCAL=true
export STATUS_OK=200
export STATUS_ACCEPTED='202'
export STATUS_DELETE_SUCCESS='200|204'
export STATUS_PATCH_SUCCESS='200|201|204'
export POST_SUCCESS='200|201|204'
export STATUS_POST_SUCCESS='200|201|204'
export PUT_SUCCESS='201|204'
export STATUS_PUT_SUCCESS='200|201|204'
export STATUS_CREATED=201
export STATUS_NO_CONTENT=204
export STATUS_UPDATED='201|204'
export DELETE_SUCCESS=204
export STATUS_BAD_REQUEST=400
export STATUS_UNAUTHORIZED=401
export STATUS_NOT_FOUND=404
export STATUS_NOT_ACCEPTABLE=406
export STATUS_UNSUPPORTED_MEDIA=415
export STATUS_NOT_IMPLEMENTED=501
if [[ "" == "${CURL}" ]]
then
export CURL="curl --ipv4 --http1.1 -k" # ignore certificates
fi
# export CURL="curl -v --ipv4"
# export CURL="curl --ipv4 --trace-ascii /dev/tty"
if [[ "" == "${ECHO_OUTPUT}" ]]
then
export ECHO_OUTPUT=/dev/null # /dev/tty #
fi
export RESULT_OUTPUT=
function 1cpl () {
sed 's/[[:space:]]*//g' | sed 's/\(.\)/\1\
/g'
}
export -f 1cpl
if ! [ -x "$(command -v md5sum)" ]; then
function md5sum () {
md5
}
export -f md5sum
fi
# define operators to export sparql and graph store url variables of the appropriate pattern
# and define the values for the default repository. these will be overridden by scripts which expect to use a
# different repository than the default.
#
# export SPARQL_URL="${STORE_URL}/${STORE_ACCOUNT}/${STORE_REPOSITORY}/sparql"
# export GRAPH_STORE_URL="${STORE_URL}/${STORE_ACCOUNT}/${STORE_REPOSITORY}/service"
function set_sparql_url() {
# $1 : account name
# $2 : repository name
export SPARQL_URL="${STORE_URL}/${1}/${2}/sparql"
}
function set_graph_store_url() {
# $1 : account name
# $2 : repository name
export GRAPH_STORE_URL="${STORE_URL}/${1}/${2}/service"
}
function set_download_url() {
# $1 : account name
# $2 : repository name
export DOWNLOAD_URL="${STORE_URL}/${1}/${2}"
}
# set the default values - each script can over-ride
set_sparql_url ${STORE_ACCOUNT} ${STORE_REPOSITORY}
set_graph_store_url ${STORE_ACCOUNT} ${STORE_REPOSITORY}
set_download_url ${STORE_ACCOUNT} ${STORE_REPOSITORY}
if [[ "" == "${STORE_CLIENT_IP_AUTHORIZED}" ]]
then
export STORE_CLIENT_IP_AUTHORIZED=true
fi
# define a token for the primary account
if [[ "" == "${STORE_TOKEN}" ]]
then
if [ -f ~/.dydra/${STORE_HOST}.${STORE_ACCOUNT}.token ]
then
export STORE_TOKEN=`cat ~/.dydra/${STORE_HOST}.${STORE_ACCOUNT}.token`
elif [ -f ~/.dydra/${STORE_ACCOUNT}.token ]
then
export STORE_TOKEN=`cat ~/.dydra/${STORE_ACCOUNT}.token`
elif [ -f ~/.dydra/${STORE_HOST}.token ]
then
export STORE_TOKEN=`cat ~/.dydra/${STORE_HOST}.token`
else
echo "no STORE_TOKEN"
return 1
fi
fi
# and for admin operations - in case different from user account
if [[ "" == "${STORE_TOKEN_ADMIN}" ]]
then
echo "reuse STORE_TOKEN as STORE_TOKEN_ADMIN"
export STORE_TOKEN_ADMIN="$STORE_TOKEN"
fi
# and one for another registered user
if [[ "" == "${STORE_TOKEN_COLLABORATOR}" ]]
then
if [ -f ~/.dydra/${STORE_HOST}.${STORE_COLLABORATOR}.token ]
then
export STORE_TOKEN_COLLABORATOR=`cat ~/.dydra/${STORE_HOST}.${STORE_COLLABORATOR}.token`
else
echo "reuse STORE_TOKEN as STORE_TOKEN_COLLABORATOR"
export STORE_TOKEN_COLLABORATOR="${STORE_TOKEN}"
fi
fi
# indicate whether those put/post operations for which the request specified the default graph, will apply any
# quad statements to the default graph or to that graph from the statement. false implies by statement.
export QUAD_DISPOSITION_BY_REQUEST=false
STORE_ERRORS=0
function test_bad_request () {
egrep -q "${STATUS_BAD_REQUEST}"
}
function test_accepted () {
egrep -q "${STATUS_ACCEPTED}"
}
function test_delete_success () {
egrep -q "${STATUS_DELETE_SUCCESS}"
}
function test_not_acceptable () {
egrep -q "${STATUS_NOT_ACCEPTABLE}"
}
function test_not_acceptable_success () {
egrep -q "${STATUS_NOT_ACCEPTABLE}"
}
function test_unauthorized () {
egrep -q "${STATUS_UNAUTHORIZED}"
}
function test_unauthorized_success () {
egrep -q "${STATUS_UNAUTHORIZED}"
}
function test_not_found () {
egrep -q "${STATUS_NOT_FOUND}|${STATUS_BAD_REQUEST}"
}
function test_not_found_success () {
egrep -q "${STATUS_NOT_FOUND}"
}
function test_not_implemented () {
egrep -q "${STATUS_NOT_IMPLEMENTED}"
}
function test_ok () {
egrep -q "${STATUS_OK}|${STATUS_NO_CONTENT}"
}
function test_success () {
egrep -q "${STATUS_OK}|${STATUS_NO_CONTENT}"
}
function test_ok_success () {
egrep -q "${STATUS_OK}"
}
function test_patch_success () {
egrep -q "${STATUS_PATCH_SUCCESS}"
}
function test_post_success () {
egrep -q "${STATUS_POST_SUCCESS}"
}
function test_put_success () {
egrep -q "${STATUS_PUT_SUCCESS}"
}
function test_unsupported_media () {
egrep -q "${STATUS_UNSUPPORTED_MEDIA}"
}
function test_updated () {
egrep -q "${STATUS_UPDATED}"
}
# provide operators to restore aspects of the store to a known state
# they presume that the various PUT operators work
function initialize_account () {
# metadata
${CURL} -w "%{http_code}\n" -L -f -s -X POST \
-H "Content-Type: application/n-quads" --data-binary @- \
-u ":${STORE_TOKEN}" \
${STORE_URL}/${STORE_ACCOUNT}/system/service <<EOF
<http://dydra.com/accounts/openrdf-sesame> <urn:dydra:baseIRI> <http://dydra.com/accounts/openrdf-sesame> <http://dydra.com/accounts/openrdf-sesame> .
EOF
}
## in all the following repositories must be present
# openrdf-sesame/collation
# openrdf-sesame/graphql
# openrdf-sesame/ldp
# openrdf-sesame/library
# openrdf-sesame/mem-rdf
# openrdf-sesame/mem-rdf-provenance
# openrdf-sesame/mem-rdf-write
# openrdf-sesame/mem-rdfs
# openrdf-sesame/public # to test anonymous access
# openrdf-sesame/system
# openrdf-sesame/tpf
# schema/foaf (must be part of the installed service)
# schema/foaf__classDescription__view (and the "class" view query
function initialize_repository_configuration () {
# metadata
${CURL} -w "%{http_code}\n" -L -f -s -X POST \
-H "Content-Type: application/n-quads" --data-binary @- \
-u ":${STORE_TOKEN}" \
${STORE_URL}/${STORE_ACCOUNT}/system/service <<EOF
<http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> <urn:dydra:baseIRI> <http://www.openrdf.org/mem-rdf> <http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> .
<http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> <urn:dydra:skolemize> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> <http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> .
<http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> <urn:dydra:defaultContextTerm> <urn:dydra:default> <http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> .
<http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> <urn:dydra:describeForm> <urn:rdfcache:simple-symmetric-concise-bounded-description> <http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> .
<http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> <urn:dydra:describeObjectDepth> "2"^^<http://www.w3.org/2001/XMLSchema#integer> <http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> .
<http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> <urn:dydra:describeSubjectDepth> "2"^^<http://www.w3.org/2001/XMLSchema#integer> <http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> .
<http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> <urn:dydra:federationMode> <urn:rdfcache:internal> <http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> .
<http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> <urn:dydra:namedContextsTerm> <urn:dydra:named> <http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> .
<http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> <urn:dydra:prefixes> "prefix dc: <http://purl.org/dc/terms/>" <http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> .
<http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> <urn:dydra:provenanceRepositoryId> <http://${STORE_SITE}/accounts/openrdf-sesame/repository/provenance> <http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> .
<http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> <urn:dydra:strictVocabularyTerms> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> <http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> .
<http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> <urn:dydra:undefinedVariableBehavior> <urn:dydra:dynamicBinding> <http://${STORE_SITE}/accounts/openrdf-sesame/repositories/mem-rdf> .
EOF
}
function initialize_repository_rdf_graphs () {
${CURL} -w "%{http_code}\n" -L -f -s -X PUT \
-H "Accept: application/n-quads" \
-H "Content-Type: application/n-quads" --data-binary @- \
-u ":${STORE_TOKEN}" \
${GRAPH_STORE_URL} <<EOF
<http://example.com/default-subject> <http://example.com/default-predicate> "default object" .
<http://example.com/named-subject> <http://example.com/named-predicate> "named object" <${STORE_NAMED_GRAPH}> .
<http://example.com/named-subject> <http://example.com/named-predicate> "rdf-graphs named object" <$STORE_URL/${STORE_ACCOUNT}/repositories/${STORE_REPOSITORY}/rdf-graphs/sesame> .
EOF
}
function initialize_profile () {
${CURL} -w "%{http_code}\n" -f -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: " \
--data-binary @- \
-u ":${STORE_TOKEN}" \
${STORE_URL}/accounts/${STORE_ACCOUNT}/repositories/${STORE_REPOSITORY}/profile <<EOF
{
"name": "mem-rdf",
"homepage": "http://example.org/test",
"summary": "a summary",
"description": "a description",
"license_url": "http://unlicense.org"
}
EOF
}
function initialize_collaboration () {
${CURL} -w "%{http_code}\n" -f -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: " \
--data-binary @- \
-u ":${STORE_TOKEN}:" \
${STORE_URL}/accounts/${STORE_ACCOUNT}/repositories/${STORE_REPOSITORY}/collaborations <<EOF
{"collaborator": "jhacker",
"read": true,
"write": false
}
EOF
}
function initialize_prefixes () {
${CURL} -w "%{http_code}\n" -f -s -X PUT \
-H "Content-Type: application/json" \
-H "Accept: " \
--data-binary @- \
-u ":${STORE_TOKEN}:" \
${STORE_URL}/accounts/${STORE_ACCOUNT}/repositories/${STORE_REPOSITORY}/configuration/prefixes <<EOF
{"prefixes": "PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>" }
EOF
}
function initialize_privacy () {
${CURL} -w "%{http_code}\n" -f -s -X PUT \
-H "Content-Type: application/json" \
--data-binary @- \
-u ":${STORE_TOKEN}:" \
${STORE_URL}/accounts/${STORE_ACCOUNT}/repositories/${STORE_REPOSITORY}/authorization <<EOF
{"permissable_ip_addresses":["192.168.1.1"],"privacy_setting":1}
EOF
}
## convenience operators,
## but note, some require presence in the respective directory
function run_all_tests() {
bash run_all.sh | tee ${ECHO_OUTPUT} > run_all.out 2&>1
}
function run_test() {
(cd `dirname "$1"`; bash -e "`basename \"$1\"`")
if [[ "0" == "$?" ]]
then
echo "$1" succeeded
else
echo "$1" failed
fi
}
function run_tests() {
for file in $@; do
case "$file" in
*.sh )
(cd `dirname $file`; bash -e `basename $file`)
if [[ "0" == "$?" ]]
then
echo $file succeeded
else
echo $file failed
fi
;;
* )
if (test -d $file)
then ./run.sh $file # `find $file -name '*.sh'`
fi
;;
esac
done
}
# curl_sparql_request { $accept-header-argument } { $content-type-header-argument } { $url }
function curl_sparql_request () {
local -a curl_args=()
local -a accept_media_type=("-H" "Accept: $STORE_SPARQL_RESULTS_MEDIA_TYPE")
local -a content_media_type=("-H" "Content-Type: $STORE_SPARQL_QUERY_MEDIA_TYPE")
local -a method=("-X" "POST")
local -a data=()
local -a user=(-u ":${STORE_TOKEN}")
local -a user_id=("user_id=$0")
local -a curl_url="${SPARQL_URL}"
local -a url_args=()
local -a account=${STORE_ACCOUNT}
local -a repository=${STORE_REPOSITORY}
while [[ "$#" > 0 ]] ; do
# echo "arg $1";
case "$1" in
-H) case "$2" in
Accept:*) accept_media_type[1]="${2}"; shift 2;;
Content-Type:*) content_media_type[1]="${2}"; shift 2;;
*) curl_args+=("${1}" "${2}"); shift 2;;
esac ;;
--account) account="${2}"; shift 2;;
--repository) repository="${2}"; shift 2;;
-u|--user) if [[ -z "${2}" ]]; then user=(); else user[1]="${2}"; fi; shift 2;;
-X) method[1]="${2}"; shift 2;;
--data*) data+=("${1}" "${2}"); shift 2;;
--head) method=(); curl_args+=("${1}"); shift 1;;
query=*) data=(); content_media_type=(); url_args+=("${1}"); method=("-X" "GET"); shift 1;;
user_id=*) user_id=("${1}"); shift 1;;
*=*) url_args+=("${1}"); shift 1;;
*) curl_args+=("${1}"); shift 1;;
esac
# echo "curl_args in loop ${curl_args[@]}" > /dev/tty
done
# echo "curl_args ${curl_args[@]}" > /dev/tty
curl_url="${STORE_URL}/${account}/${repository}/sparql"
url_args+=(${user_id[@]})
if [[ ${#url_args[*]} > 0 ]] ; then curl_url=$(IFS='&' ; echo "${curl_url}?${url_args[*]}") ; fi
if [[ ${#data[*]} == 0 && ${method[1]} == "POST" ]] ; then data=("--data-binary" "@-"); fi
# where an empty array is possible, must be conditional due to unset variable constraint
if [[ ${accept_media_type[1]} != "Accept:" ]]; then curl_args+=("${accept_media_type[@]}"); fi
if [[ ${#content_media_type[*]} > 0 ]] ; then curl_args+=("${content_media_type[@]}"); fi
if [[ ${#data[*]} > 0 ]] ; then curl_args+=("${data[@]}"); fi
if [[ ${#method[*]} > 0 ]] ; then curl_args+=(${method[@]}); fi
if [[ ${#user[*]} > 0 ]] ; then curl_args+=(${user[@]}); fi
echo ${CURL} -L -f -s "${curl_args[@]}" ${curl_url} > $ECHO_OUTPUT
mkdir -p /tmp/test/
${CURL} -L -f -s "${curl_args[@]}" ${curl_url}
}
function curl_sparql_query () {
curl_sparql_request -H "Content-Type:application/sparql-query" "$@"
}
function curl_sparql_update () {
curl_sparql_request -H "Content-Type:application/sparql-update" "$@"
}
# curl_sparql_view { accept-header-argument } { content-type-header-argument } { view_name }
# operate with/on a view
# content-type is permitted in order to post to a view
function curl_sparql_view () {
local -a curl_args=()
local -a accept_media_type=("-H" "Accept: $STORE_SPARQL_RESULTS_MEDIA_TYPE")
local -a content_media_type=("-H" "Content-Type: $STORE_SPARQL_QUERY_MEDIA_TYPE")
local -a method=("-X" "GET")
local -a data=()
local -a user=(-u ":${STORE_TOKEN}")
local -a user_id=("user_id=$0")
local graph="" # the default is all graphs
local curl_url=""
local url_args=()
local account=${STORE_ACCOUNT}
local repository=${STORE_REPOSITORY}
local view="sparql" # start out as the default service location
while [[ "$#" > 0 ]] ; do
case "$1" in
--account) account="${2}"; shift 2;;
default|DEFAULT) graph="default"; shift 1;;
-D) curl_args+=("${1}" "${2}"); shift 2;;
--graph) if [[ "" == "${2}" ]] ; then graph=""; else graph="graph=${2}"; fi; shift 2;;
-H) case "$2" in
Accept:*) accept_media_type[1]="${2}"; shift 2;;
Content-Type:*) content_media_type=("-H" "${2}"); shift 2;;
*) curl_args+=("${1}" "${2}"); shift 2;;
esac ;;
-u|--user) if [[ -z "${2}" ]]; then user=(); else user[1]="${2}"; fi; shift 2;;
-v) curl_args+=("-v"); shift 1;;
-w) curl_args+=("${1}" "${2}"); shift 2;;
-X) method[1]="${2}"; shift 2;;
--data*) data+=("${1}" "${2}"); shift 2;;
--head) method=(); curl_args+=("${1}"); shift 1;;
query=*) data=(); content_media_type=(); url_args+=("${1}"); shift 1;;
--repository) repository="${2}"; shift 2;;
user_id=*) user_id=("${1}"); shift 1;;
*=*) url_args+=("${1}"); shift 1;;
*) view="${1}"; shift 1;;
esac
done
curl_url="${STORE_URL}/${account}/${repository}/${view}"
url_args+=(${user_id[@]})
if [[ "${graph}" ]] ; then url_args+=(${graph[@]}); fi
if [[ ${#url_args[*]} > 0 ]] ; then curl_url=$(IFS='&' ; echo "${curl_url}?${url_args[*]}") ; fi
if [[ ${#data[*]} == 0 && ${method[1]} == "POST" ]] ; then data=("--data-binary" "@-"); fi
# where an empty array is possible, must be conditional due to unset variable constraint
curl_args+=("${accept_media_type[@]}");
if [[ ${#content_media_type[*]} > 0 ]] ; then curl_args+=("${content_media_type[@]}"); fi
if [[ ${#data[*]} > 0 ]] ; then curl_args+=("${data[@]}"); fi
if [[ ${#method[*]} > 0 ]] ; then curl_args+=(${method[@]}); fi
if [[ ${#user[*]} > 0 ]] ; then curl_args+=(${user[@]}); fi
echo ${CURL} -L -f -s "${curl_args[@]}" ${curl_url} > $ECHO_OUTPUT
${CURL} -L -f -s "${curl_args[@]}" ${curl_url}
}
# curl_graph_store_delete { -H $accept-header-argument } { graph }
function curl_graph_store_delete () {
curl_graph_store_get -X DELETE "$@"
}
# curl_graph_store_get { -H $accept-header-argument } {--repository $repository} { graph }
function curl_graph_store_get_nofail () {
local -a curl_args=()
local -a accept_media_type=("-H" "Accept: $STORE_GRAPH_MEDIA_TYPE")
local -a content_media_type=()
local -a method=("-X" "GET")
local -a user=(-u ":${STORE_TOKEN}")
local -a user_id=("user_id=$0")
local graph="" # the default is all graphs
local account=${STORE_ACCOUNT}
local repository=${STORE_REPOSITORY}
local curl_url=""
local url_args=()
curl_url="${STORE_URL}/${account}/${repository}/service"
while [[ "$#" > 0 ]] ; do
case "$1" in
--account) account="${2}"; shift 2; curl_url="${STORE_URL}/${account}/${repository}/service";;
all|ALL) graph="all"; shift 1;;
default|DEFAULT) graph="default"; shift 1;;
graph=*) graph="${1}"; shift 1;;
--graph=*) graph="${1}"; shift 1;;
-H) case "$2" in
Accept:*) accept_media_type[1]="${2}"; shift 2;;
Content-Type:*) content_media_type=("-H" "${2}"); shift 2;;
*) curl_args+=("${1}" "${2}"); shift 2;;
esac ;;
--head) method=(); curl_args+=("${1}"); shift 1;;
--repository) repository="${2}"; shift 2; curl_url="${STORE_URL}/${account}/${repository}/service";;
--url) curl_url="${2}"; shift 2;;
-u|--user) if [[ -z "${2}" ]]; then user=(); else user[1]="${2}"; fi; shift 2;;
user_id=*) user_id=("${1}"); shift 1;;
-X) method[1]="${2}"; shift 2;;
*=*) url_args+=("${1}"); shift 1;;
*) curl_args+=("${1}"); shift 1;;
esac
done
url_args+=(${user_id[@]})
if [[ "${graph}" ]] ; then url_args+=(${graph}); fi
if [[ ${#url_args[*]} > 0 ]] ; then curl_url=$(IFS='&' ; echo "${curl_url}?${url_args[*]}") ; fi
# where an empty array is possible, must be conditional due to unset variable constraint
curl_args+=("${accept_media_type[@]}");
if [[ ${#content_media_type[*]} > 0 ]] ; then curl_args+=(${content_media_type[@]}); fi
if [[ ${#method[*]} > 0 ]] ; then curl_args+=(${method[@]}); fi
if [[ ${#user[*]} > 0 ]] ; then curl_args+=(${user[@]}); fi
echo ${CURL} -s "${curl_args[@]}" ${curl_url} > $ECHO_OUTPUT
${CURL} -s "${curl_args[@]}" ${curl_url}
}
function curl_graph_store_get () {
curl_graph_store_get_nofail -f "$@"
}
# curl_graph_store_get_code { $accept-header-argument } { graph }
function curl_graph_store_get_code () {
curl_graph_store_get -w "%{http_code}\n" "$@"
}
function curl_graph_store_get_code_nofail () {
curl_graph_store_get_nofail -w "%{stderr}%{http_code}\n" "$@"
}
function curl_graph_store_update () {
local -a curl_args=()
local -a accept_media_type=()
local -a content_encoding=()
local -a content_media_type=("-H" "Content-Type: $STORE_GRAPH_MEDIA_TYPE")
local -a data=("--data-binary" "@-")
local -a method=("-X" "POST")
local -a user=(-u ":${STORE_TOKEN}")
local -a user_id=("user_id=$0")
local -a output="/dev/stdout"
local graph="" # the default is all graphs
local account=${STORE_ACCOUNT}
local repository=${STORE_REPOSITORY}
local curl_url="${GRAPH_STORE_URL}"
local url_args=()
curl_url="${STORE_URL}/${account}/${repository}/service"
while [[ "$#" > 0 ]] ; do
case "$1" in
--account) account="${2}"; shift 2; curl_url="${STORE_URL}/${account}/${repository}/service";;
all|ALL) graph="all"; shift 1;;
--data*) data[0]="${1}"; data[1]="${2}"; shift 2;;
default|DEFAULT) graph="default"; shift 1;;
graph=*) if [[ "graph=" == "${1}" ]] ; then graph=""; else graph="${1}"; fi; shift 1;;
--graph=*) if [[ "--graph=" == "${1}" ]] ; then graph=""; else graph="${1}"; fi; shift 1;;
-H) case "$2" in
Accept:*) accept_media_type=("-H" "${2}"); shift 2;;
Content-Type:*) content_media_type[1]="${2}"; shift 2;;
Content-Encoding:*) content_encoding=("-H" "${2}"); shift 2;;
*) curl_args+=("${1}" "${2}"); shift 2;;
esac ;;
-o) curl_args+=("-o" "${2}"); output="${2}"; shift 2;;
--repository) repository="${2}";
shift 2; curl_url="${STORE_URL}/${account}/${repository}/service";;
--url) curl_url="${2}"; shift 2;;
-u|--user) if [[ -z "${2}" ]]; then user=(); else user[1]="${2}"; fi; shift 2;;
user_id=*) user_id=("${1}"); shift 1;;
-X) method[1]="${2}"; shift 2;;
-v) curl_args+=("-v"); shift 1;;
-w) curl_args+=("${1}" "${2}"); output="/dev/stdout"; shift 2;;
*) curl_args+=("${1}"); shift 1;;
esac
done
url_args+=(${user_id[@]})
if [[ "${graph}" ]] ; then url_args+=(${graph}); fi
if [[ ${#url_args[*]} > 0 ]] ; then curl_url=$(IFS='&' ; echo "${curl_url}?${url_args[*]}") ; fi
if [[ ${#accept_media_type[*]} > 0 ]] ; then curl_args+=("${accept_media_type[@]}"); fi
if [[ ${#content_encoding[*]} > 0 ]] ; then curl_args+=("${content_encoding[@]}"); fi
if [[ ${#content_media_type[*]} > 0 ]] ; then curl_args+=("${content_media_type[@]}"); fi
if [[ ${#data[*]} > 0 ]] ; then curl_args+=("${data[@]}"); fi
if [[ ${#method[*]} > 0 ]] ; then curl_args+=(${method[@]}); fi
if [[ ${#user[*]} > 0 ]] ; then curl_args+=("${user[@]}"); fi
echo ${CURL} -f -s "${curl_args[@]}" ${curl_url} > $ECHO_OUTPUT
${CURL} -f -s "${curl_args[@]}" ${curl_url} # > $output
}
function curl_graph_store_clear () {
curl_graph_store_update -X DELETE "$@" -o /dev/null <<EOF
EOF
}
function clear_repository_content () {
curl_graph_store_update -X PUT "$@" -o /dev/null <<EOF
EOF
}
function clear_repository_revisions () {
local -a URL="${STORE_URL}/system/accounts/${1}/repositories/${2}/revisions"
${CURL} -f -s -X DELETE -w "%{http_code}\n" \
-H "Accept: text/turtle" \
-u ":${STORE_TOKEN_ADMIN}" ${URL}
}
# clear_repository_revisions test test-revisioned-repository
# initialize_repository_content { --repository $repository-name } { --url $url }
# clear everything, insert one statement each in the default and the named graphs
function initialize_repository_content () {
curl_graph_store_update -X PUT "$@" -o /dev/null <<EOF
<http://example.com/default-subject> <http://example.com/default-predicate> "default object" .
EOF
curl_graph_store_update -X POST graph=${STORE_NAMED_GRAPH} -o /dev/null "$@" <<EOF
<http://example.com/named-subject> <http://example.com/named-predicate> "named object" <${STORE_NAMED_GRAPH}> .
EOF
}
function initialize_repository () {
initialize_repository_content "$@"
}
function initialize_repository_public () {
initialize_repository_content --repository "${STORE_REPOSITORY_PUBLIC}"
}
# to setup for tests, this must be done once the repositories have been created
function initialize_all_repositories () {
curl_graph_store_update -X PUT --repository collation -o /dev/null \
-H "Content-Type: text/turtle" \
--data-binary @extensions/sparql-protocol/collation/collation.ttl
initialize_repository
}
function curl_download () {
${CURL} -f -s -S -X GET \
-H "${1}" \
-u ":${STORE_TOKEN}:" \
${DOWNLOAD_URL}.${2}
}
# curl_tpf_get { -H $header-argument } {--repository $repository} { query }
function curl_tpf_get () {
local -a curl_args=()
local -a method=("-X" "GET")
local -a user=(-u ":${STORE_TOKEN}")
local query="" # the default no query args
local revision=""
local curl_url="${STORE_URL}/${STORE_ACCOUNT}/${STORE_REPOSITORY}/tpf"
while [[ "$#" > 0 ]] ; do
case "$1" in
-H) case "$2" in
Accept*) curl_args+=("${1}" "${2}"); shift 2;;
*) curl_args+=("${1}" "${2}"); shift 2;;
esac ;;
--head) method=(); curl_args+=("${1}"); shift 1;;
--repository) curl_url="${STORE_URL}/${STORE_ACCOUNT}/${2}/tpf"; shift 2;;
--revision) revision="${2}"; shift 2;;
-u|--user) if [[ -z "${2}" ]]; then user=(); e<e user[1]="${2}"; fi; shift 2;;
*) query="${1}"; shift 1;;
esac
done
# where an empty array is possible, must be conditional due to unset variable constraint
# curl_args+=("${accept_media_type[@]}");
if [[ "${query}" ]]
then if [[ "${revision}" ]]
then curl_url="${curl_url}?${query}&revision=${revision}";
else curl_url="${curl_url}?${query}";
fi
else if [[ "${revision}" ]]
then curl_url="${curl_url}?revision=${revision}";
fi
fi
if [[ ${#method[*]} > 0 ]] ; then curl_args+=(${method[@]}); fi
if [[ ${#user[*]} > 0 ]] ; then curl_args+=(${user[@]}); fi
echo ${CURL} -f -s "${curl_args[@]}" ${curl_url} > $ECHO_OUTPUT
${CURL} -f -s "${curl_args[@]}" ${curl_url}
}
# curl_ldp_get { -H $header-argument } {--repository $repository} { --path $path }
function curl_ldp_get () {
local -a curl_args=()
local -a method=("-X" "GET")
local -a user=(-u ":${STORE_TOKEN}")
local revision=""
local repository="${STORE_REPOSITORY}"
local path=""
local curl_url=""
while [[ "$#" > 0 ]] ; do
case "$1" in
-H) case "$2" in
Accept:*) curl_args+=("${1}" "${2}"); shift 2;;
esac ;;
--head) method=(); curl_args+=("${1}"); shift 1;;
--repository) repository="${2}"; shift 2;;
--path) path="${2}"; shift 2;;
--revision) revision="${2}"; shift 2;;
-u|--user) if [[ -z "${2}" ]]; then user=(); else user[1]="${2}"; fi; shift 2;;
*) curl_args+=("${1}"); shift 1;;
esac
done
curl_url="http://ldp.${STORE_HOST}/${STORE_ACCOUNT}/${repository}"
if [[ "${path}" ]]
then curl_url="${curl_url}/${path}"
fi
# where an empty array is possible, must be conditional due to unset variable constraint
# curl_args+=("${accept_media_type[@]}");
if [[ "${query}" ]]
then if [[ "${revision}" ]]
then curl_url="${curl_url}?${query}&revision=${revision}";
else curl_url="${curl_url}?${query}";
fi
else if [[ "${revision}" ]]
then curl_url="${curl_url}?revision=${revision}";
fi
fi
if [[ ${#method[*]} > 0 ]] ; then curl_args+=(${method[@]}); fi
if [[ ${#user[*]} > 0 ]] ; then curl_args+=(${user[@]}); fi
echo ${CURL} -f -s "${curl_args[@]}" ${curl_url} > $ECHO_OUTPUT
${CURL} -f -s "${curl_args[@]}" ${curl_url}
}
function create_account() {
local -a newAccount=${1}
local -a URL="${STORE_URL}/system/accounts"
${CURL} -w "%{http_code}\n" -f -s -X POST -H "Content-Type: application/json" --data-binary @- \
-u ":${STORE_TOKEN_ADMIN}" ${URL} <<EOF
{"account": {"name": "${newAccount}"} }
EOF
}
function create_repository() {
local -a curl_args=()
local -a account="${STORE_ACCOUNT}"
local -a repository="new"
local -a class="${STORE_REPOSITORY_CLASS}"
local -a temporal_properties=""
local -a event_properties=""
local -a time_series_properties=""
while [[ "$#" > 0 ]] ; do
case "$1" in
--account) account="${2}"; shift 2;;
--class) class="${2}"; shift 2;;
--repository) repository="${2}"; shift 2;;
--temporal_properties) temporal_properties=", \"temporal-properties\": \"${2}\" "; shift 2 ;;
--event_properties) event_properties=", \"event-properties\": \"${2}\" "; shift 2 ;;
*) curl_args+=("${1}"); shift 1;;
esac
done
local -a URL="${STORE_URL}/system/accounts/${account}/repositories"
echo "create repository: ${account}/${repository}, class: ${class}" > $ECHO_OUTPUT
${CURL} -w "%{http_code}\n" -f -s -X POST "${curl_args[@]}" \
-H "Content-Type: application/json" \
-H "Accept: application/n-quads" \
--data-binary @- \
-u ":${STORE_TOKEN_ADMIN}" ${URL} <<EOF
{"repository": {"name": "${repository}", "class": "${class}"
${temporal_properties}
${event_properties}
}
}
EOF
}
function create_typed_repository() {
local -a newRepo=${1}
local -a repoClass=${2}
local -a URL="${STORE_URL}/system/accounts/${STORE_ACCOUNT}/repositories"
echo "$testName : $newRepo $repoClass"
${CURL} -w "%{http_code}\n" -f -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/n-quads" \
--data-binary @- \
-u ":${STORE_TOKEN_ADMIN}" ${URL} <<EOF
{"repository": { "name": "${newRepo}", "class": "lmdb-repository", "storageclass": "${repoClass}" } }
EOF
}
function delete_repository () {
local -a curl_args=()
local -a account="${STORE_ACCOUNT}"
local -a repository="new"
while [[ "$#" > 0 ]] ; do
case "$1" in
--account) account="${2}"; shift 2;;
--repository) repository="${2}"; shift 2;;
*) curl_args+=("${1}"); shift 1;;
esac
done
local -a URL="${STORE_URL}/system/accounts/${account}/repositories/${repository}"
echo "delete repository: ${account}/${repository}" > $ECHO_OUTPUT
${CURL} -w "%{http_code}\n" -f -s -X DELETE "${curl_args[@]}" \
-H "Accept: application/n-quads" \
-u ":${STORE_TOKEN_ADMIN}" ${URL} \
| tee ${ECHO_OUTPUT}
}
function delete_revisions () {
local -a curl_args=()
local -a account="${STORE_ACCOUNT}"
local -a repository="new"
local url_args=()
while [[ "$#" > 0 ]] ; do
case "$1" in
--account) account="${2}"; shift 2;;
--repository) repository="${2}"; shift 2;;
*=*) url_args+=("${1}"); shift 1;;
*) curl_args+=("${1}"); shift 1;;
esac
done
local -a curl_url="${STORE_URL}/system/accounts/${account}/repositories/${repository}/revisions"
if [[ ${#url_args[*]} > 0 ]] ; then curl_url=$(IFS='&' ; echo "${curl_url}?${url_args[*]}") ; fi
${CURL} -w "%{http_code}\n" -f -s -X DELETE "${curl_args[@]}" \
-o /dev/null \
-H "Accept: application/n-quads" \
-u ":${STORE_TOKEN_ADMIN}" ${curl_url}
##echo -e "\n\npress key to continue ${url_args[*]}" > /dev/tty; read
}
# repository_revision_count { --account $account } {--repository $repository}
# returns the revision count from dydra's repository introspection,
# 0 for an unrevisioned repository, >=1 for revisioned repositories
#
# the temporary file is used because as of "GNU bash, version 3.2.57(1)-release (arm64-apple-darwin22)"
# bash saw the "|" after inline data in the function definition as a syntax error
function curl_repository_revision_count () {
local -a curl_args=()
local -a account="${STORE_ACCOUNT}"
local -a repository="new"
while [[ "$#" > 0 ]] ; do
case "$1" in
--account) account="${2}"; shift 2;;
--repository) repository="${2}"; shift 2;;
*) curl_args+=("${1}"); shift 1;;
esac
done
cat > /tmp/curl_repository_revision_count.rq <<EOF
prefix dydra: <http://dydra.com/sparql-functions#>
select (dydra:repository-revision-count() as ?revisionCount)
where {}
EOF
curl_sparql_request --account "${account}" --repository "${repository}" revision-id=HEAD --data-binary @/tmp/curl_repository_revision_count.rq
}
function repository_revision_count () {
curl_repository_revision_count "$@" | tee $ECHO_OUTPUT | jq -r '.results.bindings[].revisionCount.value'
}
# repository_is_revisioned { --account $account } {--repository $repository}
# tests whether the repository is revisioned or not,
# regardless of whether it has actually stored multiple revisions or not
function repository_is_revisioned () {
repository_revision_count "$@" | egrep -q '^[1-9][0-9]*$'
}
# repository_list_revisions { --account $account } {--repository $repository}
# returns list of revision UUIDs
function repository_list_revisions () {
local -a user=(-u ":${STORE_TOKEN}")
local account=${STORE_ACCOUNT}
local repository=${STORE_REPOSITORY}
local -a curl_args=()
local curl_url=""
local -a accept_media_type=("-H" "Accept:text/plain")
local -a method=("-X" "GET")
local -a user=(-u ":${STORE_TOKEN}")
local revision=""
local repository="${STORE_REPOSITORY}"
local path=""
while [[ "$#" > 0 ]] ; do
case "$1" in
-H) case "$2" in
Accept:*) accept_media_type[1]="${2}"; shift 2;;
# Content-Type:*) content_media_type[1]="${2}"; shift 2;;
# *) curl_args+=("${1}" "${2}"); shift 2;;
esac ;;
--account) account="${2}"; shift 2;;
--repository) repository="${2}"; shift 2;;
-u|--user) if [[ -z "${2}" ]]; then user=(); else user[1]="${2}"; fi; shift 2;;
esac
done
if [[ ${#user[*]} > 0 ]] ; then curl_args+=(${user[@]}); fi
curl_url="${STORE_URL}/system/accounts/${account}/repositories/${repository}/revisions";
curl_args+=("${accept_media_type[@]}");
echo ${CURL} -f -s "${curl_args[@]}" ${curl_url} > $ECHO_OUTPUT
${CURL} -f -s "${curl_args[@]}" ${curl_url}
}
# repository_number_of_revisions { --account $account } {--repository $repository}
# returns the number of actual revisions,
# that is, it returns at least 1,