-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
337 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,34 @@ | ||
from typing import cast | ||
|
||
from onyx.configs.constants import KV_SETTINGS_KEY | ||
from onyx.configs.constants import OnyxRedisLocks | ||
from onyx.key_value_store.factory import get_kv_store | ||
from onyx.key_value_store.interface import KvKeyNotFoundError | ||
from onyx.redis.redis_pool import get_redis_client | ||
from onyx.server.settings.models import Settings | ||
from shared_configs.contextvars import CURRENT_TENANT_ID_CONTEXTVAR | ||
|
||
|
||
def load_settings() -> Settings: | ||
dynamic_config_store = get_kv_store() | ||
try: | ||
settings = Settings(**cast(dict, dynamic_config_store.load(KV_SETTINGS_KEY))) | ||
except KvKeyNotFoundError: | ||
settings = Settings() | ||
dynamic_config_store.store(KV_SETTINGS_KEY, settings.model_dump()) | ||
|
||
tenant_id = CURRENT_TENANT_ID_CONTEXTVAR.get() | ||
redis_client = get_redis_client(tenant_id=tenant_id) | ||
value = redis_client.get(OnyxRedisLocks.ANONYMOUS_USER_ENABLED) | ||
if value is not None: | ||
assert isinstance(value, bytes) | ||
anonymous_user_enabled = int(value.decode("utf-8")) == 1 | ||
else: | ||
# Default to False | ||
anonymous_user_enabled = False | ||
# Optionally store the default back to Redis | ||
redis_client.set(OnyxRedisLocks.ANONYMOUS_USER_ENABLED, "0") | ||
settings = Settings(anonymous_user_enabled=anonymous_user_enabled) | ||
return settings | ||
|
||
|
||
def store_settings(settings: Settings) -> None: | ||
if settings.anonymous_user_enabled is not None: | ||
tenant_id = CURRENT_TENANT_ID_CONTEXTVAR.get() | ||
redis_client = get_redis_client(tenant_id=tenant_id) | ||
redis_client.set( | ||
OnyxRedisLocks.ANONYMOUS_USER_ENABLED, | ||
"1" if settings.anonymous_user_enabled else "0", | ||
) | ||
|
||
get_kv_store().store(KV_SETTINGS_KEY, settings.model_dump()) |
Oops, something went wrong.