package com.tencentcloud.dbauth;
import com.tencentcloudapi.common.Credential;
import com.tencentcloud.dbauth.model.GenerateAuthenticationTokenRequest;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
public class GenerateDBAuthentication {
public static void main(String[] args) {
String region = "<实例所在地域>";
String instanceId = "<实例 ID>";
String userName = "<用户名>";
Credential credential = new Credential(System.getenv("<TENCENTCLOUD_SECRET_ID>"), System.getenv("<TENCENTCLOUD_SECRET_KEY>"));
System.out.println(getAuthToken(region, instanceId, userName, credential));
}
public static String getAuthToken(String region, String instanceId, String userName, Credential credential) {
try {
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("cam.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
GenerateAuthenticationTokenRequest tokenRequest = GenerateAuthenticationTokenRequest.builder()
.region(region)
.credential(credential)
.userName(userName)
.instanceId(instanceId)
.clientProfile(clientProfile)
.build();
return DBAuthentication.generateAuthenticationToken(tokenRequest);
} catch (TencentCloudSDKException e) {
e.printStackTrace();
}
return "";
}
}
本页内容是否解决了您的问题?