From 439ce597536a63f8630900e4fa7f9fb0e87f3bdd Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 18 Jul 2022 19:56:31 +0300 Subject: [PATCH] auth: validate dictionary backend settings --- pydrive2/auth.py | 13 +++++++++---- pydrive2/settings.py | 6 +++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pydrive2/auth.py b/pydrive2/auth.py index a0131cc6..7be814c2 100644 --- a/pydrive2/auth.py +++ b/pydrive2/auth.py @@ -349,10 +349,15 @@ def _InitializeStoragesFromSettings(self): ) result[backend] = Storage(credentials_file) elif backend == "dictionary": - result[backend] = DictionaryStorage( - self.settings["save_credentials_dict"], - self.settings["save_credentials_key"], - ) + creds_dict = self.settings.get("save_credentials_dict") + if creds_dict is None: + raise InvalidConfigError("Please specify credentials dict") + + creds_key = self.settings.get("save_credentials_key") + if creds_key is None: + raise InvalidConfigError("Please specify credentials key") + + result[backend] = DictionaryStorage(creds_dict, creds_key) elif save_credentials: raise InvalidConfigError( "Unknown save_credentials_backend: %s" % backend diff --git a/pydrive2/settings.py b/pydrive2/settings.py index f5e84ab6..751ebf35 100644 --- a/pydrive2/settings.py +++ b/pydrive2/settings.py @@ -36,7 +36,9 @@ "type": str, "required": False, "dependency": [ - {"value": "file", "attribute": ["save_credentials_file"]} + {"value": "file", "attribute": ["save_credentials_file"]}, + {"value": "dictionary", "attribute": ["save_credentials_dict"]}, + {"value": "dictionary", "attribute": ["save_credentials_key"]}, ], }, "client_config": { @@ -84,6 +86,8 @@ "default": ["https://www.googleapis.com/auth/drive"], }, "save_credentials_file": {"type": str, "required": False}, + "save_credentials_dict": {"type": dict, "required": False}, + "save_credentials_key": {"type": str, "required": False}, }