Skip to content

keycloak

Checks for Keycloak token.

check_keycloak()

Check if the Keycloak token is set and valid.

Source code in dapla_team_cli/doctor/keycloak.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def check_keycloak() -> Check:
    """Check if the Keycloak token is set and valid."""
    token = get_token()

    if not token:
        return get_new_token("is not set")
    try:
        expired = has_expired(token)
        if expired:
            return get_new_token("has expired")

    except DecodeError:
        logger.debug("invalid token: %s", token)
        return get_new_token("is invalid", True)

    return Success(message="✅ Keycloak token is set and valid")

get_new_token(state, re=False)

Ask if user wants to set a new token.

Source code in dapla_team_cli/doctor/keycloak.py
18
19
20
21
22
23
24
25
def get_new_token(state: str, re: bool = False) -> Check:
    """Ask if user wants to set a new token."""
    permission = q.confirm(f"Keycloak token {state}, do you want to {'re' if re else ''}authenticate?").ask()
    if not permission:
        return Failure(message=f"❌ Keycloak token {state}")

    set_token(None)
    return check_keycloak()