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 Deployment Issues with Atlas Security step #169

Open
elenaterenzi opened this issue Jul 26, 2024 · 0 comments
Open

Fix Deployment Issues with Atlas Security step #169

elenaterenzi opened this issue Jul 26, 2024 · 0 comments

Comments

@elenaterenzi
Copy link

the script atlas_security.sh should be modified to wait for webapi to be ready before it tries to check that the users can successfully log in to the WebAPI.
The fix that worked for me is the following:

until curl -fsSI "$WEBAPI_URL/user/login/db" > /dev/null; do
    printf '\nsleep for 5s.\n'
    sleep 5
done

the above lines need to be added to the above mentioned script at line 15 so the overall script will look like:

#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset

LOG_FILE=/mnt/azscripts/azscriptoutput/all.log
exec >  >(tee -ia ${LOG_FILE})
exec 2> >(tee -ia ${LOG_FILE} >&2)

apk --update add postgresql-client apache2-utils

psql -v ON_ERROR_STOP=1 -e "$OHDSI_ADMIN_CONNECTION_STRING" -c "$SQL_ATLAS_CREATE_SECURITY"


until curl -fsSI "$WEBAPI_URL/user/login/db" > /dev/null; do
    printf '\nsleep for 5s.\n'
    sleep 5
done

count=1
for i in ${ATLAS_USERS//,/ }
do
    if [ "$(("$count" % 2))" -eq "1" ]; then
        username=$i
    else
        # shellcheck disable=SC2016
        atlaspw=$(htpasswd -bnBC 4 "" "$i" | tr -d ':\n' | sed 's/$2y/$2a/')
        psql -v ON_ERROR_STOP=1 -e "$OHDSI_ADMIN_CONNECTION_STRING" -c "insert into webapi_security.security (email,password) values ('$username', E'$atlaspw');"
        # this step adds some required rows/ids in the db
        curl "$WEBAPI_URL/user/login/db" --data-urlencode "login=$username" --data-urlencode "password=$i" --fail

        if [ "$count" = "2" ]; then
            psql -v ON_ERROR_STOP=1 -e "$OHDSI_ADMIN_CONNECTION_STRING" -c "insert into webapi.sec_user_role (user_id, role_id) values ((select id from webapi.sec_user where login='$username'),2);" #admin role
        else
            psql -v ON_ERROR_STOP=1 -e "$OHDSI_ADMIN_CONNECTION_STRING" -c "insert into webapi.sec_user_role (user_id, role_id) values ((select id from webapi.sec_user where login='$username'),10);" #atlas user role
        fi
    fi
    ((count++))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant