Enable the Google Drive feature in Habitat

Detailed descriptions and imagery explaining each tool available inside Habitat. Feel free to post feature requests under each tools forum post if you would like to see something added or changed in the tools.
Post Reply
User avatar
Cubert
Posts: 2583
Joined: Tue Dec 29, 2015 7:57 pm
9
Contact:

Enable the Google Drive feature in Habitat

Post by Cubert »

Best Practice

To use Google Drive to upload, download, delete, list or any other feature integration inside Habitat you will need to have a "clean" google account and the Google Drive API services enabled on that account.

A clean Google account will have a empty drive. You can use this drive just for the Automate server and the plugin integration. If you use an existing google account, you may have many files from different areas of google clouding up the storage and populating the plugins file list with photos of your kids. So its just as easy to setup a new account just for the Automate server to use for this plugin.


We will walk you through the full process:


See a video on setting up Google Drive with Habitat Click Here

It's a good idea to launch in to Chrome (not required) as your browser and select from the top icon the drop down menu to launch Google Drive. Otherwise visit google.com and search for Google Drive.

1.PNG
1.PNG (49.75 KiB) Viewed 30610 times


Now assuming that the browser is not "logged in" as a Google User already and if so log out and re-run the step above. You should see the following web page in browser.

2.PNG
2.PNG (696.03 KiB) Viewed 30610 times


Select the personal account option to be presented with a "Sign In" dialog.

3.PNG
3.PNG (21.03 KiB) Viewed 30610 times


Use this dialog to select the create new account link. Create your new account and complete the initial account setup process. Afterwards it should return you to the following webpage.

4.PNG
4.PNG (65.1 KiB) Viewed 30610 times


You should now be in your new Google Drive account looking at the default view. Inside this view you should see a single "Getting Started" file. Do not delete this file yet. We will be using it later in this example.

Once you have a general google account you need to enable the plugins access via enabling API access to your account.

Enable the Google Drive API

To get started integrating with the Google Drive UI, you need to enable the Drive API within your app's Cloud Platform project and provide configuration details. This gives you access to the API as well as access to UI integration features.

To enable the Drive API, complete these steps:

While logged in to google drive with new account, go to the Google API Console. https://console.developers.google.com/

This will prompt you to accept the TOS

5.PNG
5.PNG (31.57 KiB) Viewed 30610 times


Once you agree to the TOS Create a new project called "Habitat For Automate" by selecting the create link.

6.PNG
6.PNG (23.12 KiB) Viewed 30610 times


Put in the project name "Habitat For Automate" and Create.

7.PNG
7.PNG (31.11 KiB) Viewed 30610 times


We should now be inside our project, see the top of the web page for project name to be listed. Then select the link "Enable APIS and Services". This will allow you to add the Google Drive API to your account.

8.PNG
8.PNG (34.01 KiB) Viewed 30610 times


Find and select the Google Drive API (under G Suite).

9.PNG
9.PNG (57.04 KiB) Viewed 30610 times


Select to enable this API

10.PNG
10.PNG (33.35 KiB) Viewed 30610 times


Now we need to set up security for our project. Select the "Create Credentials" link for project.

11.PNG
11.PNG (45.36 KiB) Viewed 30610 times


First select to add Google Drive as the API.

12.PNG
12.PNG (42.3 KiB) Viewed 30610 times


Now select "Other" and the "User Data" radio button. Click the "What Credentials do I need" to continue.

13.PNG
13.PNG (62.86 KiB) Viewed 30610 times


Select to setup Consent Screen.

14.PNG
14.PNG (31.59 KiB) Viewed 30610 times


Fill in the "Application Name" with Habitat For Automate

15.PNG
15.PNG (33.41 KiB) Viewed 30610 times


Select to Create Credentials at the bottom of the page.

16.PNG
16.PNG (27.39 KiB) Viewed 30610 times


You will be presented with the following screen, select "OAuth client ID".

17.PNG
17.PNG (42.63 KiB) Viewed 30610 times


Select the "Other" radio button, type in the name "Habitat For Automate" and select create.

