-
Notifications
You must be signed in to change notification settings - Fork 33
Closed
Labels
Description
In 0.2.0 the simple TokenCache interface was replaced by newer API that now requires the user to write some code along these lines:
def build_persistence(location, fallback_to_plaintext=False):
"""Build a suitable persistence instance based your current OS"""
if sys.platform.startswith('win'):
return FilePersistenceWithDataProtection(location)
if sys.platform.startswith('darwin'):
return KeychainPersistence(location, "my_service_name", "my_account_name")
if sys.platform.startswith('linux'):
try:
return LibsecretPersistence(
location,
schema_name="my_schema_name",
attributes={"my_attr1": "foo", "my_attr2": "bar"},
)
except: # pylint: disable=bare-except
if not fallback_to_plaintext:
raise
logging.exception("Encryption unavailable. Opting in to plain text.")
return FilePersistence(location)
cache = PersistedTokenCache(build_persistence(...))(That's taken from the README, of course.)
Is there a reason why this logic needs to be reproduced in all user code that doesn't have more particular requirements? Or, conversely, are there many situation where this wouldn't be good enough?
If not, couldn't the library provide a get_default_persistence(location) method, that contains something along the lines of the above? I would be happy to raise a PR for this.