From 683c1ee2c1db16370cb8bbe646460e51856a9599 Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 13 Feb 2023 12:15:00 -0500 Subject: [PATCH] added script to import users w/ burnettk --- spiffworkflow-backend/bin/get_token | 12 +++++--- spiffworkflow-backend/bin/login_with_users | 33 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100755 spiffworkflow-backend/bin/login_with_users diff --git a/spiffworkflow-backend/bin/get_token b/spiffworkflow-backend/bin/get_token index c9e7bb0be..11e8bbf90 100755 --- a/spiffworkflow-backend/bin/get_token +++ b/spiffworkflow-backend/bin/get_token @@ -20,10 +20,14 @@ set -o errtrace -o errexit -o nounset -o pipefail # ./bin/get_token repeat_form_user_1 repeat_form_user_1 # actually has permissions to the resource in this script # ./bin/get_token ciadmin1 ciadmin1 '%2Fprocess-models' -KEYCLOAK_BASE_URL=http://localhost:7002 -# KEYCLOAK_BASE_URL=https://keycloak.dev.spiffworkflow.org -BACKEND_BASE_URL=http://localhost:7000 -# BACKEND_BASE_URL=https://api.dev.spiffworkflow.org +if [[ -z "${KEYCLOAK_BASE_URL:-}" ]]; then + # KEYCLOAK_BASE_URL=http://localhost:7002 + KEYCLOAK_BASE_URL=https://keycloak.dev.spiffworkflow.org +fi +if [[ -z "${BACKEND_BASE_URL:-}" ]]; then + # BACKEND_BASE_URL=http://localhost:7000 + BACKEND_BASE_URL=https://api.dev.spiffworkflow.org +fi REALM_NAME=spiffworkflow USERNAME=${1-fin} PASSWORD=${2-fin} diff --git a/spiffworkflow-backend/bin/login_with_users b/spiffworkflow-backend/bin/login_with_users new file mode 100755 index 000000000..1bb95409c --- /dev/null +++ b/spiffworkflow-backend/bin/login_with_users @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +function error_handler() { + >&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}." + exit "$2" +} +trap 'error_handler ${LINENO} $?' ERR +set -o errtrace -o errexit -o nounset -o pipefail + +script_dir="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" + +if [[ -z "${KEYCLOAK_BASE_URL:-}" ]]; then + # export KEYCLOAK_BASE_URL=http://localhost:7002 + export KEYCLOAK_BASE_URL=https://keycloak.dev.spiffworkflow.org +fi +if [[ -z "${BACKEND_BASE_URL:-}" ]]; then + # export BACKEND_BASE_URL=http://localhost:7000 + export BACKEND_BASE_URL=https://api.dev.spiffworkflow.org +fi + +user_list="${1}" +if [[ -z "${1:-}" ]]; then + >&2 echo "usage: $(basename "$0") [user_list]" + exit 1 +fi + +while read -r input_line; do + if ! grep -qE '(^#|email)' <<<"$input_line" ; then + username=$(awk -F '@' '{print $1}' <<<"$input_line") + access_token=$("${script_dir}/get_token" "$username" "$username") + curl -v -X POST "${BACKEND_BASE_URL}/v1.0/login_with_access_token?access_token=${access_token}" -H "Authorization: Bearer $access_token" + fi +done <"$user_list"