Use @DefaultCredential for Cloud API access in GAE

This change completes the switch to @DefaultCredential for
all use cases in GAE.

Impacted modules:
- IcannReporting
- CreateCdnsTld command
- LoadSnapshot command.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=213511730
This commit is contained in:
weiminyu 2018-09-18 14:01:10 -07:00 committed by Ben McIlwain
parent 9bcd5579ef
commit 961e5cc7c7
20 changed files with 184 additions and 226 deletions

View file

@ -16,6 +16,8 @@ package google.registry.tools;
import com.beust.jcommander.ParametersDelegate;
import google.registry.bigquery.BigqueryConnection;
import javax.inject.Inject;
import javax.inject.Provider;
/** A {@link Command} that uses the bigquery client API. */
abstract class BigqueryCommand implements Command {
@ -28,9 +30,12 @@ abstract class BigqueryCommand implements Command {
/** Connection object for interacting with the Bigquery API. */
private BigqueryConnection bigquery;
@Inject Provider<BigqueryConnection.Builder> bigQueryConnectionBuilderProvider;
@Override
public void run() throws Exception {
try (BigqueryConnection autoClosingBigquery = bigqueryParameters.newConnection()) {
try (BigqueryConnection autoClosingBigquery =
bigqueryParameters.newConnection(bigQueryConnectionBuilderProvider.get())) {
bigquery = autoClosingBigquery;
runWithBigquery();
}