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] Remove default NB_API_QUERY_URL value and fix ports used by full-stack setup script #42

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ services:
ports:
- "${NB_QUERY_PORT_HOST:-3000}:5173"
environment:
NB_API_QUERY_URL: ${NB_API_QUERY_URL:-http://localhost:8000/}
NB_API_QUERY_URL: ${NB_API_QUERY_URL}
16 changes: 8 additions & 8 deletions dev/graphdb_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ echo "Environment variables have been set from ${ENV_FILE_PATH}."

# Extract just the database name
DB_NAME="${NB_GRAPH_DB#repositories/}"
NB_GRAPH_PORT_HOST=${NB_GRAPH_PORT_HOST:-7200}
NB_GRAPH_PORT=${NB_GRAPH_PORT:-7200}

# Get the directory of this script to be able to find the data-config_template.ttl file
SCRIPT_DIR=$(dirname "$0")

echo "The GraphDB server is being accessed at http://localhost:${NB_GRAPH_PORT_HOST}."
echo "The GraphDB server is being accessed at http://localhost:${NB_GRAPH_PORT}."
alyssadai marked this conversation as resolved.
Show resolved Hide resolved

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

Expand All @@ -143,14 +143,14 @@ 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_HOST}/rest/security/users/admin -d "{\"password\": \""${ADMIN_PASS}"\"}"
curl -X PATCH --header 'Content-Type: application/json' http://localhost:${NB_GRAPH_PORT}/rest/security/users/admin -d "{\"password\": \""${ADMIN_PASS}"\"}"

# 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_HOST}/rest/security)
is_security_enabled=$(curl -s -X GET http://localhost:${NB_GRAPH_PORT}/rest/security)
if [ "${is_security_enabled}" = "false" ]; then
echo "Enabling password-based access control to all databases ..."
# NOTE: This command fails without credentials once security is enabled
curl -X POST --header 'Content-Type: application/json' -d true http://localhost:${NB_GRAPH_PORT_HOST}/rest/security
curl -X POST --header 'Content-Type: application/json' -d true http://localhost:${NB_GRAPH_PORT}/rest/security
else
echo "Password-based access control has already been enabled."
fi
Expand All @@ -159,7 +159,7 @@ 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_HOST}/rest/security/users/${NB_GRAPH_USERNAME} <<EOF
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}"
Expand All @@ -178,7 +178,7 @@ sed 's/rep:repositoryID "my_db" ;/rep:repositoryID "'"${DB_NAME}"'" ;/' ${SCRIPT
# 5. Create a new database
# Assumes data-config.ttl is in the same directory as this script!
echo "Creating the GraphDB database ${DB_NAME}..."
curl -X PUT -u "admin:${ADMIN_PASS}" http://localhost:${NB_GRAPH_PORT_HOST}/${NB_GRAPH_DB} --data-binary "@data-config.ttl" -H "Content-Type: application/x-turtle"
curl -X PUT -u "admin:${ADMIN_PASS}" http://localhost:${NB_GRAPH_PORT}/${NB_GRAPH_DB} --data-binary "@data-config.ttl" -H "Content-Type: application/x-turtle"

# 6. Grant newly created user access permission to the database
# Confirm user wants to proceed with changing user permissions
Expand All @@ -193,7 +193,7 @@ curl -X PUT -u "admin:${ADMIN_PASS}" http://localhost:${NB_GRAPH_PORT_HOST}/${NB

echo "Granting user ${NB_GRAPH_USERNAME} read/write permissions to database ${DB_NAME}..."
curl -X PUT --header 'Content-Type: application/json' -d "
{\"grantedAuthorities\": [\"WRITE_REPO_${DB_NAME}\",\"READ_REPO_${DB_NAME}\"]}" http://localhost:${NB_GRAPH_PORT_HOST}/rest/security/users/${NB_GRAPH_USERNAME} -u "admin:${ADMIN_PASS}"
{\"grantedAuthorities\": [\"WRITE_REPO_${DB_NAME}\",\"READ_REPO_${DB_NAME}\"]}" http://localhost:${NB_GRAPH_PORT}/rest/security/users/${NB_GRAPH_USERNAME} -u "admin:${ADMIN_PASS}"

echo "Done."

Expand Down
6 changes: 3 additions & 3 deletions dev/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
GRAPHDB_PID=$!

# Waiting for GraphDB to start
while ! curl --silent "localhost:${NB_GRAPH_PORT_HOST}/rest/repositories" | grep '\[\]'; do
while ! curl --silent "localhost:${NB_GRAPH_PORT}/rest/repositories" | grep '\[\]'; do
:
done

Expand All @@ -20,11 +20,11 @@ main() {
echo "Finished server setup."

echo "Adding datasets to the database..."
./add_data_to_graph.sh ./data localhost:${NB_GRAPH_PORT_HOST} ${NB_GRAPH_DB} "${NB_GRAPH_USERNAME}" "${NB_GRAPH_PASSWORD}"
./add_data_to_graph.sh ./data localhost:${NB_GRAPH_PORT} ${NB_GRAPH_DB} "${NB_GRAPH_USERNAME}" "${NB_GRAPH_PASSWORD}"
echo "Finished adding datasets to databases."

echo "Adding Neurobagel vocabulary to the database"
./add_data_to_graph.sh ./vocab localhost:${NB_GRAPH_PORT_HOST} ${NB_GRAPH_DB} "${NB_GRAPH_USERNAME}" "${NB_GRAPH_PASSWORD}"
./add_data_to_graph.sh ./vocab localhost:${NB_GRAPH_PORT} ${NB_GRAPH_DB} "${NB_GRAPH_USERNAME}" "${NB_GRAPH_PASSWORD}"
echo "Finished adding the Neurobagel vocabulary to the database."

echo "Finished setting up the Neurobagel graph backend."
Expand Down
4 changes: 2 additions & 2 deletions dev/template.env
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ NB_FAPI_PORT_HOST=8080
NB_FAPI_TAG=latest

# ---- CONFIGURATION FOR QUERY TOOL ----
# URL of the f-API as it will appear to a user
NB_API_QUERY_URL=http://localhost:8080
# URL of the n-API/f-API the query to will talk to, as it appears to a user
NB_API_QUERY_URL=http://XX.XX.XX.XX # REPLACE WITH YOUR API URL (AND PORT, IF APPLICABLE) AS IT APPEARS ON A USER'S MACHINE, OR localhost:<port> IF QUERY TOOL WILL ONLY BE ACCESSED FROM ITS HOST MACHINE
alyssadai marked this conversation as resolved.
Show resolved Hide resolved
# Docker image tag of the query tool (default latest)
NB_QUERY_TAG=latest
# Port that the query tool will be exposed on the host and likely the network (default 3000)
Expand Down