use of com.tencentcloudapi.common.Credential in project tencentcloud-sdk-java by TencentCloud.
the class ProfileCredentialsProvider method getCredentials.
@Override
public Credential getCredentials() throws TencentCloudSDKException {
Wini ini = getIni();
String secretId = ini.get("default", "secret_id");
String secretKey = ini.get("default", "secret_key");
if (secretId == null || secretKey == null) {
throw new TencentCloudSDKException("Not found secretId or secretKey");
}
if (secretId.length() == 0) {
throw new TencentCloudSDKException("SecretId cannot be empty");
} else if (secretKey.length() == 0) {
throw new TencentCloudSDKException("SecretKey cannot be empty");
} else {
return new Credential(secretId, secretKey);
}
}
use of com.tencentcloudapi.common.Credential in project tencentcloud-sdk-java by TencentCloud.
the class DefaultCredentialsProvider method getCredentials.
@Override
public Credential getCredentials() throws TencentCloudSDKException {
Credential cred;
try {
cred = new EnvironmentVariableCredentialsProvider().getCredentials();
return cred;
} catch (TencentCloudSDKException e) {
}
try {
cred = new ProfileCredentialsProvider().getCredentials();
return cred;
} catch (TencentCloudSDKException e) {
}
cred = new CvmRoleCredential();
if (cred.getSecretId() != null && cred.getSecretKey() != null && cred.getToken() != null) {
return cred;
}
throw new TencentCloudSDKException("No valid credential");
}
use of com.tencentcloudapi.common.Credential in project tencentcloud-sdk-java by TencentCloud.
the class SignatureTest method testGetHmacSHA256.
@Test
public void testGetHmacSHA256() {
Credential cred = new Credential(System.getenv("TENCENTCLOUD_SECRET_ID"), System.getenv("TENCENTCLOUD_SECRET_KEY"));
HttpProfile httpProfile = new HttpProfile();
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
clientProfile.setSignMethod("HmacSHA256");
httpProfile.setReqMethod("GET");
CvmClient client = new CvmClient(cred, "ap-guangzhou", clientProfile);
DescribeInstancesRequest req = new DescribeInstancesRequest();
try {
DescribeInstancesResponse resp = client.DescribeInstances(req);
Assert.assertTrue(resp.getTotalCount() >= 0);
} catch (TencentCloudSDKException e) {
fail(e.toString());
}
}
use of com.tencentcloudapi.common.Credential in project tencentcloud-sdk-java by TencentCloud.
the class SignatureTest method testPostHmacSHA1.
@Test
public void testPostHmacSHA1() {
Credential cred = new Credential(System.getenv("TENCENTCLOUD_SECRET_ID"), System.getenv("TENCENTCLOUD_SECRET_KEY"));
HttpProfile httpProfile = new HttpProfile();
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
clientProfile.setSignMethod("HmacSHA1");
httpProfile.setReqMethod("POST");
CvmClient client = new CvmClient(cred, "ap-guangzhou", clientProfile);
DescribeInstancesRequest req = new DescribeInstancesRequest();
try {
DescribeInstancesResponse resp = client.DescribeInstances(req);
Assert.assertTrue(resp.getTotalCount() >= 0);
} catch (TencentCloudSDKException e) {
fail(e.toString());
}
}
use of com.tencentcloudapi.common.Credential in project tencentcloud-sdk-java by TencentCloud.
the class SignatureTest method testPostHmacSHA256.
@Test
public void testPostHmacSHA256() {
Credential cred = new Credential(System.getenv("TENCENTCLOUD_SECRET_ID"), System.getenv("TENCENTCLOUD_SECRET_KEY"));
HttpProfile httpProfile = new HttpProfile();
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
clientProfile.setSignMethod("HmacSHA256");
httpProfile.setReqMethod("POST");
CvmClient client = new CvmClient(cred, "ap-guangzhou", clientProfile);
DescribeInstancesRequest req = new DescribeInstancesRequest();
try {
DescribeInstancesResponse resp = client.DescribeInstances(req);
Assert.assertTrue(resp.getTotalCount() >= 0);
} catch (TencentCloudSDKException e) {
fail(e.toString());
}
}
Aggregations