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

Java ComputeCredential类代码示例

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

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



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

示例1: getCredentialFromMetadataServiceAccount

import com.google.api.client.googleapis.compute.ComputeCredential; //导入依赖的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 Credential getCredentialFromMetadataServiceAccount()
    throws IOException, GeneralSecurityException {
  LOG.debug("getCredentialFromMetadataServiceAccount()");
  Credential cred =
      new ComputeCredentialWithRetry(
          new ComputeCredential.Builder(getStaticHttpTransport(), JSON_FACTORY)
              .setRequestInitializer(new CredentialHttpRetryInitializer()));
  try {
    cred.refreshToken();
  } catch (IOException e) {
    throw new IOException("Error getting access token from metadata server at: "
        + ComputeCredential.TOKEN_SERVER_ENCODED_URL, e);
  }
  return cred;
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:21,代码来源:CredentialFactory.java


示例2: getCredentialFromMetadataServiceAccount

import com.google.api.client.googleapis.compute.ComputeCredential; //导入依赖的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


示例3: getComputeCredential

import com.google.api.client.googleapis.compute.ComputeCredential; //导入依赖的package包/类
/**
 * @see http://developers.guge.io/accounts/docs/OAuth2ServiceAccount#creatinganaccount
 * @see https://developers.google.com/accounts/docs/OAuth2
 */
private ComputeCredential getComputeCredential() throws IOException
{
    ComputeCredential credential = new ComputeCredential.Builder(httpTransport, jsonFactory)
            .build();
    credential.refreshToken();

    return credential;
}
 
开发者ID:embulk,项目名称:embulk-output-gcs,代码行数:13,代码来源:GcsAuthentication.java


示例4: getGoogleCredential

import com.google.api.client.googleapis.compute.ComputeCredential; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public ComputeCredential getGoogleCredential(
    GoogleOAuth2ScopeRequirement requirement)
    throws GeneralSecurityException {
  // Ideally GCE would allow us to down-scope the metadata credentials we are
  // providing a given library.
  return new ComputeCredential(
      getModule().getHttpTransport(), getModule().getJsonFactory());
}
 
开发者ID:jenkinsci,项目名称:google-oauth-plugin,代码行数:13,代码来源:GoogleRobotMetadataCredentials.java


示例5: client

import com.google.api.client.googleapis.compute.ComputeCredential; //导入依赖的package包/类
public synchronized Compute client() {
    if (refreshInterval != null && refreshInterval.millis() != 0) {
        if (client != null &&
            (refreshInterval.millis() < 0 || (System.currentTimeMillis() - lastRefresh) < refreshInterval.millis())) {
            if (logger.isTraceEnabled()) logger.trace("using cache to retrieve client");
            return client;
        }
        lastRefresh = System.currentTimeMillis();
    }

    try {
        gceJsonFactory = new JacksonFactory();

        logger.info("starting GCE discovery service");
        // Forcing Google Token API URL as set in GCE SDK to
        //      http://metadata/computeMetadata/v1/instance/service-accounts/default/token
        // See https://developers.google.com/compute/docs/metadata#metadataserver
        String tokenServerEncodedUrl = GceMetadataService.GCE_HOST.get(settings) +
            "/computeMetadata/v1/instance/service-accounts/default/token";
        ComputeCredential credential = new ComputeCredential.Builder(getGceHttpTransport(), gceJsonFactory)
            .setTokenServerEncodedUrl(tokenServerEncodedUrl)
            .build();

        // hack around code messiness in GCE code
        // TODO: get this fixed
        Access.doPrivilegedIOException(credential::refreshToken);

        logger.debug("token [{}] will expire in [{}] s", credential.getAccessToken(), credential.getExpiresInSeconds());
        if (credential.getExpiresInSeconds() != null) {
            refreshInterval = TimeValue.timeValueSeconds(credential.getExpiresInSeconds() - 1);
        }


        Compute.Builder builder = new Compute.Builder(getGceHttpTransport(), gceJsonFactory, null).setApplicationName(VERSION)
            .setRootUrl(GCE_ROOT_URL.get(settings));

        if (RETRY_SETTING.exists(settings)) {
            TimeValue maxWait = MAX_WAIT_SETTING.get(settings);
            RetryHttpInitializerWrapper retryHttpInitializerWrapper;

            if (maxWait.getMillis() > 0) {
                retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, maxWait);
            } else {
                retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential);
            }
            builder.setHttpRequestInitializer(retryHttpInitializerWrapper);

        } else {
            builder.setHttpRequestInitializer(credential);
        }

        this.client = builder.build();
    } catch (Exception e) {
        logger.warn("unable to start GCE discovery service", e);
        throw new IllegalArgumentException("unable to start GCE discovery service", e);
    }

    return this.client;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:60,代码来源:GceInstancesServiceImpl.java


示例6: authorize

import com.google.api.client.googleapis.compute.ComputeCredential; //导入依赖的package包/类
private Credential authorize() throws Exception {
    JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    return new ComputeCredential.Builder(httpTransport, JSON_FACTORY).build();
}
 
开发者ID:dcos,项目名称:exhibitor,代码行数:6,代码来源:GcsClientImpl.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java PsiTreeChangeListener类代码示例发布时间:2022-05-23
下一篇:
Java CriteriaLoader类代码示例发布时间: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