Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Use jq to handle GraphDB credentials payloads with special characters #109

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions scripts/graphdb_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ SCRIPT_DIR=$(dirname "$0")

echo "The GraphDB server is being accessed at http://localhost:${NB_GRAPH_PORT}."

# Install jq to construct JSON payloads for curl requests while preserving special characters
echo "Installing jq..."
apk add --no-cache jq

##### First time GraphDB setup #####

if [ "${RUN_USER_SETUP}" = "on" ]; then
Expand All @@ -144,8 +148,9 @@ if [ "${RUN_USER_SETUP}" = "on" ]; then
# 1. Change database admin password
echo "Changing the admin password (note: if you have previously set the admin password, this has no effect)..."
# TODO: To change a *previously set* admin password, we need to also provide the current password via -u
curl -X PATCH --header 'Content-Type: application/json' http://localhost:${NB_GRAPH_PORT}/rest/security/users/admin -d "{\"password\": \""${ADMIN_PASS}"\"}"

json_payload=$(jq -n --arg pw "${ADMIN_PASS}" '{password: $pw}')
curl -X PATCH --header 'Content-Type: application/json' http://localhost:${NB_GRAPH_PORT}/rest/security/users/admin -d "${json_payload}"

# 2. If security is not enabled, enable it (i.e. allow only authenticated users access)
is_security_enabled=$(curl -s -X GET http://localhost:${NB_GRAPH_PORT}/rest/security)
if [ "${is_security_enabled}" = "false" ]; then
Expand All @@ -160,12 +165,8 @@ if [ "${RUN_USER_SETUP}" = "on" ]; then
# TODO: Separate this out from the first-time setup? As this can technically be run at any time to create additional users.
# NOTE: If user already exists, response will be "An account with the given username already exists." OK for script.
echo "Creating a new database user ${NB_GRAPH_USERNAME}..."
curl -X POST --header 'Content-Type: application/json' -u "admin:${ADMIN_PASS}" -d @- http://localhost:${NB_GRAPH_PORT}/rest/security/users/${NB_GRAPH_USERNAME} <<EOF
{
"username": "${NB_GRAPH_USERNAME}",
"password": "${NB_GRAPH_PASSWORD}"
}
EOF
json_payload=$(jq -n --arg un "${NB_GRAPH_USERNAME}" --arg pw "${NB_GRAPH_PASSWORD}" '{username: $un, password: $pw}')
curl -X POST --header 'Content-Type: application/json' -u "admin:${ADMIN_PASS}" -d "${json_payload}" http://localhost:${NB_GRAPH_PORT}/rest/security/users/${NB_GRAPH_USERNAME}
fi


Expand Down