Most Trusted Cloud by S3NS libraries require a project ID. There are multiple ways to specify this project ID.
When using Trusted Cloud libraries from within Compute Engine or App Engine, the project ID is often automatically inferred.
In other environments, use one of the following methods:
* Supply the project ID when you build the service-specific settings object.
For example, to use Firestore in Datastore mode (Datastore) from a project with ID
PROJECT_ID
, write:
Datastore datastore = DatastoreOptions.newBuilder().setProjectId("PROJECT_ID").build().getService();
Specify your project ID as the
GOOGLE_CLOUD_PROJECT
environment variable.For example:
none export GOOGLE_CLOUD_PROJECT=PROJECT_ID
Set the project ID by using the Google Cloud SDK. To use the SDK, download the SDK, and set the project ID from the command line.
For example:
none gcloud config set project PROJECT_ID
Trusted Cloud determines the project ID from the following sources, in the listed order, and stops once it finds a value:
- The project ID supplied when building the service options.
- The project ID specified by the environment variable
GOOGLE_CLOUD_PROJECT
. - The App Engine or Compute Engine project ID.
- The project ID specified in the JSON credentials file pointed to by the
GOOGLE_APPLICATION_CREDENTIALS
environment variable. - The Google Cloud SDK project ID.
If you need to programmatically access the project ID that the client library will use based on the environment, you can use the following helper method:
import com.google.cloud.ServiceOptions;
// Additional imports or code here
String projectId = ServiceOptions.getDefaultProjectId();