Credentials¶
You will need a Google account that has access to,
Google Earth Engine
PICK ONE OF THE FOLLOWING
Google Drive
Google Cloud Storage
Google Earth Engine¶
Get access to Google Earth Engine by signing up for an account.
Google Drive¶
Access to the Google Drive requires two steps — developer credentials to allow the CEDAR application to use the Google Drive API, and user credentials to give permission for CEDAR to write to your Google Drive.
Developer Credentials¶
In order for this application to use the Google Drive API, you need to setup Google Cloud Platform credentials to allow you to use the Google Drive API. You can read more about Google’s authentication using OAuth 2.0.
Follow the guide to Enable the Google Drive API.
Create “OAuth client ID” credentials for the project. You will want to use the “Other” choice for the “Application type”.
Download the credentials as JSON (
client_secret.[long string].json
) and rename them toclient_secret.json
or something else that is easy to remember.You can either move this
client_secret.json
file to your working directory or point to it explicitly inside this application. You will need to know its location when to authenticate.The credentials in this file are used to link API calls back to your Google account. Therefore, it is recommended that you do not share it publicly to avoid unwanted use of your API quotas.
This step authorizes your Google account to make API calls using this application, but we still need to give the application authorization to change data for your Google account.
User Access¶
This step gives our application (“cedar”, or whatever you called the application name when creating the OAuth 2.0 credentials) access to a user’s Google Drive.
Using the command line interface program,
$ cedar auth gdrive --client_secrets_file=client_secret.json
Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth...
Enter the authorization code: [PASTE AUTHORIZATION CODE]
Authenticated using credentials file ~/.config/cedar/credentials.json
Google Cloud Storage¶
Credentials¶
This application can save to Google Cloud Storage using the
google-cloud-storage
package.
Follow the instructions provided at the following:
Python Google Cloud authentication docs
Python Google Auth user guide
It’s probably going to be easiest to create and use a Service account private credential file.
Make sure to enable the following Google Cloud Platform services:
Cloud Storage
Google Cloud Storage JSON API
The “Cloud Storage” service is needed to actually store data, and the JSON API service is needed by the client libraries we use to interact with the storage service.
To authenticate, you can use the program cedar auth gcs
. To test logging in,
it might be helpful to specify your service account file and GCS project
explicitly:
$ cedar auth gcs --service_account_file SERVICE_ACCOUNT.json --project PROJECT
Authenticated using service account file "SERVICE_ACCOUNT.json" and project "PROJECT"
Make sure to add this information to the `gcs` section of your configuration file
For ordering and downloading, you’ll need to put this information in your
configuration file in the gcs
section. You can also use environment
variables to configure GCS, as described in the google-auth library docs.
API¶
Google Drive¶
-
cedar.stores.gdrive.
get_credentials
(client_secrets_file=None, credentials_file=None, no_browser=True)[source]¶ Get OAuth2 Credentials for Google Drive
- Parameters
client_secrets_file (str or Path) – Filename of “client_secrets.[…].json” file
credentials_file (str or Path) – Filename of user credentials to load, or to save to for future use. If not provided, will use default location.
no_browser (bool, optional) – Disables opening a web browser in favor of prompting user to authenticate using a terminal prompt.
- Returns
credentials (google.oauth2.credentials.Credentials) – User credentials, including access token, for using the application.
credentials_file (str) – File storing user credentials
-
cedar.stores.gdrive.
build_gdrive_service
(credentials)[source]¶ Return Google Drive API service, either by credentials or file
- Parameters
credentials (google.oauth2.credentials.Credentials) – User credentials, including access token, for using the application.
- Returns
GDrive v3 API resource
- Return type
googleapiclient.discovery.Resource
Google Cloud Storage¶
-
cedar.stores.gcs.
build_gcs_client
(credentials=None, project=None)[source]¶ Return a Google Cloud Store API service client
- Parameters
- Returns
Client for the Google Cloud Storage client library
- Return type
google.cloud.storage.Client
Notes
You might consider setting the envirnment variable
GOOGLE_APPLICATION_CREDENTIALS
with the path to your service account credentials file [1].References