首页 > 解决方案 > Can someone provide an example of CloudRuntimeConfig Google Cloud List Variables

问题描述

I am looking for an example of RuntimeConfig Google cloud with the Java language, I need to read the list of variables stored. Here I put what I have done with authentication.

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) );

标签: javagoogle-cloud-platform

解决方案


完成测试后,实现此代码,使您可以获取 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();

推荐阅读