use of com.tencentcloudapi.common.Credential in project tencentcloud-sdk-java by TencentCloud.
the class EnvironmentVariableCredentialsProvider method getCredentials.
@Override
public Credential getCredentials() throws TencentCloudSDKException {
String secretId = System.getenv("TENCENTCLOUD_SECRET_ID");
String secretKey = System.getenv("TENCENTCLOUD_SECRET_KEY");
if (secretId == null || secretKey == null) {
throw new TencentCloudSDKException("Not found secretId or secretKey");
}
if (secretId.length() == 0) {
throw new TencentCloudSDKException("Environment variable secretId cannot be empty");
} else if (secretKey.length() == 0) {
throw new TencentCloudSDKException("Environment variable 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 STSCredential method updateCredential.
private void updateCredential() throws TencentCloudSDKException {
Credential cred = new Credential(secretId, secretKey);
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("sts.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
CommonClient client = new CommonClient("sts", "2018-08-13", cred, "ap-guangzhou", clientProfile);
String resp = client.call("AssumeRole", "{\"RoleArn\":\"" + roleArn + "\"," + "\"RoleSessionName\":\"" + roleSessionName + "\"}");
Map<String, Object> map = new Gson().fromJson(resp, new TypeToken<HashMap<String, Object>>() {
}.getType());
Map<String, Object> respmap = (Map<String, Object>) map.get("Response");
Map<String, String> credmap = (Map<String, String>) respmap.get("Credentials");
tmpSecretId = credmap.get("TmpSecretId");
tmpSecretKey = credmap.get("TmpSecretKey");
token = credmap.get("Token");
expiredTime = ((Double) respmap.get("ExpiredTime")).intValue();
}
use of com.tencentcloudapi.common.Credential in project tencentcloud-sdk-java by TencentCloud.
the class SignatureTest method testGetHmacSHA1.
@Test
public void testGetHmacSHA1() {
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("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 CommonClientTest method testJson.
@Test
public void testJson() {
Credential cred = new Credential(System.getenv("TENCENTCLOUD_SECRET_ID"), System.getenv("TENCENTCLOUD_SECRET_KEY"));
CommonClient client = new CommonClient("cvm", "2017-03-12", cred, "ap-guangzhou");
try {
String resp = client.call("DescribeInstances", "{\"Filters\":" + "[{\"Name\":\"zone\"," + "\"Values\":[\"ap-guangzhou-1\"]}]" + "}");
} catch (Exception e) {
fail(e.toString());
}
}
use of com.tencentcloudapi.common.Credential in project tencentcloud-sdk-java by TencentCloud.
the class CommonClientTest method testOctetStream.
@Test
public void testOctetStream() {
Credential cred = new Credential(System.getenv("TENCENTCLOUD_SECRET_ID"), System.getenv("TENCENTCLOUD_SECRET_KEY"));
CommonClient client = new CommonClient("cls", "2020-10-16", cred, "ap-guangzhou");
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("X-CLS-TopicId", "e621fdb8-16f4-41cf-bc73-5aead0b75a03");
headers.put("X-CLS-HashKey", "0fffffffffffffffffffffffffffffff");
headers.put("X-CLS-CompressType", "");
String filePath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "java" + File.separator + "com" + File.separator + "tencentcloudapi" + File.separator + "integration" + File.separator + "commonclient" + File.separator + "binary.data";
try {
byte[] body = Files.readAllBytes(Paths.get(filePath));
String resp = client.callOctetStream("UploadLog", headers, body);
} catch (TencentCloudSDKException e) {
Assert.assertTrue(e.toString().contains("ResourceNotFound.TopicNotExist"));
} catch (Exception e) {
fail(e.toString());
}
}
Aggregations