use of com.google.api.services.bigquery.MinifiedBigquery in project bqjdbc by looker-open-source.
the class Oauth2Bigquery method authorizeViaApplicationDefault.
/**
* This function gives back an Authorized Bigquery Client using the Application Default
* Credentials. https://cloud.google.com/docs/authentication/production#automatically
*
* <p>The following are searched (in order) to find the Application Default Credentials:
*
* <ol>
* <li>Credentials file pointed to by the {@code GOOGLE_APPLICATION_CREDENTIALS} environment
* variable
* <li>Credentials provided by the Google Cloud SDK.
* <ol>
* <li>{@code gcloud auth application-default login} for user account credentials.
* <li>{@code gcloud auth application-default login --impersonate-service-account} for
* impersonated service account credentials.
* </ol>
* <li>Google App Engine built-in credentials
* <li>Google Cloud Shell built-in credentials
* <li>Google Compute Engine built-in credentials
* </ol>
*
* @return Authorized Bigquery Client via serviceaccount e-mail and keypath
* @throws GeneralSecurityException
* @throws IOException
*/
public static Bigquery authorizeViaApplicationDefault(String userAgent, Integer connectTimeout, Integer readTimeout, String rootUrl, HttpTransport httpTransport, List<String> targetServiceAccounts, String projectId) throws IOException {
GoogleCredentials credential = GoogleCredentials.getApplicationDefault();
logger.debug("Authorizing with Application Default Credentials.");
Bigquery.Builder bqBuilder = createBqBuilderForCredential(credential, connectTimeout, readTimeout, httpTransport, userAgent, rootUrl, targetServiceAccounts, /* oauthToken= */
null, projectId);
return new MinifiedBigquery(bqBuilder);
}
use of com.google.api.services.bigquery.MinifiedBigquery in project bqjdbc by looker-open-source.
the class Oauth2Bigquery method createBqBuilderForCredential.
/**
* Creates a Bigquery.Builder using the provided GoogleCredential
*
* @param credential a valid GoogleCredential
* @return Bigquery.Builder suitable for initalizing a MinifiedBigquery
*/
private static Bigquery.Builder createBqBuilderForCredential(GoogleCredentials credential, Integer connectTimeout, Integer readTimeout, HttpTransport httpTransport, String userAgent, String rootUrl, List<String> targetServiceAccounts, @Nullable String oauthToken, @Nullable String projectId) {
// If targetServiceAccounts is empty this returns the original credential
credential = impersonateServiceAccount(credential, targetServiceAccounts, projectId);
HttpRequestTimeoutInitializer httpRequestInitializer = createRequestTimeoutInitalizer(credential, connectTimeout, readTimeout);
Bigquery.Builder bqBuilder = new Builder(httpTransport, JSON_FACTORY, httpRequestInitializer).setApplicationName(applicationName);
if (oauthToken != null || userAgent != null) {
BigQueryRequestUserAgentInitializer requestInitializer = new BigQueryRequestUserAgentInitializer();
if (userAgent != null) {
requestInitializer.setUserAgent(userAgent);
}
if (oauthToken != null) {
requestInitializer.setOauthToken(oauthToken);
}
bqBuilder.setBigqueryRequestInitializer(requestInitializer);
}
if (rootUrl != null) {
bqBuilder.setRootUrl(rootUrl);
}
return bqBuilder;
}
use of com.google.api.services.bigquery.MinifiedBigquery in project bqjdbc by looker-open-source.
the class Oauth2Bigquery method authorizeViaToken.
/**
* Authorizes a bigquery Connection with the given OAuth 2.0 Access Token
*
* @param oauthToken
* @return Authorized Bigquery Connection via OAuth Token
* @throws SQLException
*/
public static Bigquery authorizeViaToken(String oauthToken, String userAgent, Integer connectTimeout, Integer readTimeout, String rootUrl, HttpTransport httpTransport, List<String> targetServiceAccounts, String projectId) throws SQLException {
GoogleCredentials credential = GoogleCredentials.create(new AccessToken(oauthToken, null));
logger.debug("Creating a new bigquery client.");
Bigquery.Builder bqBuilder = createBqBuilderForCredential(credential, connectTimeout, readTimeout, httpTransport, userAgent, rootUrl, targetServiceAccounts, oauthToken, projectId);
return new MinifiedBigquery(bqBuilder);
}
use of com.google.api.services.bigquery.MinifiedBigquery in project bqjdbc by looker-open-source.
the class Oauth2Bigquery method authorizeViaService.
/**
* This function gives back an Authorized Bigquery Client It uses a service account, which doesn't
* need user interaction for connect
*
* @param serviceaccountemail
* @param keypath
* @param jsonAuthContents
* @return Authorized Bigquery Client via serviceaccount e-mail and keypath
* @throws GeneralSecurityException
* @throws IOException
*/
public static Bigquery authorizeViaService(String serviceaccountemail, String keypath, String password, String userAgent, String jsonAuthContents, Integer readTimeout, Integer connectTimeout, String rootUrl, HttpTransport httpTransport, List<String> targetServiceAccounts, String projectId) throws GeneralSecurityException, IOException {
GoogleCredentials credential = createServiceAccountCredential(serviceaccountemail, keypath, password, jsonAuthContents, false);
logger.debug("Authorized?");
Bigquery.Builder bqBuilder = createBqBuilderForCredential(credential, connectTimeout, readTimeout, httpTransport, userAgent, rootUrl, targetServiceAccounts, /* oauthToken= */
null, projectId);
return new MinifiedBigquery(bqBuilder);
}
Aggregations