-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Gnome Online Accounts for getting credentials (optional)
- Loading branch information
Showing
4 changed files
with
88 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2023-2024 Vlad Krupinskii <mrvladus@yandex.ru> | ||
# SPDX-License-Identifier: MIT | ||
|
||
from errands.utils.logging import Log | ||
|
||
|
||
def get_goa_credentials(acc_name: str) -> dict[str, str] | None: | ||
""" | ||
If Gnome Online Accounts is installed, try to get account info. | ||
Only for password based account yet. | ||
""" | ||
|
||
try: | ||
import gi | ||
|
||
gi.require_version("Goa", "1.0") | ||
from gi.repository import Goa | ||
except (ValueError, ModuleNotFoundError): | ||
Log.debug("Gnome Online Accounts is not installed. Skipping...") | ||
return None | ||
|
||
client: Goa.Client = Goa.Client.new_sync(None) | ||
accounts: list[Goa.ObjectProxy] = client.get_accounts() | ||
for account in accounts: | ||
acc: Goa.AccountProxy = account.get_account() | ||
name: str = acc.get_cached_property("ProviderName").get_string() | ||
if name == acc_name: | ||
Log.debug(f"GOA: Getting data for {acc_name}") | ||
username, url = ( | ||
acc.get_cached_property("PresentationIdentity").get_string().split("@") | ||
) | ||
password = account.get_password_based().call_get_password_sync( | ||
arg_id=acc.get_cached_property("Id").get_string() | ||
) | ||
result: dict[str, str] = { | ||
"url": url, | ||
"username": username, | ||
"password": password, | ||
} | ||
return result | ||
return None |
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