Skip to content

Commit

Permalink
Merge pull request #26 from nfdi4health/fix/dv-init-bugs
Browse files Browse the repository at this point in the history
fix: bugs in dv init script
  • Loading branch information
vera authored Aug 9, 2024
2 parents 93fb27a + a8e8c76 commit 92cc88d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion k8s/dataverse/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.5.1
version: 0.5.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
53 changes: 32 additions & 21 deletions k8s/dataverse/persona/nfdi4health/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,50 @@ set -euo pipefail
# Set some defaults as documented
DATAVERSE_URL=${DATAVERSE_URL:-"http://dataverse:8080"}
export DATAVERSE_URL
# get current dir location

# get current dir location
SELF_LOCATION=${BOOTSTRAP_DIR}/${PERSONA}/
echo "SELF_LOCATION"
echo $SELF_LOCATION
echo "SELF_LOCATION = $SELF_LOCATION"

echo "Running base setup-all.sh (INSECURE MODE)"
"${BOOTSTRAP_DIR}"/base/setup-all.sh --insecure -p=admin1 | tee /tmp/setup-all.sh.out
API_TOKEN=$(grep apiToken "/tmp/setup-all.sh.out" | jq ".data.apiToken" | tr -d \")
export API_TOKEN

# configure curl
echo "# hide progress meter
-s
# authentication
-H \"X-Dataverse-key:$API_TOKEN\"
# fail script on server error
--fail-with-body" > ~/.curlrc

echo "Setting DOI provider to FAKE"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X PUT -d FAKE $DATAVERSE_URL/api/admin/settings/:DoiProvider
echo

echo "Setting superuser status"
curl -X POST "${DATAVERSE_URL}/api/admin/superuser/dataverseAdmin"
echo

echo "Publishing root dataverse"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST "${DATAVERSE_URL}/api/dataverses/:root/actions/:publish"
curl -X POST "${DATAVERSE_URL}/api/dataverses/:root/actions/:publish"
echo

#echo "Allow all API calls"
##curl -X PUT -d allow $DATAVERSE_URL/api/admin/settings/:BlockedApiPolicy
#curl -X PUT -d "admin,builtin-users,licenses" $DATAVERSE_URL/api/admin/settings/:BlockedApiEndpoints

echo "Set up OIDC provider"
curl -s -X POST -H "Content-type: application/json" --upload-file $SELF_LOCATION/keycloak.json $DATAVERSE_URL/api/admin/authenticationProviders
curl -X POST -H "Content-type: application/json" --upload-file $SELF_LOCATION/keycloak.json $DATAVERSE_URL/api/admin/authenticationProviders
echo

echo "Disable tabular file ingest"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X PUT -d 0 "${DATAVERSE_URL}/api/admin/settings/:TabularIngestSizeLimit"
curl -X PUT -d 0 "${DATAVERSE_URL}/api/admin/settings/:TabularIngestSizeLimit"
echo

echo "Setting file upload limit to 5Gi"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X PUT -d 5368709120 "${DATAVERSE_URL}/api/admin/settings/:MaxFileUploadSizeInBytes"
curl -X PUT -d 5368709120 "${DATAVERSE_URL}/api/admin/settings/:MaxFileUploadSizeInBytes"
echo

echo "Upload licenses"
Expand All @@ -46,27 +57,27 @@ TSVS=$(find "${LICENCE_PATH}" -maxdepth 1 -iname 'license-*.json')
# Load licences
while IFS= read -r TSV; do
echo "Loading ${TSV}: "
curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST -H "Content-type: application/json" $DATAVERSE_URL/api/licenses --upload-file ${TSV}
curl -X POST -H "Content-type: application/json" $DATAVERSE_URL/api/licenses --upload-file ${TSV}
echo
done <<< "${TSVS}"

echo "Disable custom terms of use"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X PUT -d false "${DATAVERSE_URL}/api/admin/settings/:AllowCustomTermsOfUse"
curl -X PUT -d false "${DATAVERSE_URL}/api/admin/settings/:AllowCustomTermsOfUse"
echo

echo "Creating users"
USERS=$(find $USERS_PATH -maxdepth 1 -iname '*.json')
while IFS= read -r USER; do
echo "Creating user $(jq -r '.identifier' $USER):"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST -H "Content-type:application/json" $DATAVERSE_URL/api/admin/authenticatedUsers --upload-file $USER
curl -X POST -H "Content-type:application/json" $DATAVERSE_URL/api/admin/authenticatedUsers --upload-file $USER
echo
done <<< "${USERS}"

echo "Creating roles"
ROLES=$(find $ROLES_PATH -maxdepth 1 -iname '*.json')
while IFS= read -r ROLE; do
echo "Creating role $(basename $ROLE .json):"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST -H "Content-type:application/json" $DATAVERSE_URL/api/admin/roles --upload-file $ROLE
curl -X POST -H "Content-type:application/json" $DATAVERSE_URL/api/admin/roles --upload-file $ROLE
echo
done <<< "${ROLES}"

Expand All @@ -85,11 +96,11 @@ while IFS= read -r DATAVERSE; do

DATAVERSE_ID=$(jq -r '.alias' $DATAVERSE)
echo "Creating dataverse $PARENT_DATAVERSE/$DATAVERSE_ID:"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$PARENT_DATAVERSE --upload-file $DATAVERSE
curl -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$PARENT_DATAVERSE --upload-file $DATAVERSE
echo

echo "Publishing dataverse $PARENT_DATAVERSE/$DATAVERSE_ID:"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/actions/:publish
curl -X POST $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/actions/:publish
echo

# echo "Adding @dataverseAdmin as admin to dataverse $PARENT_DATAVERSE/$DATAVERSE_ID:"
Expand All @@ -98,11 +109,11 @@ while IFS= read -r DATAVERSE; do

if [[ $DATAVERSE_ID == "nfdi4health" ]]; then
echo "Adding :authenticated-users as dataset creators to dataverse $PARENT_DATAVERSE/$DATAVERSE_ID:"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/assignments -d '{"assignee": ":authenticated-users", "role": "dsContributor"}'
curl -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/assignments -d '{"assignee": ":authenticated-users", "role": "dsContributor"}'
echo

echo "Adding :authenticated-users as dataset permission admins to dataverse $PARENT_DATAVERSE/$DATAVERSE_ID:"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/assignments -d '{"assignee": ":authenticated-users", "role": "dsPermAdmin"}'
curl -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/assignments -d '{"assignee": ":authenticated-users", "role": "dsPermAdmin"}'
echo
fi

Expand All @@ -111,21 +122,21 @@ while IFS= read -r DATAVERSE; do
# of "NFDI4Health" where no datasets are created so it can only be used for linking, not publishing
# (only curators should be able to publish)
echo "Adding :authenticated-users as dataset publisher to dataverse $PARENT_DATAVERSE/$DATAVERSE_ID:"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/assignments -d '{"assignee": ":authenticated-users", "role": "dsPublisher"}'
curl -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/assignments -d '{"assignee": ":authenticated-users", "role": "dsPublisher"}'
echo
else
# The import client and the admin are currently the only automatically configured curator user, all other curators
# must be added manually
echo "Creating curator group"
CURATOR_GROUP_ID=`curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/groups -d '{"description": "Curator users", "displayName": "Curators", "aliasInOwner": "curators"}' | jq .data.identifier -r`
CURATOR_GROUP_ID=`curl -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/groups -d '{"description": "Curator users", "displayName": "Curators", "aliasInOwner": "curators"}' | jq .data.identifier -r`
echo

echo "Adding @service-account-import_client and @dataverseAdmin to curator group"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/groups/curators/roleAssignees -d '["@service-account-import_client", "@dataverseAdmin"]'
curl -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/groups/curators/roleAssignees -d '["@service-account-import_client", "@dataverseAdmin"]'
echo

echo "Adding curator group as curator to dataverse $PARENT_DATAVERSE/$DATAVERSE_ID:"
curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/assignments -d "{\"assignee\": \"$CURATOR_GROUP_ID\", \"role\": \"curator\"}"
curl -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/assignments -d "{\"assignee\": \"$CURATOR_GROUP_ID\", \"role\": \"curator\"}"
echo
fi
done <<< "${DATAVERSES}"
Expand All @@ -139,15 +150,15 @@ METADATABLOCK_NAMES=("citation")
# Load metadata blocks
while IFS= read -r TSV; do
echo "Loading ${TSV}:"
curl -s -X POST -H "Content-type: text/tab-separated-values" $DATAVERSE_URL/api/admin/datasetfield/load --upload-file ${TSV}
curl -X POST -H "Content-type: text/tab-separated-values" $DATAVERSE_URL/api/admin/datasetfield/load --upload-file ${TSV}
echo
METADATABLOCK_NAMES=(${METADATABLOCK_NAMES[@]} "$(awk 'NR==2 {print $2}' $TSV)")
done <<< "${TSVS}"

echo "Activating metadata blocks"
while IFS= read -r DATAVERSE; do
DATAVERSE_ID=$(jq -r '.alias' $DATAVERSE)
curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/metadatablocks -d $(jq -c -n '$ARGS.positional' --args "${METADATABLOCK_NAMES[@]}")
curl -X POST -H "Content-Type: application/json" $DATAVERSE_URL/api/dataverses/$DATAVERSE_ID/metadatablocks -d $(jq -c -n '$ARGS.positional' --args "${METADATABLOCK_NAMES[@]}")
echo
done <<< "${DATAVERSES}"

Expand Down

0 comments on commit 92cc88d

Please sign in to comment.