|
| 1 | +# Setup Google Drive remote |
| 2 | + |
| 3 | +To setup Google Drive remote you should |
| 4 | +[create and configure Google Project](#create-and-configure-google-project) if |
| 5 | +you don't have one yet. |
| 6 | + |
| 7 | +## Create and Configure Google Project |
| 8 | + |
| 9 | +Since Google Drive has tight API usage quotas, one time creation and |
| 10 | +configuration of your own `Google Project` is required. Required `client_id` and |
| 11 | +`client_secret` can be generated only once and shared with other DVC users in |
| 12 | +your organization. |
| 13 | + |
| 14 | +1. Log into the [Google Cloud Platform](https://console.developers.google.com) |
| 15 | + account. |
| 16 | +2. Create `New Project` or select available one. |
| 17 | +3. From the left sidebar menu select `APIs & Services`->`Dashboard` and click |
| 18 | + `ENABLE APIS AND SERVICES` to search for `drive` to enable |
| 19 | + `Google Drive API` from search results. |
| 20 | + |
| 21 | +  |
| 22 | + |
| 23 | +4. From the left sidebar menu select `APIs & Services`->`Credentials` and click |
| 24 | + `Create Credentials` to select `OAuth client ID`. It might ask you to setup |
| 25 | + a product name on the consent screen. Complete all required steps. |
| 26 | + |
| 27 | +  |
| 28 | + |
| 29 | +5. Select `Other` for `Application type` and click `Create` to proceed with |
| 30 | + default `Name`. |
| 31 | +6. `client id` and `client secret` should be showed to you. Use them for |
| 32 | + further DVC's configuration. |
| 33 | + |
| 34 | +```dvc |
| 35 | +$ dvc remote add -d myremote gdrive://path # see URL format section below |
| 36 | +$ dvc remote modify myremote gdrive_client_id my_gdrive_client_id |
| 37 | +$ dvc remote modify myremote gdrive_client_secret gdrive_client_secret |
| 38 | +``` |
| 39 | + |
| 40 | +⚠️ It is safe to share `client_id` and `client_secret` at least with your |
| 41 | +teammates or inside organization. These credentialds are used to |
| 42 | +[retrieve authorization token](https://developers.google.com/identity/protocols/OAuth2) |
| 43 | +and |
| 44 | +[authenticate your application](https://developers.google.com/drive/api/v2/about-auth) |
| 45 | +to Google. Credentialds don't give access to your Google Drive storage. But |
| 46 | +Google limits global number of queires per each `client_id` and uncontrolled |
| 47 | +usage of your `cliend_id` by outer world can lead to |
| 48 | +[reaching the allowed Google API usage limits](https://developers.google.com/drive/api/v2/handle-errors?hl=ro#quota). |
| 49 | + |
| 50 | +## Google Drive remote URL format |
| 51 | + |
| 52 | +Remote URL can contain `root` which is an alias of your topmost Google Drive |
| 53 | +directory. To point the remote to the path under Google Drive's `root` |
| 54 | +directory: |
| 55 | + |
| 56 | +```dvc |
| 57 | +$ dvc remote add -d myremote gdrive://root/path/to/dir |
| 58 | +``` |
| 59 | + |
| 60 | +As alternative, you can obtain unique `Google Drive id` of your desired remote |
| 61 | +directory and use it as `base` remote path in URL: |
| 62 | + |
| 63 | +```dvc |
| 64 | +$ dvc remote add -d myremote gdrive://0AIac4JZqHhKmUk9PDA/path/to/dir |
| 65 | +``` |
| 66 | + |
| 67 | +To obtain `Google Drive id` of remote directory navigate inside that directory |
| 68 | +in your web browser with opened Google Drive and find `Google Drive id` in |
| 69 | +address bar. For example, for the URL |
| 70 | + |
| 71 | +```dvc |
| 72 | +https://drive.google.com/drive/folders/0AIac4JZqHhKmUk9PDA |
| 73 | +``` |
| 74 | + |
| 75 | +the `id` will be equal to `0AIac4JZqHhKmUk9PDA`. |
| 76 | + |
| 77 | +`Shared Team Drive` can be referenced by `Google Drive id` in the similar way. |
| 78 | + |
| 79 | +## Authorization |
| 80 | + |
| 81 | +On first usage of remote you will be prompted to visit access token generation |
| 82 | +link in browser. It will ask you to log into Google account associated with |
| 83 | +Google Drive, which you want to use as DVC's remote. Login process will guide |
| 84 | +you through granting Google Drive access permissions to the used Google Project. |
| 85 | + |
| 86 | +On successful access token generation token data will be cached in git ignored |
| 87 | +directory with path `.dvc/tmp/gdrive-user-credentials.json`. |
| 88 | + |
| 89 | +⚠️ Do not share token data with anyone else to prevent unauthorized access to |
| 90 | +your Google Drive. |
0 commit comments