How to Override the Authentication Credentials
Unless otherwise configured, the client libraries use Application Default Credentials to authenticate with Google Cloud Services. While this works for most applications, in some cases you may need to override this default. You can do so by providing the UnifiedCredentialsOption The following example shows how to explicitly load a service account key file:
[](std::string const& keyfile) {
auto is = std::ifstream(keyfile);
is.exceptions(std::ios::badbit); // Minimal error handling in examples
auto contents = std::string(std::istreambuf_iterator<char>(is.rdbuf()), {});
auto options =
google::cloud::Options{}.set<google::cloud::UnifiedCredentialsOption>(
google::cloud::MakeServiceAccountCredentials(contents));
return google::cloud::aiplatform_v1::DatasetServiceClient(
google::cloud::aiplatform_v1::MakeDatasetServiceConnection(
"us-west1" /* regional service region */, options));
}
Follow these links to find examples for other *Client
classes:
aiplatform_v1::DatasetServiceClient
aiplatform_v1::EndpointServiceClient
aiplatform_v1::FeaturestoreServiceClient
aiplatform_v1::FeaturestoreOnlineServingServiceClient
aiplatform_v1::IndexServiceClient
aiplatform_v1::IndexEndpointServiceClient
aiplatform_v1::JobServiceClient
aiplatform_v1::MatchServiceClient
aiplatform_v1::MetadataServiceClient
aiplatform_v1::MigrationServiceClient
aiplatform_v1::ModelServiceClient
aiplatform_v1::ModelGardenServiceClient
aiplatform_v1::PipelineServiceClient
aiplatform_v1::PredictionServiceClient
aiplatform_v1::SpecialistPoolServiceClient
aiplatform_v1::TensorboardServiceClient
aiplatform_v1::VizierServiceClient
Keep in mind that we chose this as an example because it is relatively easy to understand. Consult the Best practices for managing service account keys guide for more details.
See Also
Authentication Components - for more information on the factory functions to create google::cloud::Credentials
objects.