From e234063b31188ed757937be0d1211671a01db819 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Fri, 16 Feb 2024 14:38:38 +0100 Subject: [PATCH] Use authorized API calls for Strapi data import (RPB-130) --- conf/rpb-sw-import.flux | 3 ++- conf/rpb-systematik-import.flux | 3 ++- conf/rpb-test-titel-import.flux | 3 ++- conf/rpb-titel-import.flux | 3 ++- conf/rppd-import.flux | 3 ++- transformAndImportFull.sh | 18 ++++++++++-------- transformAndImportTest.sh | 18 ++++++++++-------- 7 files changed, 30 insertions(+), 21 deletions(-) diff --git a/conf/rpb-sw-import.flux b/conf/rpb-sw-import.flux index aa7d0cd8..17eb0709 100644 --- a/conf/rpb-sw-import.flux +++ b/conf/rpb-sw-import.flux @@ -1,5 +1,6 @@ default IN_FILE = "test-output-sw.json"; // pass e.g. IN_FILE=output-sw-strapi.ndjson default HOST = "localhost"; // pass e.g. HOST=test-metadaten-nrw.hbz-nrw.de +default API_TOKEN = ""; // pass e.g. API_TOKEN=e8d... API_URL = "http://" + HOST + ":1337/api/rpb-authorities"; FLUX_DIR + "output/" + IN_FILE @@ -9,7 +10,7 @@ FLUX_DIR + "output/" + IN_FILE | stream-to-triples | template("{\"${p}\":${o}}") // wrap into 'data' object for strapi | log-object("Will POST: ") -| open-http(url=API_URL, method="POST", contentType="application/json") +| open-http(url=API_URL, method="POST", contentType="application/json", header="Authorization: Bearer " + API_TOKEN) | as-lines | log-object("POST Response: ") ; \ No newline at end of file diff --git a/conf/rpb-systematik-import.flux b/conf/rpb-systematik-import.flux index 53dee80b..1b07b83c 100644 --- a/conf/rpb-systematik-import.flux +++ b/conf/rpb-systematik-import.flux @@ -1,4 +1,5 @@ default HOST = "localhost"; // pass e.g. HOST=test-metadaten-nrw.hbz-nrw.de +default API_TOKEN = ""; // pass e.g. API_TOKEN=e8d... API_URL = "http://" + HOST + ":1337/api/" + PATH; "https://raw.githubusercontent.com/acka47/scripts/master/skos2json/" + INPUT @@ -8,7 +9,7 @@ API_URL = "http://" + HOST + ":1337/api/" + PATH; | stream-to-triples | template("{\"${p}\":${o}}") // wrap into 'data' object for strapi | log-object("Will POST: ") -| open-http(url=API_URL, method="POST", contentType="application/json") +| open-http(url=API_URL, method="POST", contentType="application/json", header="Authorization: Bearer " + API_TOKEN) | as-lines | log-object("POST Response: ") ; diff --git a/conf/rpb-test-titel-import.flux b/conf/rpb-test-titel-import.flux index 9b72199a..35d98b73 100644 --- a/conf/rpb-test-titel-import.flux +++ b/conf/rpb-test-titel-import.flux @@ -1,4 +1,5 @@ default HOST = "localhost"; // pass e.g. test-metadaten-nrw.hbz-nrw.de +default API_TOKEN = ""; // pass e.g. API_TOKEN=e8d... API_URL = "http://" + HOST + ":1337/api/" + PATH; FIX = " @@ -17,7 +18,7 @@ FLUX_DIR + "output/test-output-strapi.json" | stream-to-triples | template("{\"${p}\":${o}}") // wrap into 'data' object for strapi | log-object("Will POST: ") -| open-http(url=API_URL, method="POST", contentType="application/json") +| open-http(url=API_URL, method="POST", contentType="application/json", header="Authorization: Bearer " + API_TOKEN) | as-lines | log-object("POST Response: ") ; diff --git a/conf/rpb-titel-import.flux b/conf/rpb-titel-import.flux index eef54235..2b4c0bd0 100644 --- a/conf/rpb-titel-import.flux +++ b/conf/rpb-titel-import.flux @@ -1,4 +1,5 @@ default HOST = "localhost"; // pass e.g. test-metadaten-nrw.hbz-nrw.de +default API_TOKEN = ""; // pass e.g. API_TOKEN=e8d... API_URL = "http://" + HOST + ":1337/api/" + PATH; FIX = " @@ -17,7 +18,7 @@ FLUX_DIR + "output/output-strapi.ndjson" | stream-to-triples | template("{\"${p}\":${o}}") // wrap into 'data' object for strapi | log-object("Will POST: ") -| open-http(url=API_URL, method="POST", contentType="application/json") +| open-http(url=API_URL, method="POST", contentType="application/json", header="Authorization: Bearer " + API_TOKEN) | as-lines | log-object("POST Response: ") ; diff --git a/conf/rppd-import.flux b/conf/rppd-import.flux index af5104cd..264cd92c 100644 --- a/conf/rppd-import.flux +++ b/conf/rppd-import.flux @@ -1,5 +1,6 @@ default HOST = "localhost"; // pass e.g. HOST=test-metadaten-nrw.hbz-nrw.de default IN_FILE = "test-output-rppd.json"; // pass e.g. IN_FILE=output-rppd-strapi.ndjson +default API_TOKEN = ""; // pass e.g. API_TOKEN=e8d... API_URL = "http://" + HOST + ":1337/api/rppds"; FLUX_DIR + "output/" + IN_FILE @@ -9,7 +10,7 @@ FLUX_DIR + "output/" + IN_FILE | stream-to-triples | template("{\"${p}\":${o}}") // wrap into 'data' object for strapi | log-object("Will POST: ") -| open-http(url=API_URL, method="POST", contentType="application/json") +| open-http(url=API_URL, method="POST", contentType="application/json", header="Authorization: Bearer " + API_TOKEN) | as-lines | log-object("POST Response: ") ; diff --git a/transformAndImportFull.sh b/transformAndImportFull.sh index 3c1a8c47..136d09b7 100644 --- a/transformAndImportFull.sh +++ b/transformAndImportFull.sh @@ -6,28 +6,30 @@ IFS=$'\n\t' if [ -z "$@" ]; then echo "Pass host, e.g. 'localhost'"; else echo "Will import to '$@'"; fi HOST=$1 +# Create token in Strapi admin UI (Settings > API Tokens), set here or in environment +API_TOKEN=$API_TOKEN # Notationen # curl --request DELETE "http://$HOST:1337/api/rpb-notations/[1-5]" -sbt "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb.ndjson PATH=rpb-notations HOST=$HOST" +sbt "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb.ndjson PATH=rpb-notations HOST=$HOST API_TOKEN=$API_TOKEN" # curl --request DELETE "http://$HOST:1337/api/rpb-spatials/[1-5]" -sbt "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb-spatial.ndjson PATH=rpb-spatials HOST=$HOST" +sbt "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb-spatial.ndjson PATH=rpb-spatials HOST=$HOST API_TOKEN=$API_TOKEN" # Personen # curl --request DELETE "http://$HOST:1337/api/rppds/[1-5]" sbt "runMain rpb.ETL conf/rppd-to-strapi.flux IN_FILE=RPB-Export_HBZ_Bio.txt OUT_FILE=output-rppd-strapi.ndjson" -sbt "runMain rpb.ETL conf/rppd-import.flux IN_FILE=output-rppd-strapi.ndjson HOST=$HOST" +sbt "runMain rpb.ETL conf/rppd-import.flux IN_FILE=output-rppd-strapi.ndjson HOST=$HOST API_TOKEN=$API_TOKEN" # Normdaten # curl --request DELETE "http://$HOST:1337/api/rpb-authorities/[1-5]" sbt "runMain rpb.ETL conf/rpb-sw-to-strapi.flux IN_FILE=RPB-Export_HBZ_SW.txt OUT_FILE=output-sw-strapi.ndjson" -sbt "runMain rpb.ETL conf/rpb-sw-import.flux IN_FILE=output-sw-strapi.ndjson HOST=$HOST" +sbt "runMain rpb.ETL conf/rpb-sw-import.flux IN_FILE=output-sw-strapi.ndjson HOST=$HOST API_TOKEN=$API_TOKEN" # Titeldaten sbt "runMain rpb.ETL conf/rpb-titel-to-strapi.flux" # curl --request DELETE "http://$HOST:1337/api/articles/[1-5]" -sbt "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('f36_','u') PATH=articles HOST=$HOST" +sbt "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('f36_','u') PATH=articles HOST=$HOST API_TOKEN=$API_TOKEN" # curl --request DELETE "http://$HOST:1337/api/independent-works/[1-5]" -sbt "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('f36_','Monografie') PATH=independent-works HOST=$HOST" -sbt "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('f36_','Band') PATH=independent-works HOST=$HOST" -sbt "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('f36t','MultiVolumeBook') PATH=independent-works HOST=$HOST" +sbt "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('f36_','Monografie') PATH=independent-works HOST=$HOST API_TOKEN=$API_TOKEN" +sbt "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('f36_','Band') PATH=independent-works HOST=$HOST API_TOKEN=$API_TOKEN" +sbt "runMain rpb.ETL conf/rpb-titel-import.flux PICK=all_equal('f36t','MultiVolumeBook') PATH=independent-works HOST=$HOST API_TOKEN=$API_TOKEN" diff --git a/transformAndImportTest.sh b/transformAndImportTest.sh index 14d4d0f9..2d6b3a63 100644 --- a/transformAndImportTest.sh +++ b/transformAndImportTest.sh @@ -6,28 +6,30 @@ IFS=$'\n\t' if [ -z "$@" ]; then echo "Pass host, e.g. 'localhost'"; else echo "Will import to '$@'"; fi HOST=$1 +# Create token in Strapi admin UI (Settings > API Tokens), set here or in environment +API_TOKEN=$API_TOKEN # Notationen # curl --request DELETE "http://$HOST:1337/api/rpb-notations/[1-5]" -sbt "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb.ndjson PATH=rpb-notations HOST=$HOST" +sbt "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb.ndjson PATH=rpb-notations HOST=$HOST API_TOKEN=$API_TOKEN" # curl --request DELETE "http://$HOST:1337/api/rpb-spatials/[1-5]" -sbt "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb-spatial.ndjson PATH=rpb-spatials HOST=$HOST" +sbt "runMain rpb.ETL conf/rpb-systematik-import.flux INPUT=rpb-spatial.ndjson PATH=rpb-spatials HOST=$HOST API_TOKEN=$API_TOKEN" # Personen # curl --request DELETE "http://$HOST:1337/api/rppds/[1-5]" sbt "runMain rpb.ETL conf/rppd-to-strapi.flux IN_FILE=RPB-Export_HBZ_Bio_Test.txt OUT_FILE=test-output-rppd.json" -sbt "runMain rpb.ETL conf/rppd-import.flux IN_FILE=test-output-rppd.json HOST=$HOST" +sbt "runMain rpb.ETL conf/rppd-import.flux IN_FILE=test-output-rppd.json HOST=$HOST API_TOKEN=$API_TOKEN" # Normdaten # curl --request DELETE "http://$HOST:1337/api/rpb-authorities/[1-5]" sbt "runMain rpb.ETL conf/rpb-sw-to-strapi.flux IN_FILE=RPB-Export_HBZ_SW_Test.txt OUT_FILE=test-output-sw.json" -sbt "runMain rpb.ETL conf/rpb-sw-import.flux IN_FILE=test-output-sw.json HOST=$HOST" +sbt "runMain rpb.ETL conf/rpb-sw-import.flux IN_FILE=test-output-sw.json HOST=$HOST API_TOKEN=$API_TOKEN" # Titeldaten sbt "runMain rpb.ETL conf/rpb-test-titel-to-strapi.flux" # curl --request DELETE "http://$HOST:1337/api/articles/[1-5]" -sbt "runMain rpb.ETL conf/rpb-test-titel-import.flux PICK=all_equal('f36_','u') PATH=articles HOST=$HOST" +sbt "runMain rpb.ETL conf/rpb-test-titel-import.flux PICK=all_equal('f36_','u') PATH=articles HOST=$HOST API_TOKEN=$API_TOKEN" # curl --request DELETE "http://$HOST:1337/api/independent-works/[1-5]" -sbt "runMain rpb.ETL conf/rpb-test-titel-import.flux PICK=all_equal('f36_','Monografie') PATH=independent-works HOST=$HOST" -sbt "runMain rpb.ETL conf/rpb-test-titel-import.flux PICK=all_equal('f36_','Band') PATH=independent-works HOST=$HOST" -sbt "runMain rpb.ETL conf/rpb-test-titel-import.flux PICK=all_equal('f36t','MultiVolumeBook') PATH=independent-works HOST=$HOST" +sbt "runMain rpb.ETL conf/rpb-test-titel-import.flux PICK=all_equal('f36_','Monografie') PATH=independent-works HOST=$HOST API_TOKEN=$API_TOKEN" +sbt "runMain rpb.ETL conf/rpb-test-titel-import.flux PICK=all_equal('f36_','Band') PATH=independent-works HOST=$HOST API_TOKEN=$API_TOKEN" +sbt "runMain rpb.ETL conf/rpb-test-titel-import.flux PICK=all_equal('f36t','MultiVolumeBook') PATH=independent-works HOST=$HOST API_TOKEN=$API_TOKEN"