authentication: Google credentials

Description Usage Arguments Details Value See Also Examples

Description

Authenticate with Google Cloud Storage. You can download the JSON credential file from Google Gloud Platform. The package will search for the credentials from evironment variables 'GOOGLE_APPLICATION_CREDENTIALS' or 'GCS_AUTH_FILE' when it is loaded in R. If both variables are not set, the package will try to get your credentials from 'gcloud' program. If it fails to find 'gcloud', you will use anonymous credentials. To redo the credentials initialization process after the package is loaded. Simply call the 'gcs_cloud_auth' function with no argument.

Usage

1
2
3
4
5
6
gcs_cloud_auth(json_file, gcloud = FALSE, email = NULL, billing_project = NULL)

gcs_get_cloud_auth()

## S3 method for class 'auth'
print(x, ...)

Arguments

json_file

character(1). A JSON file that can be used to authenticate with Google Cloud Storage. If the value is 'NULL', the current credential will be erased.

gcloud

logical. Whether use gcloud to authenticate with Google Cloud Storage. If the value is 'TRUE', the parameter 'json_file' will be ignored. See details.

email

character(1) or NULL. For gcloud only. Account to get the access token for. If not specified, the current active account in gcloud will be used.

billing_project

character(1) or NULL. The project's ID which the charges will be sent to. If the value is not NULL, it will overwrite the default setting. See details.

x

Used for the S3 'print' function only

...

Used for the S3 'print' function only

Details

**Obtaining credentials**

When the package is loaded, it first searches the credential file from the enviroment variable 'GOOGLE_APPLICATION_CREDENTIALS'. If the credentials is not found, the environment variable 'GCS_AUTH_FILE' will be used intead. If both variables are not specified. Users need to specify the credentials by calling 'gcs_cloud_auth' function.

The function also works with Google Cloud SDK. If you have initialized the SDK and set up your google account, the credentials can be obtained via 'gcs_cloud_auth(gcloud = TRUE)'.

**Billing project**

Some buckets have enabled Requester Pays, which means users are responsible for the charges associated with the data access. In this case, you must have a billing project for receiving the bills. By default, if you are using a service account to authenticate with Google Cloud, the billing project will be set to the project associated with the service account. If you are using Google Cloud SDK, the billing probject will be the default project in 'gcloud'. You can also manually set the billing project via 'gcs_set_billing_project'.

Value

gcs_cloud_auth : No return value

gcs_get_cloud_auth : An S3 'auth' class containing credentials information

See Also

requester_pays

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Default authentication process
gcs_cloud_auth()
## Show the credentials
gcs_get_cloud_auth()

## Anonymous credential
gcs_cloud_auth(NULL)
gcs_get_cloud_auth()

## Use gcloud to do the authentication
if(GCSConnection:::exists_gcloud()){
    gcs_cloud_auth(gcloud = TRUE)
    gcs_get_cloud_auth()
}

Jiefei-Wang/GCSConnection documentation built on Sept. 12, 2020, 7:22 a.m.