Skip to content

auth: support passing settings dict to GoogleAuth #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions pydrive2/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,28 +170,33 @@ class GoogleAuth(ApiAttributeMixin):
service = ApiAttribute("service")
auth_method = ApiAttribute("auth_method")

def __init__(self, settings_file="settings.yaml", http_timeout=None):
def __init__(
self, settings_file="settings.yaml", http_timeout=None, settings=None
):
"""Create an instance of GoogleAuth.

This constructor just sets the path of settings file.
It does not actually read the file.

:param settings_file: path of settings file. 'settings.yaml' by default.
:type settings_file: str.
:param settings: settigs dict.
:type settings: dict.
"""
self.http_timeout = http_timeout
ApiAttributeMixin.__init__(self)
self.thread_local = threading.local()
self.client_config = {}
try:
self.settings = LoadSettingsFile(settings_file)
except SettingsError:
self.settings = self.DEFAULT_SETTINGS
else:
if self.settings is None:
self.settings = self.DEFAULT_SETTINGS
else:
ValidateSettings(self.settings)

if settings is None and settings_file:
try:
settings = LoadSettingsFile(settings_file)
except SettingsError:
pass

self.settings = settings or self.DEFAULT_SETTINGS
ValidateSettings(self.settings)
Copy link
Contributor Author

@efiop efiop Jul 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit unrelated (was need for this change though), but now default settings are getting validated as well (which is nice).


self._storages = self._InitializeStoragesFromSettings()
# Only one (`file`) backend is supported now
self._default_storage = self._storages["file"]
Expand Down