18.PNG
18.PNG (26.56 KiB) Viewed 30610 times


It will present you with a long URL string as a client ID and a secret key.

19.PNG
19.PNG (54.81 KiB) Viewed 30608 times


Save this Client ID and KEY safely. You will take that information and inside the Habitat plugin. Select the Configure button in main menu of the Habitat plugin to input this info.



Configure Habitat Plugin

GoogleDrive.png
GoogleDrive.png (20.05 KiB) Viewed 19428 times

On the Habitat Control Center tab you will find the Google Drive plugin icon. This will launch the Google drive file manager. From this window you can select Configure Access to add in the newly created keys and authorizations.

GoogleDriveMenu.PNG
GoogleDriveMenu.PNG (18.47 KiB) Viewed 19428 times


You can take your new ClientID and Key and add it to the plugins configuration.

GoogleAPI-Configure.PNG
GoogleAPI-Configure.PNG (34.42 KiB) Viewed 19428 times


Upon first launch of the plugin, the plugin installs the Google Drive API dll files to the LabTech Client install folder. Once you have configured the API with a ClientID you can close and relaunch the file manager to start the permissions and login process for the API. This will be handle in a browser upon relaunch of the API.

On relaunch of the file manager with a newly added Client ID, allow a few more seconds for it to launch. It is calling out to google to verify ClientID. It will force a launch of the default browser with google asking to choose an account. Select or add the account you used to create the Google Drive account above. (Not the API credentials but the google account)

You will get a warning that the API Creds you are using (ClientID) is not verified. It belongs to you so you know its safe.

24.PNG
24.PNG (30.32 KiB) Viewed 30608 times


Select to expand the advanced link to accept responsibility for the ClientID credentials your providing.

25.PNG
25.PNG (43.24 KiB) Viewed 30608 times


And then select the Allow when prompted.

26.PNG
26.PNG (28.62 KiB) Viewed 30608 times


And Again confirm your choice.

27.PNG
27.PNG (39.09 KiB) Viewed 30608 times

Now remember that Getting Started file we left in our google drive for later? Yeap, we are now going to use that file to confirm that we are indeed connected and working with Google Drive. Select to Refresh File List

It should come back pretty fast with an update showing you that one file in your google drive currently. it will also allow you to download that file or remove it if needed. This data is now in the Automate database for you to access when needed.

GoogleDriveFileManager.PNG
GoogleDriveFileManager.PNG (35.2 KiB) Viewed 19419 times

Cool Beans!

User avatar
Cubert
Posts: 2583
Joined: Tue Dec 29, 2015 7:57 pm
9
Contact:

Re: Enable the Google Drive feature in Habitat

Post by Cubert »

Google Drive is a fickle beast!

We started integrating Drive into Habitat and man what a PITA. Our integration works great for small files. The direct links work just as you expect until you start getting to about 200mb. Once you get past 200mb you start getting Google intermediate pages having you click a button to continue. It also starts to get unstable and drops the connection causing any scripts to fail out.

Our plugin lets you download and upload files from the drive a scan the drive for uploaded files to use. You have to use Google's Drive UI to upload files bigger than 200mb so you can not use the plugin to upload ISO files of 2.5gb as it will kick back a denial. So for ISO files you will need to add them via Google's UI then in plugin update file list to see new additions. Then you can use that data in scripts to download files for use in scripts.


I am working on a cmdline large file downloader that will download 2g +files from Google drive. This can be used in LT scripting to get past the Large File- No Antivirus scan warnings google drive intermediate page that pops up on large files making programmatic scripting a big pain.

Its still got a few quirks but 2 out 3 times we got our 2.7 gb iso file

Capture.PNG
Capture.PNG (46.34 KiB) Viewed 30628 times

Also if you want to run a temporary solution (time sensitive) you can also do the following.

https://insynout.blogspot.com/2017/01/s ... -from.html

It has you create an access token that you then can use either CURL or POSH to grab the file. This is good if your doing it in a single day. Get the code, plug it in and run the script against agents. 12 hours later the token expires.

Code: Select all

