java - 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) );
解决方案
完成测试后,实现此代码,使您可以获取 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();
推荐阅读
- crystal-reports - Toolbox Visual Studio 2019 中缺少 Crystal Report Viewer
- php - 如何在没有表单数据的情况下使用 ajax 发布图像?
- javascript - 使用正则表达式从对象文本中获取字符串
- c# - 实体框架核心中具有多对多关系的 CRUD
- c++ - 没有OWNER_WRITE的cmake安装目录
- plot - Octave 中的绘图函数
- github - 如果分叉的 Gist 被删除会怎样?
- ubuntu - Pyomo scip 求解器错误 FileNotFoundError
- java - 如何在不获取序列号的情况下使用 jooq 批量插入
- .net - .Net MVC 动态添加文本框并绑定到模型