Skip to content

Commit

Permalink
use password from env
Browse files Browse the repository at this point in the history
  • Loading branch information
hasan7n committed Jul 12, 2023
1 parent 53edfc3 commit 305ded9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 39 deletions.
13 changes: 11 additions & 2 deletions cli/auto_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import argparse
import os


def execute_browser_flow(email, password, url):
Expand Down Expand Up @@ -57,8 +58,16 @@ def execute_browser_flow(email, password, url):
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--email")
parser.add_argument("--password")
parser.add_argument("--url")

args = parser.parse_args()
execute_browser_flow(args.email, args.password, args.url)

# load password from the environment
try:
password = os.environ["MOCK_USERS_PASSWORD"]
except KeyError:
raise RuntimeError(
"The environment variable `MOCK_USERS_PASSWORD` must be set."
)

execute_browser_flow(args.email, password, args.url)
7 changes: 2 additions & 5 deletions cli/auto_login.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#! /bin/bash

unset -v EMAIL
unset -v PASSWORD

while getopts e:p: flag
while getopts e: flag
do
case "${flag}" in
e) EMAIL=${OPTARG};;
p) PASSWORD=${OPTARG};;
esac
done

: ${EMAIL:?Missing -e}
: ${PASSWORD:?Missing -p}


get_url() {
Expand All @@ -31,6 +28,6 @@ PROC_STREAM=${COPROC[0]}
URL=$(get_url $PROC_STREAM)

LOGIN_SCRIPT="$(dirname "$0")/auto_login.py"
python $LOGIN_SCRIPT --email $EMAIL --password $PASSWORD --url $URL
python $LOGIN_SCRIPT --email $EMAIL --url $URL

wait ${COPROC_PID}
7 changes: 2 additions & 5 deletions cli/cli_chestxray_tutorial_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ checkFailed(){
DATAOWNER="[email protected]"
BENCHMARKOWNER="[email protected]"

DATAOWNERPASSWORD="Dataset123"
BENCHMARKOWNERPASSWORD="Benchmark123"

if ${FRESH}; then
clean
fi
Expand Down Expand Up @@ -85,13 +82,13 @@ echo "=========================================="
medperf profile activate testbenchmark
checkFailed "testbenchmark profile activation failed"

timeout -k ${TIMEOUT}s ${TIMEOUT}s bash $LOGIN_SCRIPT -e $BENCHMARKOWNER -p $BENCHMARKOWNERPASSWORD
timeout -k ${TIMEOUT}s ${TIMEOUT}s bash $LOGIN_SCRIPT -e $BENCHMARKOWNER
checkFailed "testbenchmark login failed"

medperf profile activate testdata
checkFailed "testdata profile activation failed"

timeout -k ${TIMEOUT}s ${TIMEOUT}s bash $LOGIN_SCRIPT -e $DATAOWNER -p $DATAOWNERPASSWORD
timeout -k ${TIMEOUT}s ${TIMEOUT}s bash $LOGIN_SCRIPT -e $DATAOWNER
checkFailed "testdata login failed"

echo "====================================="
Expand Down
13 changes: 4 additions & 9 deletions cli/cli_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ DATAOWNER="[email protected]"
BENCHMARKOWNER="[email protected]"
ADMIN="[email protected]"

MODELOWNERPASSWORD="Model123"
DATAOWNERPASSWORD="Dataset123"
BENCHMARKOWNERPASSWORD="Benchmark123"
ADMINPASSWORD="Admin123"

##########################################################
################### Start Testing ########################
##########################################################
Expand Down Expand Up @@ -154,19 +149,19 @@ echo "=========================================="
medperf profile activate testbenchmark
checkFailed "testbenchmark profile activation failed"

timeout -k ${TIMEOUT}s ${TIMEOUT}s bash $LOGIN_SCRIPT -e $BENCHMARKOWNER -p $BENCHMARKOWNERPASSWORD
timeout -k ${TIMEOUT}s ${TIMEOUT}s bash $LOGIN_SCRIPT -e $BENCHMARKOWNER
checkFailed "testbenchmark login failed"

medperf profile activate testmodel
checkFailed "testmodel profile activation failed"

timeout -k ${TIMEOUT}s ${TIMEOUT}s bash $LOGIN_SCRIPT -e $MODELOWNER -p $MODELOWNERPASSWORD
timeout -k ${TIMEOUT}s ${TIMEOUT}s bash $LOGIN_SCRIPT -e $MODELOWNER
checkFailed "testmodel login failed"

medperf profile activate testdata
checkFailed "testdata profile activation failed"

timeout -k ${TIMEOUT}s ${TIMEOUT}s bash $LOGIN_SCRIPT -e $DATAOWNER -p $DATAOWNERPASSWORD
timeout -k ${TIMEOUT}s ${TIMEOUT}s bash $LOGIN_SCRIPT -e $DATAOWNER
checkFailed "testdata login failed"
##########################################################

Expand Down Expand Up @@ -233,7 +228,7 @@ checkFailed "Benchmark submission failed"
BMK_UID=$(medperf benchmark ls | tail -n 1 | tr -s ' ' | cut -d ' ' -f 2)

# Approve benchmark
ADMIN_TOKEN=$(python $ADMIN_LOGIN_SCRIPT --email $ADMIN --password $ADMINPASSWORD --env dev)
ADMIN_TOKEN=$(python $ADMIN_LOGIN_SCRIPT --email $ADMIN --env dev)
checkFailed "Retrieving admin token failed"
curl -sk -X PUT $SERVER_URL$VERSION_PREFIX/benchmarks/$BMK_UID/ -d '{"approval_status": "APPROVED"}' -H 'Content-Type: application/json' -H "Authorization: Bearer $ADMIN_TOKEN"
checkFailed "Benchmark approval failed"
Expand Down
18 changes: 3 additions & 15 deletions server/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,9 @@ def seed(args):
api_server.validate(False)

# get tokens
admin_token = token_from_credentials(
"[email protected]",
"Admin123",
env="dev",
)
benchmark_owner_token = token_from_credentials(
"[email protected]",
"Benchmark123",
env="dev",
)
model_owner_token = token_from_credentials(
"[email protected]",
"Model123",
env="dev",
)
admin_token = token_from_credentials("[email protected]", env="dev")
benchmark_owner_token = token_from_credentials("[email protected]", env="dev")
model_owner_token = token_from_credentials("[email protected]", env="dev")

# set admin
set_user_as_admin(api_server, admin_token)
Expand Down
15 changes: 12 additions & 3 deletions server/token_from_credentials.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import requests
import argparse
import os


def token_from_credentials(email, password, env):
def token_from_credentials(email, env):
"""Retrieve access tokens using the Resource Owner Flow"""

# load password from the environment
try:
password = os.environ["MOCK_USERS_PASSWORD"]
except KeyError:
raise RuntimeError(
"The environment variable `MOCK_USERS_PASSWORD` must be set."
)

if env == "dev":
auth_domain = "dev-5xl8y6uuc2hig2ly.us.auth0.com"
audience = "https://localhost-dev/"
Expand Down Expand Up @@ -34,9 +44,8 @@ def token_from_credentials(email, password, env):
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--email")
parser.add_argument("--password")
parser.add_argument("--env", choices=["dev", "tutorial"])

args = parser.parse_args()
access_token = token_from_credentials(args.email, args.password, args.env)
access_token = token_from_credentials(args.email, args.env)
print(access_token)

0 comments on commit 305ded9

Please sign in to comment.