Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
7757f50
use keyring to store credentials
maxjeblick Aug 9, 2023
e4a4d52
use keyring migration
maxjeblick Aug 9, 2023
dfd5238
update pipfile
maxjeblick Aug 9, 2023
5adb0f2
switch to yaml
maxjeblick Aug 9, 2023
f5b9514
try to fix ssh keyring
maxjeblick Aug 9, 2023
419689d
Merge branch 'max/use_keyring_storage' of github.com:h2oai/h2o-llmstu…
maxjeblick Aug 9, 2023
1a6a662
switch to DBUSkeyring
maxjeblick Aug 9, 2023
03d84f2
undo switch to DBUSkeyring
maxjeblick Aug 9, 2023
55c8a88
switch to DBUSkeyring
maxjeblick Aug 9, 2023
26ba4f7
set SecretService in make wave
maxjeblick Aug 9, 2023
75377d0
pop up if secret cannot be saved
maxjeblick Aug 9, 2023
340dfce
pop up if secret cannot be saved
maxjeblick Aug 9, 2023
1b641b6
pop up if secret cannot be saved
maxjeblick Aug 9, 2023
e86c4e2
show traceback
maxjeblick Aug 9, 2023
858860a
add factory method for credentials
maxjeblick Aug 10, 2023
449934b
add factory method for credentials
maxjeblick Aug 10, 2023
8023c7a
fix keyring deletion
maxjeblick Aug 10, 2023
24db4a8
fix format
maxjeblick Aug 10, 2023
351e9c6
fix format
maxjeblick Aug 10, 2023
a0ecff5
add tests for settings
maxjeblick Aug 10, 2023
a1cdb20
refact settings
maxjeblick Aug 10, 2023
4a07912
add readme with updates
maxjeblick Aug 10, 2023
a02a1cc
remove make keyring variable
maxjeblick Aug 10, 2023
fcdcf0c
fix format
maxjeblick Aug 10, 2023
bf4c673
better wording
maxjeblick Aug 10, 2023
95ff87b
better wording
maxjeblick Aug 10, 2023
0c0a0e6
update pipfile
maxjeblick Aug 10, 2023
1630aac
fix pr number
maxjeblick Aug 10, 2023
d59f483
Update requirements.txt
maxjeblick Aug 10, 2023
cc467f5
Merge branch 'main' into max/use_keyring_storage
maxjeblick Aug 10, 2023
105c209
remove uneeded variables
maxjeblick Aug 10, 2023
29ae38f
Merge branch 'main' into max/use_keyring_storage
maxjeblick Aug 14, 2023
3056be5
Merge branch 'max/use_keyring_storage' of github.com:h2oai/h2o-llmstu…
maxjeblick Aug 14, 2023
ebef445
Merge branch 'main' into max/use_keyring_storage
maxjeblick Aug 16, 2023
8efb651
fix merge conflicts
maxjeblick Aug 16, 2023
fcda030
refact saveing of user settings
maxjeblick Aug 16, 2023
ea1340f
refact saveing of user settings
maxjeblick Aug 16, 2023
33aad0c
add button for no setting error pop up
maxjeblick Aug 16, 2023
6e8a829
Merge branch 'main' into max/use_keyring_storage
maxjeblick Aug 16, 2023
512ad37
Merge branch 'main' into max/use_keyring_storage
maxjeblick Aug 17, 2023
e081e3c
first save/load secrets
maxjeblick Aug 17, 2023
a95cb5a
more type annotations
maxjeblick Aug 17, 2023
7581249
Merge branch 'main' into max/use_keyring_storage
maxjeblick Aug 17, 2023
037aadc
Merge branch 'main' into max/use_keyring_storage
maxjeblick Aug 17, 2023
e965ffc
Merge branch 'max/use_keyring_storage' of github.com:h2oai/h2o-llmstu…
maxjeblick Aug 17, 2023
a494812
fix merge conflicts
maxjeblick Sep 12, 2023
97faf73
add keyring dependency
maxjeblick Sep 12, 2023
051d006
Update requirements.txt
maxjeblick Sep 12, 2023
76d06bb
use env file as default
maxjeblick Sep 12, 2023
58a9359
disable keyring if it is not working
maxjeblick Sep 12, 2023
f14523d
disable keyring after 3 seconds
maxjeblick Sep 12, 2023
ae91449
disable keyring after 3 seconds
maxjeblick Sep 12, 2023
35a1a98
use timeout for keyring credential saver
maxjeblick Sep 12, 2023
4ba47a6
fix timeout
maxjeblick Sep 12, 2023
02f1bf6
fix timeout
maxjeblick Sep 12, 2023
6d12cfb
fix timeout
maxjeblick Sep 12, 2023
691e033
fix format
maxjeblick Sep 12, 2023
d6dc681
update readme comment
maxjeblick Sep 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more type annotations
  • Loading branch information
