Skip to content

Commit

Permalink
feat: improve gf-auth-stop command, add envvars for keycloak setup, a…
Browse files Browse the repository at this point in the history
…nd add instructions for running the auth server to CONTRIBUTING
  • Loading branch information
nikiburggraf committed Jun 17, 2024
1 parent e19d49a commit feb5fbd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 48 deletions.
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,37 @@ NOTE: You can also/alternatively run `pre-commit run` (changes only) or

## Run Genetic Forensic portal

First run the authentication application (Keycloak server) with the following
command

```bash
gf-auth-up
```

You are now ready to run the Genetic Forensic portal Streamlit application:

```bash
gf-portal
```

## Stopping the auth portal

To stop the auth portal, run the following command:

```bash
gf-auth-stop
```

## DO NOT RUN IN PROD: Exporting a list of DEV users from the DEV auth server

To update the Keycloak realm containing the dev users, you can run the following
command. Do not export your actual production users this way, as you do NOT want
those users being uploaded to the repository.

```bash
gf-auth-dev-export-DO-NOT-RUN-IN-PROD
```

## Testing

When making changes, please run the following tests:
Expand Down
43 changes: 1 addition & 42 deletions src/genetic_forensic_portal/app/common/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,7 @@ def login_success(message: str, username: str, token: dict[Any, Any]) -> None:

@st.experimental_dialog("Login") # type: ignore[misc]
def authentication_dialog() -> None:
login_tab, create_tab = st.tabs(
[
"Login to existing account",
"Create new account",
]
)

# Create new account
with create_tab:
st.write("Coming soon!")
# TODO figure out how to connect to keycloak to create an account
# with st.form(key="create"):
# username = st.text_input(
# label="Create a username",
# placeholder=None,
# help=None,
# disabled=st.session_state[AUTHENTICATED],
# )

# password = st.text_input(
# label="Create a password",
# placeholder=None,
# help=None,
# type="password",
# disabled=st.session_state[AUTHENTICATED],
# )

# if st.form_submit_button(
# label="Create account",
# type="primary",
# disabled=st.session_state[AUTHENTICATED],
# ):
# try:
# st.write(username)
# except Exception as e:
# st.error(e.message)
# st.session_state[AUTHENTICATED] = False
# else:
# login_success("Account created!", username)

# Login to existing account
with login_tab, st.form(key="login"):
with st.form(key="login"):
username = st.text_input(
label="Login username",
placeholder=None,
Expand Down
26 changes: 20 additions & 6 deletions src/genetic_forensic_portal/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,33 @@ def start_keycloak(force: bool = False) -> None:


def up() -> None:
if "DEFAULT_AUTH_ADMIN_PASSWORD" in os.environ:
os.environ["KEYCLOAK_ADMIN"] = os.environ["DEFAULT_AUTH_ADMIN_USERNAME"]
os.environ["KEYCLOAK_ADMIN_PASSWORD"] = os.environ[

Check warning on line 61 in src/genetic_forensic_portal/auth.py

View check run for this annotation

Codecov / codecov/patch

src/genetic_forensic_portal/auth.py#L58-L61

Added lines #L58 - L61 were not covered by tests
"DEFAULT_AUTH_ADMIN_PASSWORD"
]
elif (

Check warning on line 64 in src/genetic_forensic_portal/auth.py

View check run for this annotation

Codecov / codecov/patch

src/genetic_forensic_portal/auth.py#L64

Added line #L64 was not covered by tests
"KEYCLOAK_ADMIN" not in os.environ
or "KEYCLOAK_ADMIN_PASSWORD" not in os.environ
):
os.environ["KEYCLOAK_ADMIN"] = input("Enter Keycloak admin username: ")
os.environ["KEYCLOAK_ADMIN_PASSWORD"] = input("Enter Keycloak admin password: ")

Check warning on line 69 in src/genetic_forensic_portal/auth.py

View check run for this annotation

Codecov / codecov/patch

src/genetic_forensic_portal/auth.py#L68-L69

Added lines #L68 - L69 were not covered by tests

down()
logger.info("Starting Keycloak")
start_keycloak()

Check warning on line 73 in src/genetic_forensic_portal/auth.py

View check run for this annotation

Codecov / codecov/patch

src/genetic_forensic_portal/auth.py#L71-L73

Added lines #L71 - L73 were not covered by tests


def down() -> None:
logger.info("Stopping Keycloak")
keycloak_pid_file = KEYCLOAK_PID_FILE.open("r")
keycloak_pid = keycloak_pid_file.read()
keycloak_pid_file.close()
if KEYCLOAK_PID_FILE.exists():
logger.info("Stopping Keycloak")
keycloak_pid_file = KEYCLOAK_PID_FILE.open("r")
keycloak_pid = keycloak_pid_file.read()
keycloak_pid_file.close()

Check warning on line 81 in src/genetic_forensic_portal/auth.py

View check run for this annotation

Codecov / codecov/patch

src/genetic_forensic_portal/auth.py#L76-L81

Added lines #L76 - L81 were not covered by tests

os.system(f"kill -9 {keycloak_pid}")
os.system(f"kill -9 {keycloak_pid}")

Check warning on line 83 in src/genetic_forensic_portal/auth.py

View check run for this annotation

Codecov / codecov/patch

src/genetic_forensic_portal/auth.py#L83

Added line #L83 was not covered by tests

KEYCLOAK_PID_FILE.unlink()
KEYCLOAK_PID_FILE.unlink()

Check warning on line 85 in src/genetic_forensic_portal/auth.py

View check run for this annotation

Codecov / codecov/patch

src/genetic_forensic_portal/auth.py#L85

Added line #L85 was not covered by tests


def export() -> None:
Expand Down

0 comments on commit feb5fbd

Please sign in to comment.