本文整理汇总了Java中com.google.api.client.googleapis.auth.oauth2.GoogleCredential.createScopedRequired方法的典型用法代码示例。如果您正苦于以下问题:Java GoogleCredential.createScopedRequired方法的具体用法?Java GoogleCredential.createScopedRequired怎么用?Java GoogleCredential.createScopedRequired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.googleapis.auth.oauth2.GoogleCredential
的用法示例。
在下文中一共展示了GoogleCredential.createScopedRequired方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClient
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
/** Builds a new Pubsub client and returns it. */
public static Pubsub getClient(final HttpTransport httpTransport, final JsonFactory jsonFactory)
throws IOException {
checkNotNull(httpTransport);
checkNotNull(jsonFactory);
GoogleCredential credential =
GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
if (credential.createScopedRequired()) {
credential = credential.createScoped(PubsubScopes.all());
}
if (credential.getClientAuthentication() != null) {
System.out.println(
"\n***Warning! You are not using service account credentials to "
+ "authenticate.\nYou need to use service account credentials for this example,"
+ "\nsince user-level credentials do not have enough pubsub quota,\nand so you will run "
+ "out of PubSub quota very quickly.\nSee "
+ "https://developers.google.com/identity/protocols/application-default-credentials.");
System.exit(1);
}
HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential);
return new Pubsub.Builder(httpTransport, jsonFactory, initializer)
.setApplicationName(APP_NAME)
.build();
}
示例2: BigQueryExporter
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
public BigQueryExporter(BigQueryExporterConfiguration config) {
this.config = config;
this.checkedSchemas = new HashSet<String>();
this.existingSchemaMap = new HashMap<String, com.google.api.services.bigquery.model.TableSchema>();
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential;
try {
credential = GoogleCredential.getApplicationDefault(transport,
jsonFactory);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (credential.createScopedRequired()) {
credential = credential.createScoped(BigqueryScopes.all());
}
this.bq = new Bigquery.Builder(transport, jsonFactory, credential)
.setApplicationName(this.config.applicationName).build();
}
示例3: loadCredentials
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
/**
* HTTP request initializer that loads credentials from the service account file
* and manages authentication for HTTP requests
*/
private GoogleCredential loadCredentials(String serviceAccount) throws IOException {
if (serviceAccount == null) {
throw new ElasticsearchException("Cannot load Google Cloud Storage service account file from a null path");
}
Path account = environment.configFile().resolve(serviceAccount);
if (Files.exists(account) == false) {
throw new ElasticsearchException("Unable to find service account file [" + serviceAccount
+ "] defined for repository");
}
try (InputStream is = Files.newInputStream(account)) {
GoogleCredential credential = GoogleCredential.fromStream(is);
if (credential.createScopedRequired()) {
credential = credential.createScoped(Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL));
}
return credential;
}
}
示例4: getClient
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
/**
* Builds a new Pubsub client and returns it.
*/
public static Pubsub getClient(final HttpTransport httpTransport,
final JsonFactory jsonFactory)
throws IOException {
checkNotNull(httpTransport);
checkNotNull(jsonFactory);
GoogleCredential credential =
GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
if (credential.createScopedRequired()) {
credential = credential.createScoped(PubsubScopes.all());
}
if (credential.getClientAuthentication() != null) {
System.out.println("\n***Warning! You are not using service account credentials to "
+ "authenticate.\nYou need to use service account credentials for this example,"
+ "\nsince user-level credentials do not have enough pubsub quota,\nand so you will run "
+ "out of PubSub quota very quickly.\nSee "
+ "https://developers.google.com/identity/protocols/application-default-credentials.");
System.exit(1);
}
HttpRequestInitializer initializer =
new RetryHttpInitializerWrapper(credential);
return new Pubsub.Builder(httpTransport, jsonFactory, initializer)
.setApplicationName(APP_NAME)
.build();
}
示例5: getProjectsApiStub
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
/**
* Return the Projects api object used for accessing the Cloud Resource Manager Projects API.
* @return Projects api object used for accessing the Cloud Resource Manager Projects API
* @throws GeneralSecurityException Thrown if there's a permissions error.
* @throws IOException Thrown if there's an IO error initializing the API object.
*/
public static synchronized Projects getProjectsApiStub()
throws GeneralSecurityException, IOException {
if (projectApiStub != null) {
return projectApiStub;
}
HttpTransport transport;
GoogleCredential credential;
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
transport = GoogleNetHttpTransport.newTrustedTransport();
credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
if (credential.createScopedRequired()) {
Collection<String> scopes = CloudResourceManagerScopes.all();
credential = credential.createScoped(scopes);
}
projectApiStub = new CloudResourceManager
.Builder(transport, jsonFactory, credential)
.build()
.projects();
return projectApiStub;
}
示例6: getServiceAccountsApiStub
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
/**
* Get the API stub for accessing the IAM Service Accounts API.
* @return ServiceAccounts api stub for accessing the IAM Service Accounts API.
* @throws IOException Thrown if there's an IO error initializing the api connection.
* @throws GeneralSecurityException Thrown if there's a security error
* initializing the connection.
*/
public static ServiceAccounts getServiceAccountsApiStub() throws IOException, GeneralSecurityException {
if (serviceAccountsApiStub == null) {
HttpTransport transport;
GoogleCredential credential;
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
transport = GoogleNetHttpTransport.newTrustedTransport();
credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
if (credential.createScopedRequired()) {
Collection<String> scopes = IamScopes.all();
credential = credential.createScoped(scopes);
}
serviceAccountsApiStub = new Iam.Builder(transport, jsonFactory, credential)
.build()
.projects()
.serviceAccounts();
}
return serviceAccountsApiStub;
}
示例7: create
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
@Override
public Credential create() {
GoogleCredential credential;
try {
credential = GoogleCredential.getApplicationDefault();
} catch (IOException e) {
throw
new RuntimeException(
"Unable to obtain credentials to communicate with the Cloud SQL API", e);
}
if (credential.createScopedRequired()) {
credential = credential.createScoped(
Collections.singletonList(SQLAdminScopes.SQLSERVICE_ADMIN));
}
return credential;
}
示例8: loadStorageCredential
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
private static GoogleCredential loadStorageCredential(HttpTransport transport, JsonFactory factory, String jsonPath) throws IOException {
GoogleCredential credential;
if (!jsonPath.isEmpty()) {
FileInputStream stream = new FileInputStream(jsonPath);
credential = GoogleCredential.fromStream(stream, transport, factory);
log.info("Loaded storage credentials from " + jsonPath);
} else {
log.info("Using storage default application credentials.");
credential = GoogleCredential.getApplicationDefault();
}
if (credential.createScopedRequired()) {
credential = credential.createScoped(StorageScopes.all());
}
return credential;
}
示例9: loadKmsCredential
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
private static GoogleCredential loadKmsCredential(HttpTransport transport, JsonFactory factory, String jsonPath) throws IOException {
GoogleCredential credential;
if (!jsonPath.isEmpty()) {
FileInputStream stream = new FileInputStream(jsonPath);
credential = GoogleCredential.fromStream(stream, transport, factory);
log.info("Loaded kms credentials from " + jsonPath);
} else {
log.info("Using kms default application credentials.");
credential = GoogleCredential.getApplicationDefault();
}
if (credential.createScopedRequired()) {
credential = credential.createScoped(CloudKMSScopes.all());
}
return credential;
}
示例10: isClusterCollected
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
private boolean isClusterCollected(SpydraArgument arguments)
throws IOException, GeneralSecurityException {
GoogleCredential credential = GoogleCredential.fromStream(
new ByteArrayInputStream(gcpUtils.credentialJsonFromEnv().getBytes()));
if (credential.createScopedRequired()) {
credential =
credential.createScoped(
Collections.singletonList("https://www.googleapis.com/auth/cloud-platform"));
}
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
Dataproc dataprocService =
new Dataproc.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("Google Cloud Platform Sample")
.build();
Dataproc.Projects.Regions.Clusters.List request =
dataprocService.projects().regions().clusters().list(
arguments.getCluster().getOptions().get(SpydraArgument.OPTION_PROJECT),
arguments.getRegion());
ListClustersResponse response;
do {
response = request.execute();
if (response.getClusters() == null) continue;
String clusterName = arguments.getCluster().getName();
for (Cluster cluster : response.getClusters()) {
if (cluster.getClusterName().equals(clusterName)) {
String status = cluster.getStatus().getState();
LOGGER.info("Cluster state is" + status);
return status.equals("DELETING");
}
}
request.setPageToken(response.getNextPageToken());
} while (response.getNextPageToken() != null);
return true;
}
示例11: createComputeService
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
/**
* Set up the Compute Engine service
*
* @return Compute.Builder
*
* @throws IOException
* @throws GeneralSecurityException
*/
public static Compute createComputeService() throws IOException, GeneralSecurityException {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
GoogleCredential credential = GoogleCredential.getApplicationDefault();
if (credential.createScopedRequired()) {
credential =
credential.createScoped(Arrays.asList("https://www.googleapis.com/auth/cloud-platform"));
}
return new Compute.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("b612_BetterWorld/1.0")
.build();
}
示例12: constructStorageApiStub
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
private static Storage constructStorageApiStub() throws GeneralSecurityException, IOException {
JsonFactory jsonFactory = new JacksonFactory();
HttpTransport transport;
transport = GoogleNetHttpTransport.newTrustedTransport();
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
if (credential.createScopedRequired()) {
Collection<String> scopes = StorageScopes.all();
credential = credential.createScoped(scopes);
}
return new Storage.Builder(transport, jsonFactory, credential)
.setApplicationName("GCS Samples")
.build();
}
示例13: buildService
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
private static Storage buildService() throws IOException, GeneralSecurityException {
HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
if (credential.createScopedRequired()) {
Collection<String> bigqueryScopes = StorageScopes.all();
credential = credential.createScoped(bigqueryScopes);
}
return new Storage.Builder(transport, jsonFactory, credential)
.setApplicationName("MCSFS")
.build();
}
示例14: client
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
@Override
protected Bigquery client(GoogleCredential credential, HttpTransport transport, JsonFactory jsonFactory)
{
if (credential.createScopedRequired()) {
credential = credential.createScoped(BigqueryScopes.all());
}
return new Bigquery.Builder(transport, jsonFactory, credential)
.setApplicationName("Digdag")
.build();
}
示例15: newGCEController
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //导入方法依赖的package包/类
/** Returns a GCEController using default application credentials. */
public static GCEController newGCEController(
String projectName,
Map<String, Map<ClientParams, Integer>> types,
int cores,
ScheduledExecutorService executor) {
try {
HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
if (credential.createScopedRequired()) {
credential =
credential.createScoped(
Collections.singletonList("https://www.googleapis.com/auth/cloud-platform"));
}
return new GCEController(
projectName,
types,
cores,
executor,
new Storage.Builder(transport, jsonFactory, credential)
.setApplicationName("Cloud Pub/Sub Loadtest Framework")
.build(),
new Compute.Builder(transport, jsonFactory, credential)
.setApplicationName("Cloud Pub/Sub Loadtest Framework")
.build(),
new Pubsub.Builder(transport, jsonFactory, credential)
.setApplicationName("Cloud Pub/Sub Loadtest Framework")
.build());
} catch (Throwable t) {
log.error("Unable to initialize GCE: ", t);
return null;
}
}