当前位置: 首页>>代码示例>>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;未经允许,请勿转载。