Verified Commit 012d8dbf authored by Jakob Moser's avatar Jakob Moser
Browse files

Reformat file

parent 8623b2aa
Loading
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ from ldap.directories import uni_id_directory
type UniId = str
type Password = str


def _get_connection(bind_uni_id: UniId, bind_password: Password) -> Connection:
    """
    Return a connection to the Uni LDAP directory, with the given bind user credentials.
@@ -38,19 +39,20 @@ def _get_credentials() -> tuple[UniId, Password]:
    password_from_env = os.getenv("BIND_PASSWORD")

    if not uni_id_from_env:
        raise ValueError("Please provide a bind Uni ID as env variable, e.g., using: export BIND_UNI_ID=\"ab123\"")
        raise ValueError(
            'Please provide a bind Uni ID as env variable, e.g., using: export BIND_UNI_ID="ab123"'
        )

    if not password_from_env:
        raise ValueError("Please provide a bind password as env variable, e.g., using: read -s BIND_PASSWORD; export BIND_PASSWORD")
        raise ValueError(
            "Please provide a bind password as env variable, e.g., using: read -s BIND_PASSWORD; export BIND_PASSWORD"
        )

    return uni_id_from_env, password_from_env



def main(
    uni_id: Annotated[
        str, typer.Argument(help="Uni ID to query")
    ],
    uni_id: Annotated[str, typer.Argument(help="Uni ID to query")],
) -> None:
    """
    Get details on a single user from Uni Heidelberg LDAP, given their Uni ID.
@@ -71,7 +73,11 @@ def main(
    connection = _get_connection(*credentials)

    with connection:
        connection.search("dc=ad,dc=uni-heidelberg,dc=de", f"(cn={escape_rdn(uni_id)})", attributes=["*"])
        connection.search(
            "dc=ad,dc=uni-heidelberg,dc=de",
            f"(cn={escape_rdn(uni_id)})",
            attributes=["*"],
        )
        print(connection.entries)