當前位置: 首頁>>代碼示例>>Java>>正文


Java GoogleCredential.createScopedRequired方法代碼示例

本文整理匯總了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();
}
 
開發者ID:mdvorsky,項目名稱:DataflowSME,代碼行數:25,代碼來源:InjectorUtils.java

示例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();
}
 
開發者ID:frew,項目名稱:chute,代碼行數:21,代碼來源:BigQueryExporter.java

示例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;
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:GoogleCloudStorageService.java

示例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();
}
 
開發者ID:davorbonaci,項目名稱:beam-portability-demo,代碼行數:28,代碼來源:InjectorUtils.java

示例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;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:policyscanner,代碼行數:27,代碼來源:GCPProject.java

示例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;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:policyscanner,代碼行數:26,代碼來源:GCPServiceAccount.java

示例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;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-sql-jdbc-socket-factory,代碼行數:17,代碼來源:SslSocketFactory.java

示例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;
}
 
開發者ID:spinnaker,項目名稱:halyard,代碼行數:18,代碼來源:GoogleStorage.java

示例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;
}
 
開發者ID:spinnaker,項目名稱:halyard,代碼行數:18,代碼來源:GoogleKms.java

示例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;
}
 
開發者ID:spotify,項目名稱:spydra,代碼行數:40,代碼來源:LifecycleIT.java

示例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();
  }
 
開發者ID:DanielHawes,項目名稱:AsteroidEndpointTest,代碼行數:23,代碼來源:AsteroidList.java

示例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();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:policyscanner,代碼行數:14,代碼來源:GCSFilesSource.java

示例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();
}
 
開發者ID:darshanmaiya,項目名稱:MCSFS,代碼行數:15,代碼來源:StorageFactory.java

示例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();
}
 
開發者ID:gymxxx,項目名稱:digdag-bq-wait,代碼行數:12,代碼來源:BqWaitClient.java

示例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;
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:pubsub,代碼行數:35,代碼來源:GCEController.java


注:本文中的com.google.api.client.googleapis.auth.oauth2.GoogleCredential.createScopedRequired方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。