diff --git a/dvc/fs/gdrive.py b/dvc/fs/gdrive.py index 3198ad0283..ca7ae4b6de 100644 --- a/dvc/fs/gdrive.py +++ b/dvc/fs/gdrive.py @@ -109,6 +109,7 @@ def _validate_config(self): if ( self._use_service_account and not self._service_account_json_file_path + and GDriveFileSystem.GDRIVE_CREDENTIALS_DATA not in os.environ ): raise DvcException( "To use service account, set " diff --git a/tests/unit/remote/test_gdrive.py b/tests/unit/remote/test_gdrive.py index 9c23c323be..e03ff5642f 100644 --- a/tests/unit/remote/test_gdrive.py +++ b/tests/unit/remote/test_gdrive.py @@ -41,3 +41,11 @@ def test_drive(self, dvc, monkeypatch): ) with pytest.raises(GDriveAuthError): assert fs.fs + + def test_service_account_using_env_var(self, dvc, monkeypatch): + monkeypatch.setenv(GDriveFileSystem.GDRIVE_CREDENTIALS_DATA, "foo") + GDriveFileSystem( + gdrive_credentials_tmp_dir=dvc.tmp_dir, + gdrive_use_service_account=True, + **self.CONFIG + )