iterative / iterative/PyDrive2

Unable to list files with service account auth for GDriveFilesystem

Đang mở
#307 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
fs
Ngôn ngữ chính
Python
Star
670
Fork
75
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Hello, I'm using the latest version of the library `PyDrive2[fsspec]==1.17.0` and I'm trying to authenticate a service account (the SA email is shared with the drive I wish to test and the keys were generated, I doubt if this order matters).

I followed the steps provided in [the docs](https://docs.iterative.ai/PyDrive2/fsspec/#service-account) for the jsonkey file as a string. Its authenticated without errors however I'm unable to list files from the shared drive
1. GDrive API is hit
![image](https://github.com/iterative/PyDrive2/assets/117059509/95c29c8c-b372-4f7d-a75b-629e1978b3a8)
1. Listing of files with GDriveFilesystem returns empty (screenshot while debugging)
![gdrive_issue_proof (1)](https://github.com/iterative/PyDrive2/assets/117059509/3c9cd0c8-bd83-4131-9715-4d46a890aaf1)

Digging further, I followed steps mentioned in [this comment](https://github.com/iterative/PyDrive2/issues/21#issuecomment-929186260) and was able to list files with the `GDrive` object however. In fact I noticed the `GDrive` object being created [here](https://github.com/iterative/PyDrive2/blob/4d83d04948f16804026eaf4449ac02c75ba907a4/pydrive2/fs/spec.py#L234) and the files get listed (while debugging) when I used
```
file_list = self.client.ListFile().GetList()
```
![gdrive_issue_proof_ls (1)](https://github.com/iterative/PyDrive2/assets/117059509/2e58103c-344e-4f6a-9625-0de952b5df45)

Code snippet:
```python
from oauth2client.service_account import ServiceAccountCredentials
from pydrive2.auth import GoogleAuth
from pydrive2.fs import GDriveFileSystem
from pydrive2.drive import GoogleDrive

def _init_with_service_key(self, service_key_settings: str) -> GDriveFileSystem:
"""Creates a GDriveFileSystem with a service account key."""
# Attempt from issue #21
# scope = ["https://www.googleapis.com/auth/drive"]
# gauth = GoogleAuth()
# gauth.auth_method = 'service'
# gauth.credentials = ServiceAccountCredentials.from_json_keyfile_dict(service_key_settings, scopes=scope)
# drive = GoogleDrive(gauth)

# about = drive.GetAbout()
# file_list = drive.ListFile().GetList()
# gdrive = GDriveFileSystem(
# path="root",
# google_auth=gauth,
# use_service_account=True
# )

gdrive = GDriveFileSystem(
path="root",
use_service_account=True,
client_json=service_key_settings,
skip_instance_cache=True,
use_listings_cache=False
)
return gdrive
```

Any ideas on how I can proceed? Thanks in advance! :)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start with the service-account path in pydrive2/fs/spec.py around line 234 and compare its GDriveFileSystem setup with the working GoogleDrive ListFile().GetList() example in the issue. Reproduce the empty listing against the shared drive and trace the API request; done means GDriveFileSystem lists the files available to the service account.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
google-cloud, python
Lĩnh vực
api, cloud
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.