-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from jpgill86/gdrive
Add capability to download files from Google Drive
- Loading branch information
Showing
20 changed files
with
706 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ as ``neurotic.MetadataSelector``. | |
api/data | ||
api/download | ||
api/ftpauth | ||
api/gdrive | ||
api/metadata | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.. _api-gdrive: | ||
|
||
``neurotic.datasets.gdrive`` | ||
============================= | ||
|
||
.. automodule:: neurotic.datasets.gdrive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
.. _gdrive: | ||
|
||
Configuring for Google Drive | ||
============================ | ||
|
||
*neurotic* can download files from Google Drive (see :ref:`gdrive-urls` for | ||
details on how to specify remote URLs). **However, before this capability can | ||
be used, you must complete some manual configuration.** | ||
|
||
.. _gdrive-credentials: | ||
|
||
Generating a Client Credentials File | ||
------------------------------------ | ||
|
||
Because of limitations stated in Google's Terms of Service on what | ||
client-identifying credentials may be included with open source desktop | ||
applications, it is not possible for *neurotic* to supply users with an | ||
essential file needed for Google Drive access [1]_. This file is called the | ||
client credentials file, and you will need to generate one yourself. The | ||
instructions in this section will walk you through this one-time process. | ||
|
||
The file produced by following these steps, ``credentials.json``, does not | ||
provide access to your Google account, so your account is not compromised if | ||
the file falls into the wrong hands. However, it does identify you to Google as | ||
the owner of your installation of *neurotic* when you use it to download files; | ||
for this reason, you are discouraged from distributing this file to others, as | ||
abuse of it could cause Google to invalidate it and sanction your account. | ||
|
||
The steps below take advantage of a tutorial. If you know what you are doing, | ||
you can generate your own client credentials file from the `Google API | ||
Console`_ instead of using the tutorial, but that procedure is much more | ||
complicated. The tutorial is comparatively easy. | ||
|
||
1. Click the following link to open a web page. The web page is a tutorial for | ||
accessing Google Drive programmatically, as *neurotic* does. You will not | ||
need to follow the steps of this tutorial, but it does provide a convenient | ||
shortcut for generating the client credentials file. | ||
|
||
https://developers.google.com/drive/api/v3/quickstart/python | ||
|
||
2. Click the button labeled "Enable the Drive API" in step 1 of the tutorial. | ||
You may be prompted to log into Google, and then a series of dialog boxes | ||
will take you through the configuration process. Follow these steps: | ||
|
||
a. Enter new project name: "neurotic". | ||
b. Accept terms of service, if necessary. | ||
c. Click "Next". | ||
d. Configure your OAuth client: Choose "Desktop app". | ||
e. Click "Create". | ||
f. Click "Download Client Configuration", which will download a file called | ||
``credentials.json``. | ||
g. Click "Done". | ||
|
||
3. Launch *neurotic*. Under the Help menu, click "Open Google Drive credentials | ||
directory". Move the ``credentials.json`` file into this folder. | ||
|
||
4. Finally, close and restart *neurotic*. | ||
|
||
.. _gdrive-authorization: | ||
|
||
Authorizing *neurotic* to Access Google Drive | ||
--------------------------------------------- | ||
|
||
After you have created a client credentials file and saved it to the right | ||
location, you can attempt to download files from Google Drive using a properly | ||
configured metadata file (see :ref:`gdrive-urls` for details). When you do this | ||
for the first time, or when you use the "Request Google Drive authorization | ||
now" action under the Help menu, you will need to complete the following steps | ||
to authorize *neurotic* to access your Google Drive: | ||
|
||
1. Your web browser will open and ask you to sign into a Google account before | ||
continuing to "Quickstart". This name comes from the tutorial used to make | ||
the client credentials file. | ||
|
||
.. image:: _static/gdrive-auth-1.png | ||
:alt: Google Drive authorization flow, step 1 | ||
:width: 300 | ||
|
||
2. You will be presented with an intimidating warning about the app being | ||
unverified by Google. You will see your own email listed as the developer | ||
because this warning is associated with the client credentials file you | ||
created. | ||
|
||
.. image:: _static/gdrive-auth-2.png | ||
:alt: Google Drive authorization flow, step 2 | ||
:width: 400 | ||
|
||
3. Due to the terms-of-service limitations mentioned earlier, it is not | ||
possible for *neurotic* to distribute a client credentials file that would | ||
avoid presenting you with this warning. This policy exists because open | ||
source desktop applications can be modified by anyone with access to the | ||
system at any time, making it impossible for Google to certify that the | ||
mutable app has any particular identity and is safe. If you trust the | ||
application and are willing to proceed without Google's stamp of approval, | ||
click "Advanced" to reveal more text, and then click "Go to Quickstart | ||
(unsafe)", which will take you past this warning. | ||
|
||
.. image:: _static/gdrive-auth-3.png | ||
:alt: Google Drive authorization flow, step 3 | ||
:width: 400 | ||
|
||
4. To download files from your Google Drive, *neurotic* needs the privileges to | ||
access and read those files. Click "Allow" to indicate that you want to | ||
allow this. Note that again the app is referred to as "Quickstart" due to | ||
the settings of the tutorial used to create the client credentials file. | ||
|
||
.. image:: _static/gdrive-auth-4.png | ||
:alt: Google Drive authorization flow, step 4 | ||
:width: 300 | ||
|
||
5. Click "Allow" another time to confirm. Again, "Quickstart" refers to your | ||
client credentials file, which *neurotic* will use. | ||
|
||
.. image:: _static/gdrive-auth-5.png | ||
:alt: Google Drive authorization flow, step 5 | ||
:width: 300 | ||
|
||
6. When you see this message in your browser, you can close it: "The | ||
authorization flow has completed. You may close this window." | ||
|
||
The authorization process should now be complete, and you can begin using | ||
*neurotic* to access and download Google Drive files. | ||
|
||
.. _gdrive-save-token: | ||
|
||
Making Google Drive Authorization Persistent | ||
-------------------------------------------- | ||
|
||
By default, authorization persists only until *neurotic* is closed. Each time | ||
*neurotic* is restarted and you want to download from Google Drive again, you | ||
will need to repeat the authorization procedure described above. You can avoid | ||
this by configuring *neurotic* to retain the products of authorization (access | ||
and refresh tokens) indefinitely. See :ref:`global-config` for details on the | ||
global configuration file; by setting the ``save_token`` parameter under the | ||
``gdrive`` heading to ``true``, you can minimize the frequency of authorization | ||
requests. | ||
|
||
.. warning:: | ||
|
||
Enabling ``save_token`` is not recommended on systems used by others you do | ||
not trust. These others will be able to download files from your Google | ||
Drive using *neurotic* with the same level of ease you experience, and with | ||
access to the token file they could use it outside of *neurotic* to gain | ||
read-only access to your Google Drive and your Shared Drives. | ||
|
||
.. _gdrive-purge-token: | ||
|
||
Purging Google Drive Authorization | ||
---------------------------------- | ||
|
||
If you need to use a different Google account than the one you previously | ||
authorized *neurotic* to use, or if you set ``save_token=true`` and now want to | ||
remove the persistent access and refresh tokens from your system, you can use | ||
the "Purge Google Drive authorization token" action from the Help menu. After | ||
using this, you will need to complete the authorization procedure again, and | ||
you will have the opportunity to select a different Google account. | ||
|
||
|
||
.. [1] See `this StackOverflow question | ||
<https://stackoverflow.com/q/27585412>`_ for an informal discussion. | ||
.. _Google API Console: https://console.developers.google.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ at the same datasets! | |
citations | ||
metadata | ||
examples | ||
gdrive | ||
globalconfig | ||
api | ||
releasenotes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.