Trying to connect google drive to paperspace gradient notebook - google-drive-api

I'm trying to mount google drive to paperspace notebook using google-drive-ocamlfuse with the following code
sudo add-apt-repository ppa:alessandro-strada/ppa
sudo apt update && sudo apt install google-drive-ocamlfuse
but when launching with
google-drive-ocamlfuse
there's an error:
/bin/sh: 1: firefox: not found
/bin/sh: 1: google-chrome: not found
/bin/sh: 1: chromium-browser: not found
/bin/sh: 1: open: not found
Cannot retrieve auth tokens.
Failure("Error opening URL:https://accounts.google.com/o/oauth2/auth?client_id=..........
ocamlfuse's github page has instructions on "Headless Usage & Authorization" but it's for local machine not for something like paperspace.
is there any way i can use google-drive-ocamlfuse to mount the drive?
is there any other better/simpler method to mount google drive on paperspace gradient?

Short answer:
There is no way to mount Google Drive as filesystem on paperspace gradient.
Long answer:
Your error message says cannot open browser. You are correct, should use headless mode [https://github.com/astrada/google-drive-ocamlfuse/wiki/Headless-Usage-&-Authorization]. Basically create an OAuth App, note down the client-id and client-secret, then authenticate using google-drive-ocamlfuse -headless -id client-id -secret client-secret.
But even if the authentication step success, you will still encounter error like fuse: device not found, try 'modprobe fuse' first. It is because Paperspace gradient notebook is running as container. A container cannot perform fuse operation unless it has SYS_ADMIN capability. (See FUSE inside Docker). In this case, we have no control on how paperspace running their container. So we are unable to mount filesystem on paperspace gradient.
However, you can use something like https://github.com/iterative/PyDrive2 to access Google Drive file.

Related

Script that uses google-drive-ocamlfuse fails when run through Rundeck

I have a script that runs fine when run directly from the shell of the server hosting Rundeck. It uses google-drive-ocamlfuse to mount my google drive to a local directory, creates a folder in the directory, and then unmounts.
name=New-Folder-Name
google-drive-ocamlfuse /home/user/mygoogledrive/
mkdir /home/user/mygoogledrive/$name
fusermount -u /home/user/mygoogledrive/
If I try to run this as an ad hoc command in Rundeck:
sudo ./var/lib/rundeck/scripts/create-folder.sh
... it errors out with:
Error: no DISPLAY environment variable specified
/bin/sh: 1: google-chrome: not found
/bin/sh: 1: chromium-browser: not found
/bin/sh: 1: open: not found
Cannot retrieve auth tokens.
Failure("Error opening URL:https://accounts.google.com/o/oauth2/auth?client_id=REDACTING-PERSONAL-INFO")
mkdir: cannot create directory ‘/home/user/mygoogledrive/New-Folder-Name’: No such file or directory
fusermount: failed to unmount /home/home-db/mygoogledrive: Invalid argument
I am new to Rundeck and am not yet comfortable with permissions and I don't have a good sense of how a command is being run on the server by Rundeck. It must be accessing and executing the file, given the error output, but maybe there are some limitations in the environment due to permissioning that doesn't allow for the use of certain libraries need by google-drive-ocamlfuse? Any ideas?
To use sudo on a target remote node, you need to set the sudo parameters. Otherwise, if you need to use sudo locally, the easier way is to use this plugin in your Rundeck instance.

Is there a way to mount Google Drive on my local machine like what could be done in Colab?

In Colab, the following code snippet is used for mounting Google Drive.
from google.colab import drive
drive.mount('/test', force_remount=True)
And I'm wondering if it could work on my local machine. When implementing this locally, it says "no module named google", even after having executed pip install google.
Is there another package that should be installed, or it just cannot be achieved? I've searched for a while, but it seems that the only solution is to install Google Drive Desktop to give access to remote files.
Although google.colab python library can be found here, this library is a collection of tools meant to work in conjunction with the Google Colab product.
Indeed, Google Drive Desktop is your best option to "mount" your Google Drive to your local machine.
Alternatively, there are several 3rd party Google Drive clients available.
Use ocamlfuse.
Here are the step by step details: https://medium.com/#enthu.cutlet/how-to-mount-google-drive-on-linux-windows-systems-5ef4bff24288
Instead of mounting it to a home folder (named googledrive in tutorial), I suggest mounting it such that folder structure would be same for both colab and local machine. To do that:
create your mounting folder at root (it's not a recommended practice but there is no harm). You need to use sudo. i.e at /, use sudo mkdir test
then create MyDrive inside test.
Chnage test or MyDrive owner to yourself: sudo chown <your username> MyDrive/
Mount to MyDrive by: google-drive-ocamlfuse MyDrive/
Enjoy!

gsutil doesn't run in the mounted drive directory

I'm trying to run gsutil in the shared environment and I see a really weird behaviour.
When I run it being in the root of the filesystem, as well as anywhere else - everything is fine, but when I open the shared drive mounted directory it fails with this:
$: gsutil
cannot open path of the current working directory: Permission denied
The shared drive folder itself is the Google Fileshare NFS with drwxrwxr-x, and the user is in the group that can do rwx.
Any help appreciated, thanks!
update: The issue was in the snap way of the installation of the gcloud-sdk, I'm not sure the exact nature of the problem, but reinstalling it following the google-sdk istallation manual with apt-get solved the issue.

Using Google Cloud Endpoints API over local HTTP

I am using OSX. I have set up my endpoints in my development server. When I visit localhost:8080/_ah/api/explorer, I receive this error message:
The API you are exploring is hosted over HTTP, which can cause
problems. Learn how to use Explorer with a local HTTP API.
The link instructs me to start a Chrome session with special flags as follows:
[path-to-Chrome] --user-data-dir=test --unsafely-treat-insecure-origin-as-secure=http://localhost:port
I am confused about where to input this line? I assumed that it should be entered into the CLI, so I tried it on the terminal:
$ /Applications/GoogleChrome.app --user-data-dir=test --unsafely-treat-insecure-origin-as-secure=http://localhost:8080
Of course, the response is this:
$ -bash: GoogleChrome.app: command not found
After some research, I found that I can launch a Chrome session using the $ google-chrome command, but this also failed with -bash: google-chrome: command not found.
I also tried to locate Chrome using $ whereis google-chrome, but this returns no response.
Try this: open /Applications/Google\ Chrome.app --args --user-data-dir=test --unsafely-treat-insecure-origin-as-secure=http://localhost:8080

Is it possible to run Google Page speed from the command line?

Is it possible to run Google Page speed from the command line? If so, how? I'm interested in automating nightly or daily Google PageSpeed calls that will inform me after a commit or daily if I've caused a drop in the Google PageSpeed 'grade' (for a given page).
It's possible to use the PageSpeed Insights from the command line:
Install via:
$ npm install --global psi
Usage:
$ psi <url> --key=<key> --prettyprint=<true> --userIp=<userIp> --locale=<locale> --strategy=<desktop|mobile>
Run it like this: $ psi http://stackoverflow.com
Also for mobile insights: $ psi http://stackoverflow.com --strategy=mobile
UPDATE: You can use the PageSpeed Insights within your local development environment (internet connection required) with grunt + grunt-pagespeed + ngrok. Checkout the sample project for grunt-pagespeed and ngrok for further information.
Note: Run $ ngrok -authtoken <your-token> 80 and check the web interface parameters to make sure to set the right port in your Gruntfile.js!
There is a Google Page Speed API. It won't work directly from a command line but you can easily write a script in your language of choice that will interact with the API.
You can use curl to run PageSpeed from command line like so:
curl "https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=http://your_url/&prettyprint=true&strategy=mobile&key=your_api_key"
It will return human readable results in json. cmd-F "score" to locate the overall score.
Reference : Official Google api.