Skip to content

Commit

Permalink
auth: validate dictionary backend settings
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Jul 18, 2022
1 parent 37abe56 commit 439ce59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 9 additions & 4 deletions pydrive2/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion pydrive2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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},
}


Expand Down

0 comments on commit 439ce59

Please sign in to comment.