2024-04-17 12:23:26 -05:00
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
|
2025-03-19 16:30:32 -05:00
|
|
|
from keyring import backend, credentials
|
2024-04-17 12:23:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class KeyringTest(backend.KeyringBackend):
|
|
|
|
|
priority = 9
|
|
|
|
|
|
|
|
|
|
def get_password(self, service, username):
|
2025-04-29 12:54:07 -05:00
|
|
|
print(f"Keyring request for {username}@{service}", file=sys.stderr)
|
2025-03-19 16:30:32 -05:00
|
|
|
entries = json.loads(os.environ.get("KEYRING_TEST_CREDENTIALS", "{}"))
|
|
|
|
|
return entries.get(service, {}).get(username)
|
2024-04-17 12:23:26 -05:00
|
|
|
|
|
|
|
|
def set_password(self, service, username, password):
|
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
|
|
def delete_password(self, service, username):
|
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
|
|
def get_credential(self, service, username):
|
2025-04-29 12:54:07 -05:00
|
|
|
print(f"Keyring request for {service}", file=sys.stderr)
|
2025-03-19 16:30:32 -05:00
|
|
|
entries = json.loads(os.environ.get("KEYRING_TEST_CREDENTIALS", "{}"))
|
|
|
|
|
service_entries = entries.get(service, {})
|
|
|
|
|
if not service_entries:
|
|
|
|
|
return None
|
|
|
|
|
if username:
|
|
|
|
|
password = service_entries.get(username)
|
|
|
|
|
if not password:
|
|
|
|
|
return None
|
|
|
|
|
return credentials.SimpleCredential(username, password)
|
|
|
|
|
else:
|
|
|
|
|
return credentials.SimpleCredential(*list(service_entries.items())[0])
|