有人可以提供CloudRuntimeConfig Google Cloud List变量的示例吗

时间:2018-08-06 04:43:06

标签: java google-cloud-platform

我正在寻找Java语言的RuntimeConfig Google云示例,我需要阅读存储的变量列表。在这里,我将说明身份验证的内容。

String projectId =  null;
GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(jsonPath))
      .createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService();

    if (credentials instanceof ServiceAccountCredentials) {
       projectId = ((ServiceAccountCredentials) credentials).getProjectId();
      System.out.println("Project:\t"+ projectId );
    }else
    {

        System.out.println("Project nodef." );

    }

    HttpTransport transport;
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    transport = GoogleNetHttpTransport.newTrustedTransport();


    CloudRuntimeConfig runtimeconfig = new CloudRuntimeConfig(transport, jsonFactory, null);

    System.out.println("--->" +  runtimeconfig.projects().configs().list("projects//"+projectId) );

1 个答案:

答案 0 :(得分:1)

在进行测试后,请完成此代码,使您可以获取Google Cloud Runtime Config的变量。

    HttpTransport transport;
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    transport = GoogleNetHttpTransport.newTrustedTransport();

    CloudRuntimeConfig runtimeconfig =  new CloudRuntimeConfig.Builder(transport, jsonFactory, null)
                                                  .setApplicationName(PROJECTID)
                                                  .build();

    Variable requestVariable =
            runtimeconfig.projects()
                         .configs()
                         .variables()
                         .get("projects/"+PROJECTID+"/configs/+"MYCONFIG+"config/variables/"+MIVAR)
                         .setOauthToken(credentials.getAccessToken().getTokenValue())
                         .execute();