'default credentials' 验证 bigQuery 客户端的逻辑是什么
what's the logic behind 'default credentials' to authenticate bigQuery client
我看到了两种验证 bigQuery 的方法java 客户端
/**
* Creates an authorized Bigquery client service using Application Default Credentials.
*
* @return an authorized Bigquery client
* @throws IOException if there's an error getting the default credentials.
*/
public static Bigquery createAuthorizedClient() throws IOException {
// Create the credential
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
// Depending on the environment that provides the default credentials (e.g. Compute Engine, App
// Engine), the credentials may require us to specify the scopes we need explicitly.
// Check for this case, and inject the Bigquery scope if required.
if (credential.createScopedRequired()) {
credential = credential.createScoped(BigqueryScopes.all());
}
return new Bigquery.Builder(transport, jsonFactory, credential)
.setApplicationName("Bigquery Samples")
.build();
}
还有这个
public class QuickstartSample {
public static void Main() {
// Your Google Cloud Platform project ID
string projectId = "YOUR_PROJECT_ID";
// Instantiates a client
BigqueryClient client = BigqueryClient.Create(projectId);
// The id for the new dataset
string datasetId = "my_new_dataset";
// Creates the dataset
BigqueryDataset dataset = client.CreateDataset(datasetId);
Console.WriteLine($"Dataset {dataset.FullyQualifiedId} created.");
}
}
这是什么意思?
default credentials (e.g. Compute Engine, App Engine)
它将无法访问我的特定 GCP 项目,对吗?
那么这些 default credentials
有什么意义?
对于 "application default credentials",应用程序使用自己的服务帐户而不是最终用户的服务帐户。有关详细信息,请参阅 https://cloud.google.com/bigquery/authentication#app-default-cred。
我看到了两种验证 bigQuery 的方法java 客户端
/**
* Creates an authorized Bigquery client service using Application Default Credentials.
*
* @return an authorized Bigquery client
* @throws IOException if there's an error getting the default credentials.
*/
public static Bigquery createAuthorizedClient() throws IOException {
// Create the credential
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
// Depending on the environment that provides the default credentials (e.g. Compute Engine, App
// Engine), the credentials may require us to specify the scopes we need explicitly.
// Check for this case, and inject the Bigquery scope if required.
if (credential.createScopedRequired()) {
credential = credential.createScoped(BigqueryScopes.all());
}
return new Bigquery.Builder(transport, jsonFactory, credential)
.setApplicationName("Bigquery Samples")
.build();
}
还有这个
public class QuickstartSample {
public static void Main() {
// Your Google Cloud Platform project ID
string projectId = "YOUR_PROJECT_ID";
// Instantiates a client
BigqueryClient client = BigqueryClient.Create(projectId);
// The id for the new dataset
string datasetId = "my_new_dataset";
// Creates the dataset
BigqueryDataset dataset = client.CreateDataset(datasetId);
Console.WriteLine($"Dataset {dataset.FullyQualifiedId} created.");
}
}
这是什么意思?
default credentials (e.g. Compute Engine, App Engine)
它将无法访问我的特定 GCP 项目,对吗?
那么这些 default credentials
有什么意义?
对于 "application default credentials",应用程序使用自己的服务帐户而不是最终用户的服务帐户。有关详细信息,请参阅 https://cloud.google.com/bigquery/authentication#app-default-cred。