Beispiel #1
0
def _get_ids():
    if not FixedUser.enabled():
        return

    return {
        hashlib.md5(f"{user.username}:{user.password}".encode()).hexdigest():
        user.user_id
        for user in FixedUser.from_config()
    }
Beispiel #2
0
def init_mongo_data():
    try:
        _apply_migrations(log)

        _ensure_uuid()

        company_id = _ensure_company(get_default_company(), "clearml", log)

        _ensure_default_queue(company_id)

        fixed_mode = FixedUser.enabled()

        for user, credentials in config.get("secure.credentials", {}).items():
            user_data = {
                "name": user,
                "role": credentials.role,
                "email": f"{user}@example.com",
                "key": credentials.user_key,
                "secret": credentials.user_secret,
            }
            revoke = fixed_mode and credentials.get("revoke_in_fixed_mode",
                                                    False)
            user_id = _ensure_auth_user(user_data,
                                        company_id,
                                        log=log,
                                        revoke=revoke)
            if credentials.role == Role.user:
                _ensure_backend_user(user_id, company_id,
                                     credentials.display_name)

        if fixed_mode:
            log.info("Fixed users mode is enabled")
            FixedUser.validate()

            if FixedUser.guest_enabled():
                _ensure_company(FixedUser.get_guest_user().company, "guests",
                                log)

            for user in FixedUser.from_config():
                try:
                    ensure_fixed_user(user, log=log)
                except Exception as ex:
                    log.error(f"Failed creating fixed user {user.name}: {ex}")
    except Exception as ex:
        log.exception("Failed initializing mongodb")