• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ComputeEngineCredentials类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.auth.oauth2.ComputeEngineCredentials的典型用法代码示例。如果您正苦于以下问题:Java ComputeEngineCredentials类的具体用法?Java ComputeEngineCredentials怎么用?Java ComputeEngineCredentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ComputeEngineCredentials类属于com.google.auth.oauth2包,在下文中一共展示了ComputeEngineCredentials类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getCredentialFromMetadataServiceAccount

import com.google.auth.oauth2.ComputeEngineCredentials; //导入依赖的package包/类
/**
 * Initializes OAuth2 credential using preconfigured ServiceAccount settings on the local
 * GCE VM. See: <a href="https://developers.google.com/compute/docs/authentication"
 * >Authenticating from Google Compute Engine</a>.
 */
public static Credentials getCredentialFromMetadataServiceAccount()
    throws IOException, GeneralSecurityException {
  Credentials cred = new ComputeEngineCredentials(getHttpTransport());
  try {
    cred.refresh();
  } catch (IOException e) {
    throw new IOException("Error getting access token from metadata server at: " +
        ComputeCredential.TOKEN_SERVER_ENCODED_URL, e);
  }
  return cred;
}
 
开发者ID:dmmcerlean,项目名称:cloud-bigtable-client,代码行数:17,代码来源:CredentialFactory.java


示例2: computeEngineCreds

import com.google.auth.oauth2.ComputeEngineCredentials; //导入依赖的package包/类
/** Sends a large unary rpc with compute engine credentials. */
public void computeEngineCreds(String serviceAccount, String oauthScope) throws Exception {
  ComputeEngineCredentials credentials = ComputeEngineCredentials.create();
  TestServiceGrpc.TestServiceBlockingStub stub = blockingStub
      .withCallCredentials(MoreCallCredentials.from(credentials));
  final SimpleRequest request = SimpleRequest.newBuilder()
      .setFillUsername(true)
      .setFillOauthScope(true)
      .setResponseSize(314159)
      .setResponseType(PayloadType.COMPRESSABLE)
      .setPayload(Payload.newBuilder()
          .setBody(ByteString.copyFrom(new byte[271828])))
      .build();

  final SimpleResponse response = stub.unaryCall(request);
  assertEquals(serviceAccount, response.getUsername());
  assertFalse(response.getOauthScope().isEmpty());
  assertTrue("Received oauth scope: " + response.getOauthScope(),
      oauthScope.contains(response.getOauthScope()));

  final SimpleResponse goldenResponse = SimpleResponse.newBuilder()
      .setOauthScope(response.getOauthScope())
      .setUsername(response.getUsername())
      .setPayload(Payload.newBuilder()
          .setType(PayloadType.COMPRESSABLE)
          .setBody(ByteString.copyFrom(new byte[314159])))
      .build();
  assertEquals(goldenResponse, response);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:30,代码来源:AbstractInteropTest.java


示例3: googleCredentials

import com.google.auth.oauth2.ComputeEngineCredentials; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public CredentialsProvider googleCredentials() throws Exception {
	CredentialsProvider credentialsProvider;

	Credentials propertyCredentials = this.gcpProperties.getCredentials();

	List<String> scopes = resolveScopes();

	if (!StringUtils.isEmpty(propertyCredentials.getLocation())) {
		credentialsProvider = FixedCredentialsProvider
				.create(GoogleCredentials.fromStream(
						propertyCredentials.getLocation().getInputStream())
				.createScoped(scopes));
	}
	else {
		credentialsProvider = GoogleCredentialsProvider.newBuilder()
				.setScopesToApply(scopes)
				.build();
	}

	try {
		com.google.auth.Credentials credentials = credentialsProvider.getCredentials();

		if (LOGGER.isInfoEnabled()) {
			if (credentials instanceof UserCredentials) {
				LOGGER.info("Default credentials provider for user "
						+ ((UserCredentials) credentials).getClientId());
			}
			else if (credentials instanceof ServiceAccountCredentials) {
				LOGGER.info("Default credentials provider for service account "
						+ ((ServiceAccountCredentials) credentials).getClientEmail());
			}
			else if (credentials instanceof ComputeEngineCredentials) {
				LOGGER.info("Default credentials provider for Google Compute Engine.");
			}
			LOGGER.info("Scopes in use by default credentials: " + scopes.toString());
		}
	}
	catch (IOException ioe) {
		LOGGER.error("No credentials were found.", ioe);
	}

	return credentialsProvider;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:46,代码来源:GcpContextAutoConfiguration.java


示例4: build

import com.google.auth.oauth2.ComputeEngineCredentials; //导入依赖的package包/类
@Override
public CredentialOptions build() {
    return CredentialOptions.credential(new ComputeEngineCredentials());
}
 
开发者ID:spotify,项目名称:heroic,代码行数:5,代码来源:ComputeEngineCredentialsBuilder.java



注:本文中的com.google.auth.oauth2.ComputeEngineCredentials类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UnauthorizedInstantiationException类代码示例发布时间:2022-05-23
下一篇:
Java SimpleFunction类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap