-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
2c14751
commit dd145b0
Showing
5 changed files
with
107 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,126 @@ | ||
import keyring | ||
|
||
|
||
def get_auth_token(username): | ||
return keyring.get_password("autorepo", f"gh_token_{username}") | ||
def get_auth_token(username: str) -> str | None: | ||
try: | ||
token = keyring.get_password("autorepo", f"gh_token_{username}") | ||
except Exception: | ||
return None | ||
|
||
return token | ||
|
||
def set_auth_token(username, token): | ||
keyring.set_password("autorepo", f"gh_token_{username}", token) | ||
|
||
def token_exists(username: str) -> bool: | ||
return get_auth_token(username) is not None | ||
|
||
def delete_auth_token(username): | ||
keyring.delete_password("autorepo", f"gh_token_{username}") | ||
|
||
def set_auth_token(username: str, token: str) -> bool: | ||
try: | ||
keyring.set_password("autorepo", f"gh_token_{username}", token) | ||
|
||
def set_current_user(username): | ||
keyring.set_password("autorepo", "current_user", username) | ||
return True | ||
except Exception: | ||
return False | ||
|
||
|
||
def get_current_user(): | ||
return keyring.get_password("autorepo", "current_user") | ||
def delete_auth_token(username: str) -> bool: | ||
if not token_exists(username): | ||
return False | ||
|
||
try: | ||
keyring.delete_password("autorepo", f"gh_token_{username}") | ||
|
||
def token_exists(username): | ||
return get_auth_token(username) is not None | ||
return True | ||
except Exception: | ||
return False | ||
|
||
|
||
def list_users(): | ||
users = keyring.get_password("autorepo", "all_users") | ||
if users is None: | ||
return [] | ||
def set_current_user(username: str) -> bool: | ||
if not token_exists(username): | ||
return False | ||
|
||
try: | ||
keyring.set_password("autorepo", "current_user", username) | ||
|
||
return True | ||
except Exception: | ||
return False | ||
|
||
|
||
def get_current_user() -> str | None: | ||
try: | ||
username = keyring.get_password("autorepo", "current_user") | ||
except Exception: | ||
return None | ||
|
||
return username | ||
|
||
|
||
def delete_current_user() -> bool: | ||
try: | ||
keyring.delete_password("autorepo", "current_user") | ||
|
||
return True | ||
except Exception: | ||
return False | ||
|
||
|
||
return users.split(";") | ||
def list_users() -> list: | ||
try: | ||
users = keyring.get_password("autorepo", "all_users") | ||
if users == "" or users == " " or users is None: | ||
return [] | ||
|
||
users = users.split(";") | ||
|
||
def add_user(username): | ||
return users | ||
except Exception: | ||
return [] | ||
|
||
|
||
def add_user(username: str) -> bool: | ||
users = list_users() | ||
if username in users: | ||
return | ||
return False | ||
|
||
users.append(username) | ||
|
||
keyring.set_password("autorepo", "all_users", ";".join(users)) | ||
try: | ||
keyring.set_password("autorepo", "all_users", ";".join(users)) | ||
|
||
return True | ||
except Exception: | ||
return False | ||
|
||
def remove_user(username): | ||
|
||
def remove_user(username: str) -> bool: | ||
users = list_users() | ||
if username not in users: | ||
return | ||
return False | ||
|
||
users.pop(users.index(username)) | ||
|
||
try: | ||
keyring.set_password("autorepo", "all_users", ";".join(users)) | ||
|
||
return True | ||
except Exception: | ||
return False | ||
|
||
|
||
def set_default_current_user() -> bool: | ||
users = list_users() | ||
if len(users) == 0: | ||
delete_current_user() | ||
|
||
return False | ||
|
||
return set_current_user(users[0]) | ||
|
||
users.remove(username) | ||
|
||
keyring.set_password("autorepo", "all_users", ";".join(users)) | ||
if __name__ == "__main__": | ||
print(list_users()) | ||
print(len(list_users())) | ||
print(get_current_user()) | ||
print(delete_current_user()) | ||
print(get_current_user()) |
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