Closed benglewis closed 2 months ago
Hi there @benglewis :wave:!
Thank you for opening an issue. Our team will triage this as soon as we can. Please take a moment to review the troubleshooting steps which lists common error messages and their resolution steps.
Hi @benglewis - the error you're getting is because of quota (number of requests per second) to the Drive API. From the debug logs, the domain-wide delegation token was successfully created. To use the token, you need to pull the generated access_token
from the auth
action outputs. There's no mechanism for ADC to declare a DWD scope; only the generated token will have the DWD scope.
Hi @sethvargo ,
I would greatly appreciate if you can explain with an example how I can "pull the generated access_token
from the auth
action outputs". I tried multiple times to load the credentials JSON output, both from the file path and environment variable. Every time I got different weird errors (like the JSON being invalid and not credentials for a service account, for example). I would really appreciate just a little more guidance and some explanation of how I can use that access_token
properly.
Thank you in advance :)
@sethvargo I figured it out... Here are the needed changes:
from google.oauth2.credentials import Credentials
...
def main(folder_path: str, target_subfolder: str | None = None):
credentials = Credentials(os.environ["GOOGLE_APPLICATION_ACCESS_TOKEN"])
service = build("drive", "v3", credentials=credentials)
...
- name: Upload to Google Drive
env:
GOOGLE_DRIVE_FOLDER_ID: ${{ secrets.GOOGLE_DRIVE_FOLDER_ID }}
GOOGLE_APPLICATION_ACCESS_TOKEN: ${{ steps.auth.outputs.access_token }}
run: |
python .github/workflows/upload_to_gdrive.py my-folder target-folder-location
...
That is it :)
It's an output of the auth
action: https://github.com/google-github-actions/auth?tab=readme-ov-file#outputs
Right. The issue I faced was understanding how to use it together with the Python library. My above code shows how I was able to get it to work 🙂
TL;DR
I am also struggling with this. I am using the Python
googleapiclient
library to upload files to Google Drive using both GCP's Workload Identity Provider (WIF) and delegation to my Google Workspace user. The delegation seems to fail and instead, the files are uploaded as the service account (to which I already gave access to the folder), but it then gets stuck later on since it does not have sufficient storage space in it's Google Drive allowance. How can I get this work?Here's the contents of upload_to_gdrive.py:
Expected behavior
The files should be uploaded as my Google Workspace user
Observed behavior
The files are uploaded as the Service Account user until the user hits a storage limit (I have given the service account permissions to the folder and I am uploading large files)
Action YAML
Log output
Additional information
No response