From 9154d5a641ca00fc591d4b7edd5a3f3214cdd73f Mon Sep 17 00:00:00 2001 From: Olaf Rode <olaf.rode@fokus.fraunhofer.de> Date: Mon, 24 Mar 2025 15:25:19 +0100 Subject: [PATCH] feat: major renovation to integrate Catalog API features --- LICENSE | 201 ++++++++++++++++++++ README.md | 5 +- curl/README.md | 33 +++- curl/download.sh | 183 ++++++++++++++++++ curl/download_latest_icd10gm.sh | 17 -- curl/token.b64 | 1 - go-init/README.md | 9 - java-mvn-init/README.md | 3 - npm/{.npmrc => .npmrc.template} | 2 +- npm/README.md | 19 +- npm/create_npm_config.sh | 54 ++++++ npm/install_icd10gm-latest.sh | 1 - sushi-wrap/BfArM-Package-Test/sushi-wrap.sh | 186 ++++++++++++++++-- sushi-wrap/BfArM-Package-Test/token.b64 | 1 - sushi-wrap/README.md | 24 ++- 15 files changed, 688 insertions(+), 51 deletions(-) create mode 100644 LICENSE create mode 100755 curl/download.sh delete mode 100755 curl/download_latest_icd10gm.sh delete mode 100644 curl/token.b64 delete mode 100644 go-init/README.md delete mode 100644 java-mvn-init/README.md rename npm/{.npmrc => .npmrc.template} (51%) create mode 100755 npm/create_npm_config.sh delete mode 100755 npm/install_icd10gm-latest.sh delete mode 100644 sushi-wrap/BfArM-Package-Test/token.b64 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index cc478a9..aa1e56f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # bfarm-package-download -Kurzlebiges Beispielprojekt, um den automatiserten Download von FHIR-Packages aus der BfArM Package Registry (https://terminologien.bfram.de/packages/...) zu demonstrieren. +Innerhalb des Repositories wird eine Reihe von Beispiel-Clients und -Konfigurationen bereitgestellt, die den automatiserten Download von FHIR-Packages aus der BfArM Package Registry (https://terminologien.bfram.de/packages/...) demonstrieren: +- **[curl](./curl/README.md)** - Beispiel-Skript für das automatisierte Downloaden von FHIR-Packages über curl. Der Client unterstützt verschiedene Anwendungsszenarien im Kontext des Content-Syndication (z.B. Download der als "latest" getaggten Paketversionen, Download aller Paketversionen) +- **[npm](./npm/README.md)** - Beispielkonfiguration/-anleitung für die Nutzung von npm zum Download von FHIR-Packages. +- **[sushi-wrap](./sushi-wrap/README.md)** - Beispiel-Skript für die Integration mit Sushi diff --git a/curl/README.md b/curl/README.md index 2cc0c32..94130bf 100644 --- a/curl/README.md +++ b/curl/README.md @@ -1,10 +1,35 @@ -# curl +# curl-basiertes Download-Skript ## Voraussetzung - -Folgende Pakete werden zur Ausführung des Skripts benötigt: +Folgende Pakete werden zur Ausführung des Download-Skripts benötigt: - **curl** (command line tool and library for transferring data with URLs) - [Website](https://curl.se/) - **jq** (leightweight and flexible command-line JSON processor) - [Website](https://jqlang.github.io/jq/) -Bevor das Skript gestartet wird, muss ein gültiges Access Token für die Umgebung beschafft und in der Datei `token.b64` hinterlegt werden. Der einfachste Weg führt über die Webseite. \ No newline at end of file +## Vorbemerkung +Die vom ZTS angebotenen Inhalte unterliegen Downloadbedingungen, welche unter [https://terminologien.bfarm.de/download-conditions.html](https://terminologien.bfarm.de/download-conditions.html) eingesehen werden können. Bitte stellen Sie sicher, dass Sie die jeweils geltenden Bedingungen akzeptieren, bevor Sie das angebotenen Skript nutzen. Die Annahme der Bedingungen ist über den Kommandozeilenparameter ```-c``` zu bestätigen. + +## Kommandozeilenparameter +Folgende Kommandozeilenparameter werden durch das Tool unterstützt: + +- ```-c``` consent to download conditions - valid values: ```true```, ```false``` - default value: ```false``` +- ```-i``` packages to INCLUDE - valid values: ```ALL``` (for all available packages), ```{packagelist}``` (package names separated by ',') - e.g. ```bfarm.terminologien.icd10gm,bfarm.terminologien.ops``` - default: ```ALL``` +- ```-e``` packages to EXCLUDE from download - valid values: ```{packagelist}``` (package names separated by ',') - e.g. ```bfarm.terminologien.loinc,bfarm.terminologien.ucum``` - default: +- ```-l``` download only latest version of the package - valid values: ```true```, ```false``` - default: ```true``` +- ```-o``` output directory (location where downloaded packages will be stored) - e.g. ```./content``` - default: ```./packages``` + +## Beispiel-Nutzung +Das hier angebotene Skript ermöglicht die Umsetzung verschiedener Anwendungsfälle in Bezug auf den Download von Terminologiepaketen: + +**Download der jeweils aktuellen Version eines namentlich bekannten Pakets** + +```./download.sh -c [true|false] -i bfarm.terminologien.icd10gm -l true -o ./icd10gm``` + +**Download ALLER Version eines namentlich bekannten Pakets** + +```./download.sh -c [true|false] -i bfarm.terminologien.ops -l false -o ./ops``` + +**Download ALLER Version ALLER vom ZTS verwalteten Pakete** + +```./download.sh -c [true|false] -i ALL -l false -o ./packages``` + diff --git a/curl/download.sh b/curl/download.sh new file mode 100755 index 0000000..74f8855 --- /dev/null +++ b/curl/download.sh @@ -0,0 +1,183 @@ +#!/bin/bash + +# ==================================================================================================================================== +# Konfiguration +# ==================================================================================================================================== + +# Für die Verwendung des Skripts, muss explizit bestätigt werden, dass die jeweils geltenden Downloadbedingungen akzeptiert wurden +# vgl. https://terminologien.bfarm.de/download-conditions.html +ACCEPTED_DOWNLOAD_CONDITIONS=false + +# Pakete die heruntergeladen werden sollen. Diese können als Komma-separierte Liste angegeben werden. Wird der Wert 'ALL' gesetzt, werden alle Pakete heruntergeladen +INCLUDE_PACKAGES=ALL + +# Pakete die NICHT heruntergeladen werden sollen. Diese müssen als Komma-separierte Liste angegeben werden +EXCLUDE_PACKAGES= + +# Beschränken des Downloads auf die als "latest" gekennzeichnete Version +LATEST_ONLY=true + +# Der Wert der im User-Agent-Header gesetzt werden soll +USER_AGENT=example-zts-client/1.0 + +# Endpunktadressen der ZTS-API +CATALOG_API_ENDPOINT=https://terminologien.bfarm.de/packages/catalog +PACKAGE_API_ENDPOINT=https://terminologien.bfarm.de/packages +TOKEN_API_ENDPOINT=https://terminologien.bfarm.de/api/generate-token + +# Ausgabeverzeichnis, in welchem heruntergeladenen Paketversionen gespeichert werden +OUTPUT_DIR=./packages + +# Pfad-/Dateinamen für temporäre Arbeitsdateien +CATALOG_METADATA_FILE=catalog.json +PACKAGE_METADATA_FILE=response.json +CURRENT_DIR=$(pwd) + +# ==================================================================================================================================== +# Hilfsfunktionen +# ==================================================================================================================================== + +# Ausgabe der Verwendung des Skripts +usage() { + echo "$0 -c [true|false] -i [ALL|{packagelist}] -e {packageList} -l [true|false] -o [outputDir]" + echo "Command Line Parameters:" + echo " -c consent to download conditions" + echo " valid values: 'true', 'false'" + echo " default: 'false'" + echo " -i packages to INCLUDE" + echo " valid values: 'ALL' (for all available packages), {packagelist} (package names separated by ',') - e.g. 'bfarm.terminologien.icd10gm,bfarm.terminologien.ops'" + echo " default: 'ALL'" + echo " -e packages to EXCLUDE from download" + echo " valid values: {packagelist} (package names separated by ',') - e.g. 'bfarm.terminologien.loinc,bfarm.terminologien.ucum'" + echo " default: " + echo " -l download only latest version of the package" + echo " valid values: 'true', 'false'" + echo " default: 'true'" + echo " -o output directory (location where downloaded packages will be stored) - e.g. './content'" + echo " default: './packages'" + exit 1 +} + +# ==================================================================================================================================== +# Verarbeitung der Kommandozeilenparameter (inkl. Validierung) +# ==================================================================================================================================== + +# Kommandozeilenparameter verarbeiten +while getopts "c:i:e:l:o:" opt; do + case $opt in + c) ACCEPTED_DOWNLOAD_CONDITIONS="$OPTARG" ;; + i) INCLUDE_PACKAGES="$OPTARG" ;; + e) EXCLUDE_PACKAGES="$OPTARG" ;; + l) LATEST_ONLY="$OPTARG" ;; + o) OUTPUT_DIR="$OPTARG" ;; + *) usage ;; + esac +done + +# Prüfen, ob die Downloadbedingungen übernommen wurden +if [ "$ACCEPTED_DOWNLOAD_CONDITIONS" != true ]; then + echo "Die Downloadbedingungen müssen bestätigt werden" + usage +fi + +# Prüfen, ob die INCLUDE_PACKAGE Wert korrekt ist +if [[ ! "$INCLUDE_PACKAGES" =~ ^ALL$|^[a-z0-9]+(\.[a-z0-9]+)+(,[a-z0-9]+(\.[a-z0-9]+)+)*$ ]]; then + echo "Fehler bei der Angabe der zu inkludierenden Pakete: '$INCLUDE_PACKAGES'" + usage +fi + +# Prüfen, ob der EXCLUDE_PACKAGE Wert korrekt ist +if [[ ! "$EXCLUDE_PACKAGES" =~ ^$|^[a-z0-9]+(\.[a-z0-9]+)+(,[a-z0-9]+(\.[a-z0-9]+)+)*$ ]]; then + echo "Fehler bei der Angabe der zu exkludierenden Pakete: '$EXCLUDE_PACKAGES'" + usage +fi + +# Prüfen, ob der LATEST_ONLY Wert korrekt ist + + +# ==================================================================================================================================== +# Vorbereiten der Umgebung +# ==================================================================================================================================== + +# Anlegen eines (temporären) Ausgabeverzeichnisses +mkdir -p $OUTPUT_DIR + +# ==================================================================================================================================== +# Abruf der Liste unterstützten Pakete +# ==================================================================================================================================== + +# Catalog API nach Liste der unterstützten Terminologien anfragen - Das Ergebnis wird in eine Datei geschrieben +echo "Downloading ZTS-Gesamtkatalog" +curl --user-agent "{$USER_AGENT}" -X GET "{$CATALOG_API_ENDPOINT}" -H "Accept: application/json" -sS -o $CATALOG_METADATA_FILE + +# Iterieren über alle Einträge des Katalogs +jq -r '.[].name' $CATALOG_METADATA_FILE | while read name; do + + # Nur wenn die INCLUDE und EXCLUDE-Kriterien eingehalten werden, laden wir überhaupt Inhalte herunter + if [[ "$INCLUDE_PACKAGES" == *"$name"* || "$INCLUDE_PACKAGES" == "ALL" ]] && [[ ! "$EXCLUDE_PACKAGES" == *"$name"* ]]; then + + # Paketmetadaten herunterladen + curl --user-agent "{$USER_AGENT}" -sS -X GET "{$PACKAGE_API_ENDPOINT}/{$name}" -H "Accept: application/json" -o $PACKAGE_METADATA_FILE + + # Downloadbedingungen des Pakets akzeptieren + # Wichtig: Informieren Sie sich vorab über die jeweils gültigen Downloadbedingungen. Dies kann über die Webseite erfolgen. + DOWNLOAD_TOKEN=$(curl --user-agent "{$USER_AGENT}" -sS -X POST -H "Content-Type: application/json" -d "{\"packages\":[\"$name\"]}" $TOKEN_API_ENDPOINT | jq -r '.token') + + if [[ "$LATEST_ONLY" == true ]]; then + # Wir laden nur die als 'latest' gekennzeichnete Version des Pakets herunter + + # latest version mit "jq" aus Datei extrahieren + PACKAGE_VERSION_LATEST=$(jq -r '."dist-tags".latest' $PACKAGE_METADATA_FILE) + + # Wechsel ins Ausgabeverzeichnis + cd $OUTPUT_DIR + + # Erwarteten Dateinamen berechnen + EXPECTED_FILE_NAME="$name-$PACKAGE_VERSION_LATEST.tar.gz" + + # Paketversionen werden nur heruntergeladen, wenn es sie noch nicht gibt + if [ -f $EXPECTED_FILE_NAME ]; then + echo "$EXPECTED_FILE_NAME existiert bereits. Es wird kein erneuter Download dieser Paketversion durchgeführt." + else + # Latest Paketversion herunterladen (und Dateinamen aus Content-Disposition Header übernehmen) + echo "Downloading $name#$PACKAGE_VERSION_LATEST" + curl --user-agent "{$USER_AGENT}" -X GET "{$PACKAGE_API_ENDPOINT}/{$name}/{$PACKAGE_VERSION_LATEST}" -H "Authorization: Bearer $DOWNLOAD_TOKEN" -sS -O --remote-header-name + fi + + # Wechsel ins ursprüngliches Arbeitsverzeichnis + cd $CURRENT_DIR + + else + # Wir laden alle vorhandenen Versionen des Pakets herunter + jq -r '.versions | keys[]' $PACKAGE_METADATA_FILE | while read version; do + + # Wechsel ins Ausgabeverzeichnis + cd $OUTPUT_DIR + + # Erwarteten Dateinamen berechnen + EXPECTED_FILE_NAME="$name-$version.tar.gz" + + # Paketversionen werden nur heruntergeladen, wenn es sie noch nicht gibt + if [ -f $EXPECTED_FILE_NAME ]; then + echo "$EXPECTED_FILE_NAME existiert bereits. Es wird kein erneuter Download dieser Paketversion durchgeführt." + else + # Latest Paketversion herunterladen (und Dateinamen aus Content-Disposition Header übernehmen) + echo "Downloading $name#$version" + curl --user-agent "{$USER_AGENT}" -X GET "{$PACKAGE_API_ENDPOINT}/{$name}/{$version}" -H "Authorization: Bearer $DOWNLOAD_TOKEN" -sS -O --remote-header-name + fi + + # Wechsel ins ursprüngliches Arbeitsverzeichnis + cd $CURRENT_DIR + + done + fi + + # Heruntergeladene Metadaten des Pakets löschen + rm $PACKAGE_METADATA_FILE + + fi +done + +# Heruntergeladenen Katalog löschen +rm $CATALOG_METADATA_FILE + diff --git a/curl/download_latest_icd10gm.sh b/curl/download_latest_icd10gm.sh deleted file mode 100755 index 1e714ca..0000000 --- a/curl/download_latest_icd10gm.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -PACKAGE_ENDPOINT=https://terminologien.bfarm.de/packages -PACKAGE_NAME=bfarm.terminologien.icd10gm -PACKAGE_METADATA_FILE=response.json -TOKEN_FILE=token.b64 -DOWNLOAD_TOKEN=$(cat $TOKEN_FILE) - -# Paketmetadaten herunterladen -curl -X GET "{$PACKAGE_ENDPOINT}/{$PACKAGE_NAME}" -H "Accept: application/json" -o $PACKAGE_METADATA_FILE - -# latest version mit "jq" aus Datei extrahieren und ausgeben -PACKAGE_VERSION_LATEST=$(jq -r '."dist-tags".latest' $PACKAGE_METADATA_FILE) -rm $PACKAGE_METADATA_FILE - -# Latest Paketversion herunterladen (und Dateinamen aus Content-Disposition Header übernehmen) -curl -X GET "{$PACKAGE_ENDPOINT}/{$PACKAGE_NAME}/{$PACKAGE_VERSION_LATEST}" -H "Authorization: Bearer $DOWNLOAD_TOKEN" -O --remote-header-name diff --git a/curl/token.b64 b/curl/token.b64 deleted file mode 100644 index 75fa1b3..0000000 --- a/curl/token.b64 +++ /dev/null @@ -1 +0,0 @@ -{{ACCESS_TOKEN}} \ No newline at end of file diff --git a/go-init/README.md b/go-init/README.md deleted file mode 100644 index 4052886..0000000 --- a/go-init/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Projektinitialisierung -``` -mkdir package-loader -cd package-loader -go mod init package-loader -vim main.go -# Code schreiben :) -go run main.go -``` \ No newline at end of file diff --git a/java-mvn-init/README.md b/java-mvn-init/README.md deleted file mode 100644 index ecc0e4f..0000000 --- a/java-mvn-init/README.md +++ /dev/null @@ -1,3 +0,0 @@ - -# Projektinitialisierung -```mvn archetype:generate -DgroupId=org.example -DartifactId=package-load -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false``` \ No newline at end of file diff --git a/npm/.npmrc b/npm/.npmrc.template similarity index 51% rename from npm/.npmrc rename to npm/.npmrc.template index b79fa43..eeef9a7 100644 --- a/npm/.npmrc +++ b/npm/.npmrc.template @@ -1,3 +1,3 @@ registry=https://terminologien.bfarm.de/packages/ -//terminologien.bfarm.de/packages/:_authToken={{ACCESS_TOKEN}} +//terminologien.bfarm.de/packages/:_authToken={{DOWNLOAD_TOKEN}} cache=./.npm_cache diff --git a/npm/README.md b/npm/README.md index 4adb8fc..2b56439 100644 --- a/npm/README.md +++ b/npm/README.md @@ -5,5 +5,22 @@ Folgende Pakete werden zur Ausführung des Skripts benötigt: - **npm** (node package manager) - [Website](https://www.npmjs.com/) +- **curl** (command line tool and library for transferring data with URLs) - [Website](https://curl.se/) +- **jq** (leightweight and flexible command-line JSON processor) - [Website](https://jqlang.github.io/jq/) -Bevor das Skript gestartet wird, muss ein gültiges Access Token für die Umgebung beschafft und in der Datei `.npmrc` hinterlegt werden. Der einfachste Weg führt über die Webseite. \ No newline at end of file +## Vorbemerkung +Die vom ZTS angebotenen Inhalte unterliegen Downloadbedingungen, welche unter [https://terminologien.bfarm.de/download-conditions.html](https://terminologien.bfarm.de/download-conditions.html) eingesehen werden können. Bitte stellen Sie sicher, dass Sie die jeweils geltenden Bedingungen akzeptieren, bevor Sie das angebotenen Skript nutzen. Technisch wird das Akzeptieren der Downloadbedingungen durch die Verwendung eines Access Tokens zum Ausdruck gebracht, welches in der NPM-Konfigurationsdatei `.npmrc` hinterlegt werden kann. + +## Erstellen der ```npm``` Konfiguration +Voraussetzung für die Verwendung von ```npm``` ist das Erstellen einer passenden Konfigurationsdatei, die u.a. die für den Zugriff auf die Registry erforderlichen Credentials (in Form eines Download Token) beinhaltet. Die Erstellung einer Konfigurationsdatei kann dabei sehr einfach über das beigefügte Skript ```create_npm_config.sh``` erfolgen. + +Bevor das Skript gestartet werden kann, sind Anpassungen an dessen Inhalt erforderlich. Hierzu müssen in der Konfigurationsvariable ```ACCEPTED_DOWNLOAD_CONDITIONS``` alle Pakete aufgeführt werden, für die der Nutzer die Downloadbedingungen (s.o.) akzeptiert. + +Über ```./create_npm_config.sh``` kann das Skript gestartet werden. Für die hinterlegten Pakete wird nun ein Download Token erzeugt und mit einer Vorlagendatei (```.npmrc.template```) kombiniert. + +## Download von Paketen über ```npm``` +Über folgendes Kommando kann der Download eines bestimmten Pakets (hier ICD-10-GM in der aktuellen Version) über ```npm```angestoßen werden: + +```npm --registry https://terminologien.bfarm.de/packages install bfarm.terminologien.icd10gm --userconfig ./.npmrc --prefix ./.packages``` + +Im Ergebnis wird ein Verzeichnis ```.packages```angelegt in welchem das entpackte FHIR-Package in der 'latest'-Version zu finden ist. \ No newline at end of file diff --git a/npm/create_npm_config.sh b/npm/create_npm_config.sh new file mode 100755 index 0000000..b66424d --- /dev/null +++ b/npm/create_npm_config.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# ==================================================================================================================================== +# Konfiguration +# ==================================================================================================================================== + +# Liste der akzeptierten Downloadbedingungen, e.g. 'bfarm.terminologien.abc,bfarm.terminologien.xyz' +# Die Liste der akzeptierten Downloadbedingungen kann über die Webseite (https://terminologien.bfarm.de) eingesehen werden. +ACCEPTED_DOWNLOAD_CONDITIONS=bfarm.terminologien.abc,bfarm.terminologien.xyz + +# Der Endpunkt der Token-API +TOKEN_API_ENDPOINT=https://terminologien.bfarm.de/api/generate-token + +# Der Wert der im User-Agent-Header gesetzt werden soll +USER_AGENT=example-zts-client/1.0 + +# ==================================================================================================================================== +# Struktur für Request an TOKEN_API_ENDPOINT generieren +# ==================================================================================================================================== + +# Iterieren über die Liste der gemäß Konfiguration akzeptierten Downloadbedingungen +IFS=',' read -ra items <<< "$ACCEPTED_DOWNLOAD_CONDITIONS" +PACKAGE_ARRAY="[" +for item in "${items[@]}"; do + PACKAGE_ARRAY+="\"$item\"," +done + +# Letztes Komma entfernen und Array schließen +PACKAGE_ARRAY="${PACKAGE_ARRAY%,}]" + +# Request Body für Anfrage an Token-API erstellen +REQUEST_BODY="{\"packages\":$PACKAGE_ARRAY}" + +# ==================================================================================================================================== +# Token für den Download generieren +# ==================================================================================================================================== + +# Downloadbedingungen des Pakets akzeptieren +# Wichtig: Informieren Sie sich vorab über die jeweils gültigen Downloadbedingungen. Dies kann über die Webseite erfolgen. +DOWNLOAD_TOKEN=$(curl --user-agent "{$USER_AGENT}" -sS -X POST -H "Content-Type: application/json" -d "$REQUEST_BODY" $TOKEN_API_ENDPOINT | jq -r '.token') +echo "Download Token: $DOWNLOAD_TOKEN" +if [[ -z "$DOWNLOAD_TOKEN" ]] || [[ "$DOWNLOAD_TOKEN" == "null" ]]; then + echo "Error while generating Download Token. Please check the configuration for 'accepted download conditions'." + exit 1 +fi + +# ==================================================================================================================================== +# Konfigurationsdatei für npm erstellen +# ==================================================================================================================================== + +# Erstellen der Konfigurationsdatei aus dem Template +cat .npmrc.template | \ +sed "s/{{DOWNLOAD_TOKEN}}/$DOWNLOAD_TOKEN/g" > .npmrc +echo "Konfigurationsdatei erstellt" \ No newline at end of file diff --git a/npm/install_icd10gm-latest.sh b/npm/install_icd10gm-latest.sh deleted file mode 100755 index d46fb71..0000000 --- a/npm/install_icd10gm-latest.sh +++ /dev/null @@ -1 +0,0 @@ -npm --registry https://terminologien.bfarm.de/packages install bfarm.terminologien.icd10gm --userconfig ./.npmrc --prefix ./.packages \ No newline at end of file diff --git a/sushi-wrap/BfArM-Package-Test/sushi-wrap.sh b/sushi-wrap/BfArM-Package-Test/sushi-wrap.sh index c0eeaaf..71b724b 100755 --- a/sushi-wrap/BfArM-Package-Test/sushi-wrap.sh +++ b/sushi-wrap/BfArM-Package-Test/sushi-wrap.sh @@ -1,30 +1,194 @@ #!/bin/bash -PACKAGE_ENDPOINT=https://terminologien.bfarm.de/packages -TOKEN_FILE=token.b64 -DOWNLOAD_TOKEN=$(cat $TOKEN_FILE) +# ==================================================================================================================================== +# Konfiguration +# ==================================================================================================================================== + +# Liste der akzeptierten Downloadbedingungen, e.g. 'bfarm.terminologien.abc,bfarm.terminologien.xyz' +# Die Liste der akzeptierten Downloadbedingungen kann über die Webseite (https://terminologien.bfarm.de) eingesehen werden. +ACCEPTED_DOWNLOAD_CONDITIONS=bfarm.terminologien.abc,bfarm.terminologien.xyz + +# Der Wert der im User-Agent-Header gesetzt werden soll +USER_AGENT=example-zts-client/1.0 + +# Endpunktadressen der ZTS-API +CATALOG_API_ENDPOINT=https://terminologien.bfarm.de/packages/catalog +PACKAGE_API_ENDPOINT=https://terminologien.bfarm.de/packages +TOKEN_API_ENDPOINT=https://terminologien.bfarm.de/api/generate-token + +# Pfad-/Dateinamen für temporäre Arbeitsdateien +CATALOG_METADATA_FILE=catalog.json +FHIR_HOME=~/.fhir OUTPUT_DIR=$(uuidgen) +CURRENT_DIR=$(pwd) + +# Dies und Das +DEBUG=false +# ==================================================================================================================================== +# Hilfsfunktionen +# ==================================================================================================================================== + +# Funktion, die prüft, ob ein Element in einem Array enthalten ist +contains_element() { + local element="$1" + shift + local array=("$@") + for e in "${array[@]}"; do + if [[ "$e" == "$element" ]]; then + return 0 # gefunden + fi + done + return 1 # nicht gefunden +} + +# ==================================================================================================================================== +# Vorbereiten der Umgebung +# ==================================================================================================================================== + +# Anlegen eines (temporären) Ausgabeverzeichnisses mkdir $OUTPUT_DIR -yq '.dependencies' sushi-config.yaml | \ -grep bfarm | \ -sed 's/:/\//g' | \ -sed 's/ //g' | \ -xargs -I {} curl -X GET "{$PACKAGE_ENDPOINT}/{}" -H "Authorization: Bearer $DOWNLOAD_TOKEN" -O --remote-header-name --output-dir $OUTPUT_DIR + +# Umwandeln der Liste der akzeptierten Downloadbedingungen in ein Array +IFS=',' read -ra accepted_conditions_packages <<< "$ACCEPTED_DOWNLOAD_CONDITIONS" +echo "Pakete für die Downloadbedingungen akzeptiert wurden: ${accepted_conditions_packages[@]}" + +# ==================================================================================================================================== +# Abruf der Liste unterstützten Pakete +# ==================================================================================================================================== + +# Catalog API nach Liste der unterstützten Terminologien anfragen - Das Ergebnis wird in eine Datei geschrieben +curl --user-agent "{$USER_AGENT}" -X GET "{$CATALOG_API_ENDPOINT}" -H "Accept: application/json" -sS -o $CATALOG_METADATA_FILE + +# Katalog in Array umwandeln, welches die Namen der unterstützten Pakete enthält. Das sind die Pakete, die auf dem ZTS verfügbar sind und heruntergelden werden können. +available_packages=($(jq -r '.[].name' "$CATALOG_METADATA_FILE")) +if [[ "$DEBUG" == "true" ]]; then + echo "Auf ZTS verwaltete Pakete: ${available_packages[@]}" +fi + +# Schnittmenge zwischen den akzeptierten Paketen und den auf dem ZTS verfügbaren Paketen bilden. Das sind die Pakete, die heruntergeladen werden dürfen. +downloadable_packages=() +for item in "${accepted_conditions_packages[@]}"; do + for element in "${available_packages[@]}"; do + if [[ "$item" == "$element" ]]; then + downloadable_packages+=("$item") + fi + done +done + +if [[ "$DEBUG" == "true" ]]; then + echo "Für den Download 'verfügbare' Pakete: ${downloadable_packages[@]}" +fi + +# ==================================================================================================================================== +# Abhängigkeiten verarbeiten +# ==================================================================================================================================== + +# Abhängigkeiten aus der Konfigurationsdatei extrahieren und in ein Array umwandeln +dependencies=($(yq '.dependencies' sushi-config.yaml | sed 's/:.*//')) +if [[ "$DEBUG" == "true" ]]; then + echo "Definierte Paketabhängigkeiten: ${dependencies[@]}" +fi + +# Schnittmenge zwischen den benötigten Paketen und den herunterladbaren Paketen bilden +final_packages=() +for item in "${dependencies[@]}"; do + for element in "${downloadable_packages[@]}"; do + if [[ "$item" == "$element" ]]; then + final_packages+=("$item") + fi + done +done + +if [[ "$DEBUG" == "true" ]]; then + echo "Für den Download vorgesehene Pakete: ${final_packages[@]}" +fi + +# ==================================================================================================================================== +# Struktur für Request an TOKEN_API_ENDPOINT generieren +# ==================================================================================================================================== + +# Array für Anfrage Body vorbereiten +PACKAGE_ARRAY="[" +for item in "${downloadable_packages[@]}"; do + PACKAGE_ARRAY+="\"$item\"," +done + +# Letztes Komma entfernen und Array schließen +PACKAGE_ARRAY="${PACKAGE_ARRAY%,}]" + +# Request Body für Anfrage an Token-API erstellen +REQUEST_BODY="{\"packages\":$PACKAGE_ARRAY}" + +# ==================================================================================================================================== +# Token für den Download generieren +# ==================================================================================================================================== + +# Downloadbedingungen des Pakets akzeptieren +# Wichtig: Informieren Sie sich vorab über die jeweils gültigen Downloadbedingungen. Dies kann über die Webseite erfolgen. +DOWNLOAD_TOKEN=$(curl --user-agent "{$USER_AGENT}" -sS -X POST -H "Content-Type: application/json" -d "$REQUEST_BODY" $TOKEN_API_ENDPOINT | jq -r '.token') +if [[ "$DEBUG" == "true" ]]; then + echo "Download Token: $DOWNLOAD_TOKEN" +fi + +# ==================================================================================================================================== +# Download der Pakete +# ==================================================================================================================================== + +# Iterieren über die definierten Paketabhängigkeiten +yq '.dependencies' sushi-config.yaml | while read package_version; do + + # Paketname und Paketversion extrahieren + name=$(echo $package_version | sed 's/:.*//' | sed 's/^[[:space:]]*//; s/[[:space:]]*$//') + version=$(echo $package_version | sed 's/.*://' | sed 's/^[[:space:]]*//; s/[[:space:]]*$//') + + # Nur wenn das Paket in der Liste der herunterladbaren Pakete enthalten ist, wird es heruntergeladen + if contains_element $name "${downloadable_packages[@]}"; then + echo "Downloading $name#$version" + curl --user-agent "{$USER_AGENT}" -sS -X GET "{$PACKAGE_API_ENDPOINT}/{$name}/{$version}" -H "Authorization: Bearer $DOWNLOAD_TOKEN" -O --remote-header-name --output-dir $OUTPUT_DIR + else + echo "Das Paket '$name' ist auf dem ZTS entweder nicht verfügbar oder die Downloadbedingungen wurden nicht akzeptiert." + fi +done + +# ==================================================================================================================================== +# Heruntergeladene Pakete verarbeiten und in das FHIR-Verzeichnis verschieben +# ==================================================================================================================================== cd $OUTPUT_DIR for file in *.tar.gz; do + + # Paketname und Paketversion extrahieren export PACKAGE_NAME=$(echo $file | sed 's/-.*//') export PACKAGE_VERSION=$(echo $file | sed 's/.*-\([0-9.]*\)\..*/\1/') + + # Verzeichnis für das Paket anlegen mkdir $PACKAGE_NAME#$PACKAGE_VERSION + + # Entpacken des Pakets tar -xzf $file -C $PACKAGE_NAME#$PACKAGE_VERSION + + # Paketdatei löschen rm $file - mv -f $PACKAGE_NAME#$PACKAGE_VERSION ~/.fhir/packages + + # Verschieben des entpackten Pakets in das FHIR-Verzeichnis + if [ -d $FHIR_HOME/packages/$PACKAGE_NAME#$PACKAGE_VERSION ]; then + echo "Das Paket $PACKAGE_NAME#$PACKAGE_VERSION existiert bereits." + else + mv -f $PACKAGE_NAME#$PACKAGE_VERSION $FHIR_HOME/packages + fi done -cd .. +# Wechsel ins ursprüngliche Arbeitsverzeichnis und Aufräumen +cd $CURRENT_DIR rm -rf $OUTPUT_DIR +rm $CATALOG_METADATA_FILE + +# ==================================================================================================================================== +# Sushi aufrufen +# ==================================================================================================================================== sushi . -# So Long, and Thanks for All the Fsh + +echo "So Long, and Thanks for All the Fsh" diff --git a/sushi-wrap/BfArM-Package-Test/token.b64 b/sushi-wrap/BfArM-Package-Test/token.b64 deleted file mode 100644 index 75fa1b3..0000000 --- a/sushi-wrap/BfArM-Package-Test/token.b64 +++ /dev/null @@ -1 +0,0 @@ -{{ACCESS_TOKEN}} \ No newline at end of file diff --git a/sushi-wrap/README.md b/sushi-wrap/README.md index 2753996..71b9d7e 100644 --- a/sushi-wrap/README.md +++ b/sushi-wrap/README.md @@ -6,5 +6,27 @@ Folgende Pakete werden zur Ausführung des Skripts benötigt: - **curl** (command line tool and library for transferring data with URLs) - [Website](https://curl.se/) - **yq** (lightweight and portable command-line YAML processor) - [Website](https://github.com/mikefarah/yq/) +- **jq** (leightweight and flexible command-line JSON processor) - [Website](https://jqlang.github.io/jq/) + +## Vorbemerkung +Die vom ZTS angebotenen Inhalte unterliegen Downloadbedingungen, welche unter [https://terminologien.bfarm.de/download-conditions.html](https://terminologien.bfarm.de/download-conditions.html) eingesehen werden können. Bitte stellen Sie sicher, dass Sie die jeweils geltenden Bedingungen akzeptieren, bevor Sie das angebotenen Skript nutzen. Technisch wird das Akzeptieren der Downloadbedingungen durch die Verwendung eines Access Tokens zum Ausdruck gebracht, welches während der Ausführung des Wrapper-Skripts erzeugt wird. + +## Struktur und Funktionsweise +Das Verzeichnis ```/BfArM-Package-Test``` enthält eine "normales" Sushi-Beispiel-Projekt, welches um ein Wrapper-Skript (```sushi-wrap```) ergänzt wurde. Dieses Skript funktioniert dabei nach folgendem Muster: + +1. Abruf der Liste vom ZTS unterstützter Pakete über die Catalog API +2. Abgleich der heruntergeladenen Liste mit Liste der akzeptierten Downloadbedingungen +3. Parsen der Datei ```sushi-config.yaml```mittels ```yq``` +4. Herunterladen aller Abhängigkeiten, die vom ZTS bereitgestellt werden und für die die Downloadbedingungen akzeptiert wurden +5. Entpacken der heruntergeladenen Paket-Versionen und verschieben der Dateien in das FHIR-Home-Verzeichnis +6. Aufräumen +7. Ausführen von ```sushi``` + +Das Wrapper-Skript kann in beliebigen sushi-Projekten zum Einsatz kommen. + +## Notwendige Anpassungen am Wrapper-Skript +Bevor das Wrapper-Skript genutzt werden kann, sind Anpassungen an dessen Inhalt erforderlich. Hierzu müssen in der Konfigurationsvariable ```ACCEPTED_DOWNLOAD_CONDITIONS``` alle Pakete aufgeführt werden, für die der Nutzer die Downloadbedingungen (s.o.) akzeptiert. + +## Starten des Wrapper-Skripts +Durch den Aufruf von ```./sushi-wrap.sh```aus dem ```/BfArM-Package-Test```-Verzeichnis heraus, kann das Wrapper-Skript gestartet werden. -Bevor das Skript gestartet wird, muss ein gültiges Access Token für die Umgebung beschafft und in der Datei `token.b64` hinterlegt werden. Der einfachste Weg führt über die Webseite. \ No newline at end of file -- GitLab