实例化Google IAM的API调用时,是否可以更改用户代理信息?我的代码是这样的:
public static Iam initIam() throws IOException, GeneralSecurityException {
InputStream resourceAsStream = GoogleIAM.class.getClassLoader().getResourceAsStream("creds.txt");
GoogleCredential credential = GoogleCredential.fromStream(resourceAsStream);
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
if (credential.createScopedRequired()) {
List<String> scopes = new ArrayList<>();
// Enable full Cloud Platform scope.
scopes.add(IamScopes.CLOUD_PLATFORM);
credential = credential.createScoped(scopes);
}
// Create IAM API object associated with the authenticated transport.
return new Iam.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName("test").build();
}
我看到可以使用HeaderProvider这样对Google Storage进行存储:
Map<String, String> m = ImmutableMap.<String, String>builder().put("user-agent", "my custom useragent").build();
HeaderProvider headerProvider = FixedHeaderProvider.create(m);
但是我找不到如何在Google IAM中使用HeaderProvider。
有什么想法吗?
答案 0 :(得分:0)
实际上已经在代码中完成
返回新的Iam.Builder(httpTransport,JSON_FACTORY, 凭据).setApplicationName(“ test”)。build();
使用setApplicationName方法,在其中的Stackdriver日志中,您可以看到用户名字段中存在应用程序名称(即测试)