maxjeblick committed Aug 17, 2023
commit a95cb5a4d34516351658293a561710959632227f
36 changes: 18 additions & 18 deletions app_utils/utils/setting_utils.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq, what is the difference between app_utils > sections > settings.py vs app_utils > utils > setting_utils.py ? I wonder if they can be merged then you can revert from app_utils.utils.utils import X . utils.utils.utils looks a bit weird 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • setting_utils.py contains the backend logic associated with saving and loading the user settings/secrets.
  • settings.py contains the rendering/routing of the settings page itself.
  • utils.py contains utils for everything else frontend related.

At some point, utils.py should probably be split up into multiple files, as it was done for llm_studio utils.
I'd keep the split into utils and setting_utils as is to start the refactoring of utils.py.
Regarding the naming:
app_utils.utils.utils should probably be wave_app.utils.generic_utils or similar, that is, app_utils as a folder name is also a bit misleading.

Copy link
Contributor

@fatihozturkh2o fatihozturkh2o Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I think we can do the following steps to make it more tidy:

  • Move the utils folder out of app_utils. (Have them both at the same level)
    • Or, move the utils folder under the "llm_studio" folder since it's more related to the CLI part. (Wdyt?)
  • Rename app_utils -> wave_utils
  • Then under the utils folder rename setting_utils.py -> settings.py
  • Then under the utils folder rename utils.py -> general.py

Doesn't look complicated. Wdyt doing this in another PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree that renaming/moving components makes sense, in particular, for the frontend/wave part.
Let's probably address this in another PR.

Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ class NoSaver:

"""

def __init__(self, username, root_dir):
def __init__(self, username: str, root_dir: str):
self.username = username
self.root_dir = root_dir

def save(self, name, password):
def save(self, name: str, password: str):
pass

def load(self, name):
def load(self, name: str):
pass

def delete(self, name):
def delete(self, name: str):
pass


Expand All @@ -86,17 +86,17 @@ class KeyRingSaver(NoSaver):
Some machines may not have keyring installed, so this class may not be available.
"""

def __init__(self, username, root_dir):
def __init__(self, username: str, root_dir: str):
super().__init__(username, root_dir)
self.namespace = f"{username}_h2o_llmstudio"

def save(self, name, password):
def save(self, name: str, password: str):
keyring.set_password(self.namespace, name, password)

def load(self, name):
def load(self, name: str):
return keyring.get_password(self.namespace, name)

def delete(self, name):
def delete(self, name: str):
try:
keyring.delete_password(self.namespace, name)
except (KeyringLocked, PasswordDeleteError):
Expand All @@ -116,7 +116,7 @@ class EnvFileSaver(NoSaver):
def filename(self):
return os.path.join(self.root_dir, f"{self.username}.env")

def save(self, name, password):
def save(self, name: str, password: str):
data = {}
if os.path.exists(self.filename):
with open(self.filename, "r") as f:
Expand All @@ -125,12 +125,12 @@ def save(self, name, password):
with open(self.filename, "w") as f:
yaml.safe_dump(data, f)

def load(self, name):
def load(self, name: str):
with open(self.filename, "r") as f:
data = yaml.safe_load(f)
return data.get(name, None)

def delete(self, name):
def delete(self, name: str):
if os.path.exists(self.filename):
with open(self.filename, "r") as f:
data = yaml.safe_load(f)
Expand Down Expand Up @@ -160,13 +160,13 @@ def get(cls, name: str) -> Any:
return cls._secrets.get(name)


def _save_user_settings(q):
def _save_user_settings(q: Q):
user_settings = {key: q.client[key] for key in USER_SETTING_KEYS}
with open(_get_usersettings_path(q), "w") as f:
yaml.dump(user_settings, f)


def _load_user_settings(q):
def _load_user_settings(q: Q):
if os.path.isfile(_get_usersettings_path(q)):
logger.info("Reading user settings")
with open(_get_usersettings_path(q), "r") as f:
Expand All @@ -175,7 +175,7 @@ def _load_user_settings(q):
q.client[key] = user_settings.get(key, default_cfg.user_settings[key])


async def _save_secrets(q):
async def _save_secrets(q: Q):
secret_name, secrets_handler = _get_secrets_handler(q)
for key in SECRET_KEYS:
try:
Expand Down Expand Up @@ -217,7 +217,7 @@ async def _save_secrets(q):
]


def _load_secrets(q):
def _load_secrets(q: Q):
secret_name, secrets_handler = _get_secrets_handler(q)
for key in SECRET_KEYS:
try:
Expand All @@ -226,7 +226,7 @@ def _load_secrets(q):
logger.error(f"Could not load password {key} from {secret_name}")


def _get_secrets_handler(q):
def _get_secrets_handler(q: Q):
secret_name = (
q.client["credential_saver"] or default_cfg.user_settings["credential_saver"]
)
Expand All @@ -246,7 +246,7 @@ def _clear_secrets(q: Q, name: str, excludes=tuple()):
secrets_handler.delete(name)


def _maybe_migrate_to_yaml(q):
def _maybe_migrate_to_yaml(q: Q):
"""
Migrate user settings from a pickle file to a YAML file.
"""
Expand Down Expand Up @@ -286,5 +286,5 @@ def _maybe_migrate_to_yaml(q):
)


def _get_usersettings_path(q):
def _get_usersettings_path(q: Q):
return os.path.join(get_database_dir(q), f"{get_user_id(q)}.yaml")