本文整理汇总了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;未经允许,请勿转载。 |
请发表评论