本文整理汇总了Java中com.google.cloud.AuthCredentials类的典型用法代码示例。如果您正苦于以下问题:Java AuthCredentials类的具体用法?Java AuthCredentials怎么用?Java AuthCredentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthCredentials类属于com.google.cloud包,在下文中一共展示了AuthCredentials类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pubSubCloud
import com.google.cloud.AuthCredentials; //导入依赖的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