Skip to content

Commit

Permalink
fix: bentoctl init-auth JSON error handling + compose up fix
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Oct 8, 2024
1 parent c4a60d8 commit b6722b9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions py_bentoctl/auth_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
PORTAL_PUBLIC_URL = os.getenv("BENTOV2_PORTAL_PUBLIC_URL")
CBIOPORTAL_URL = os.getenv("BENTO_CBIOPORTAL_PUBLIC_URL")

GATEWAY_CONTAINER_NAME = os.getenv("BENTOV2_GATEWAY_CONTAINER_NAME")

AUTH_REALM = os.getenv("BENTOV2_AUTH_REALM")
AUTH_CLIENT_ID = os.getenv("BENTOV2_AUTH_CLIENT_ID")
AUTH_PUBLIC_URL = os.getenv("BENTOV2_AUTH_PUBLIC_URL")
Expand Down Expand Up @@ -519,11 +521,14 @@ def create_test_user_if_needed(token: str) -> None:
],
})

create_user_res_data = create_user_res.json()
if create_user_res.ok:
create_user_res_data = create_user_res.json()
cprint(f" Created user: {AUTH_TEST_USER} (ID={create_user_res_data['id']}).", "green")
else:
err(f" Failed to create user: {AUTH_TEST_USER}; {create_user_res.status_code} {create_user_res_data}")
err(
f" Failed to create user: {AUTH_TEST_USER}; {create_user_res.status_code} "
f"{create_user_res.content.decode('utf-8')}"
)
exit(1)

def success():
Expand All @@ -536,11 +541,12 @@ def success():
info(f"[bentoctl] Using internal IdP, setting up Keycloak... (DEV_MODE={c.DEV_MODE})")

try:
docker_client.containers.get(GATEWAY_CONTAINER_NAME) # Needed to access Keycloak through the proper channel
docker_client.containers.get(AUTH_CONTAINER_NAME)
except requests.exceptions.HTTPError:
info(f" Starting {AUTH_CONTAINER_NAME}...")
# Not found, so we need to start it
subprocess.check_call((*c.COMPOSE, "up", "-d", "auth"))
subprocess.check_call((*c.COMPOSE, "up", "--wait", "-d", "auth", "gateway"))
success()

info(f" Signing in as {AUTH_ADMIN_USER}...")
Expand Down

0 comments on commit b6722b9

Please sign in to comment.