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


Java GoogleCredential.fromStream方法代碼示例

本文整理匯總了Java中com.google.api.client.googleapis.auth.oauth2.GoogleCredential.fromStream方法的典型用法代碼示例。如果您正苦於以下問題:Java GoogleCredential.fromStream方法的具體用法?Java GoogleCredential.fromStream怎麽用?Java GoogleCredential.fromStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.api.client.googleapis.auth.oauth2.GoogleCredential的用法示例。


在下文中一共展示了GoogleCredential.fromStream方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: getGoogleCredential

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private GoogleCredential getGoogleCredential() {
  try {
    if (StringUtils.isNotEmpty(config.getCredentialPath())) {
      return GoogleCredential.fromStream(new FileInputStream(config.getCredentialPath()));
    } else {
      return GoogleCredential.getApplicationDefault();
    }
  } catch (IOException ioe) {
    throw new RuntimeException(ioe);
  }
}
 
開發者ID:spinnaker,項目名稱:fiat,代碼行數:12,代碼來源:GoogleDirectoryUserRolesProvider.java

示例6: loadCredential

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private synchronized void loadCredential() throws IOException {
  if (credential != null) {
    return;
  }

  final InputStream credentialStream =
      getCredentialStreamFromResource(Resources.getResource(resourceName));

  credential = GoogleCredential.fromStream(credentialStream);
}
 
開發者ID:spotify,項目名稱:dataproc-java-submitter,代碼行數:11,代碼來源:ResourceCredentialProvider.java

示例7: init

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
public static AndroidPublisher init(Context context, String fileName) throws IOException {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(context.getPackageName()), "applicationId cannot be null or empty!");
    newTrustedTransport();
    GoogleCredential credential = GoogleCredential.fromStream(context.getAssets().open(fileName), HTTP_TRANSPORT, JSON_FACTORY);
    credential = credential.createScoped(Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER));

    return new AndroidPublisher.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
            .setApplicationName(context.getPackageName())
            .build();
}
 
開發者ID:sugoi-wada,項目名稱:appversionchecker,代碼行數:11,代碼來源:AndroidPublisherHelper.java

示例8: pubSubCloud

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
@Bean
@Profile("cloud")
public PubSub pubSubCloud(Environment environment) throws Exception {
	String vcapServicesEnv = environment.getProperty("VCAP_SERVICES");
	JsonParser parser = JsonParserFactory.getJsonParser();
	Map<String, Object> services = parser.parseMap(vcapServicesEnv);
	List<Map<String, Object>> googlePubsub = (List<Map<String, Object>>) services.get("google-pubsub");
	Map<String, Object> credentials = (Map<String, Object>) googlePubsub.get(0).get("credentials");
	String privateKeyData = (String) credentials.get("PrivateKeyData");
	GoogleCredential googleCredential = GoogleCredential.fromStream(new ByteArrayInputStream(Base64.decodeBase64(privateKeyData)));

	return PubSubOptions.newBuilder().setAuthCredentials(AuthCredentials.createFor(googleCredential.getServiceAccountId(),
			googleCredential.getServiceAccountPrivateKey()))
			.setProjectId(pubSubBinderConfigurationProperties.getProjectName()).build().getService();
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-binder-google-pubsub,代碼行數:16,代碼來源:PubSubServiceAutoConfiguration.java

示例9: googleCredential

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private GoogleCredential googleCredential(String credential)
{
    try {
        return GoogleCredential.fromStream(new ByteArrayInputStream(credential.getBytes(UTF_8)));
    }
    catch (IOException e) {
        throw new TaskExecutionException(e, buildExceptionErrorConfig(e));
    }
}
 
開發者ID:gymxxx,項目名稱:digdag-bq-wait,代碼行數:10,代碼來源:GcpCredentialProvider.java

示例10: provideGoogleCredential

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
@Provides
@Singleton
static GoogleCredential provideGoogleCredential(
    NetHttpTransport netHttpTransport,
    JsonFactory jsonFactory,
    @Key("jsonCredential") String jsonCredential) {
  try {
    return GoogleCredential.fromStream(
        new ByteArrayInputStream(jsonCredential.getBytes(UTF_8)),
        netHttpTransport,
        jsonFactory);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:16,代碼來源:Modules.java


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