curl -H "Authorization: Bearer YYYYY" https://www.googleapis.com/drive/v3/files/XXXXX?alt=media -o ZZZZZ
Or

Code: Select all

Invoke-RestMethod -Uri https://www.googleapis.com/drive/v3/files/XXXXX?alt=media -Method Get -Headers @{"Authorization"="Bearer YYYYY"} | Out-File ZZZZZ

In your command, replace “XXXXX” with the file ID from above, “YYYYY” with the access token from above, and “ZZZZZ” with the file name that will be saved (for example, “myFile.mp4” if you’re downloading a mp4 file).


We are working on a method to store the Refresh Token in the plugin and then auto refresh the access tokens using the refresh token. If your a Google Drive guy/gal, you will understand that this can be a permanent fix to scripting using tokens.

User avatar
Cubert
Posts: 2583
Joined: Tue Dec 29, 2015 7:57 pm
9
Contact:

Re: Enable the Google Drive feature in Habitat

Post by Cubert »

We have updated our executable for large files and its now in the plugin. Using the plugins file manager you can now add the executable Habitat-GDLFD.exe to your google drive file store. It can then be used in scripts using the download from URL command and pasting in the URL from plugin file list. Then you can craft scripts to use this exe to download the much bigger file when needed.

edward.cossett
Posts: 11
Joined: Tue Feb 11, 2020 4:23 pm
4

Re: Enable the Google Drive feature in Habitat

Post by edward.cossett »

I seem to be having issues downloading anything with Habitat-GDLFD. It runs the command and it finishes instantly. Is there any way to debug what's going on? It can't seem to download small or large files.

edward.cossett
Posts: 11
Joined: Tue Feb 11, 2020 4:23 pm
4

Re: Enable the Google Drive feature in Habitat

Post by edward.cossett »

Upon further inspection, it seems when I uploaded the ISOs into the Drive, I needed to enable link sharing. That has fixed my issues. Using the API key, I can download the ISOs now with the Upgrade Assistant! I used postman to try and "get" some other files that I had in there. Postman could only see the Large File Downloader. When I noticed it couldn't even see the getting started file, I knew it was probably related to permissions in Google Drive.

User avatar
Cubert
Posts: 2583
Joined: Tue Dec 29, 2015 7:57 pm
9
Contact:

Re: Enable the Google Drive feature in Habitat

Post by Cubert »

Awesome!

Yea I think somewhere in our "How-To" above it should reference the making the GD files publicly available. Maybe it was in one of the videos.. Not sure but glad you got it worked out.

edward.cossett
Posts: 11
Joined: Tue Feb 11, 2020 4:23 pm
4

Re: Enable the Google Drive feature in Habitat

Post by edward.cossett »

Last night it was able to grab the ISO for some machines and update with the upgrade assistant using the API key. Sadly, however I started getting this after it downloaded the ISO for about 7 or 8 machines:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "downloadQuotaExceeded",
"message": "The download quota for this file has been exceeded."
}
],
"code": 403,
"message": "The download quota for this file has been exceeded."
}
}

Seems that we weren't able to download with the link after that many downloads, and apparently google limits downloads with direct links. So a portion of our computers were able to download the ISO, and then the rest got limitied. I'm reading that this means we can't download with the link for 24hours. But I can still download manually with the export link that the Habitat-GDLFD is supposed to download it with. However, I'm still noticing the issue where that executable runs and exits almost immediately and doesn't download the file. Running it manually does nothing either. Is there something I'm missing with that EXE? I can download the EXE just fine, but it's not seeming to be able to download anything for me.

BlooTech
Posts: 27
Joined: Tue Dec 12, 2017 5:05 pm
7

Re: Enable the Google Drive feature in Habitat

Post by BlooTech »

Unfortunately, Google has updated their API dashboard so this setup guide is not click for click anymore. Leads to many unanswered questions which in turn leads to misconfiguration and many other issues that I've already experienced. Please update this guide and the youtube video. Can you also please start the video tutorial from scratch instead of starting from a project that has already been created? TIA!

Post Reply

Return to “Habitat Documentation Forum”