Search in sources :

Example 26 with Credential

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);
    }
}
Also used : TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) Credential(com.tencentcloudapi.common.Credential)

Example 27 with Credential

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();
}
Also used : Credential(com.tencentcloudapi.common.Credential) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) TypeToken(com.google.gson.reflect.TypeToken) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) Gson(com.google.gson.Gson) Map(java.util.Map) HashMap(java.util.HashMap) CommonClient(com.tencentcloudapi.common.CommonClient)

Example 28 with Credential

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());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) CvmClient(com.tencentcloudapi.cvm.v20170312.CvmClient) DescribeInstancesRequest(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest) DescribeInstancesResponse(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse) Test(org.junit.Test)

Example 29 with Credential

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());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) CommonClient(com.tencentcloudapi.common.CommonClient) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) Test(org.junit.Test)

Example 30 with Credential

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());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) HashMap(java.util.HashMap) CommonClient(com.tencentcloudapi.common.CommonClient) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) Test(org.junit.Test)

Aggregations

Credential (com.tencentcloudapi.common.Credential)55 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)41 ClientProfile (com.tencentcloudapi.common.profile.ClientProfile)39 HttpProfile (com.tencentcloudapi.common.profile.HttpProfile)39 CvmClient (com.tencentcloudapi.cvm.v20170312.CvmClient)12 DescribeInstancesRequest (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest)12 DescribeInstancesResponse (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse)10 CommonClient (com.tencentcloudapi.common.CommonClient)9 Test (org.junit.Test)8 TciClient (com.tencentcloudapi.tci.v20190318.TciClient)6 SoeClient (com.tencentcloudapi.soe.v20180724.SoeClient)5 OcrClient (com.tencentcloudapi.ocr.v20181119.OcrClient)3 SmsClient (com.tencentcloudapi.sms.v20210111.SmsClient)3 HashMap (java.util.HashMap)3 CmqConfig (com.qcloud.cmq.entity.CmqConfig)2 DescribeZonesRequest (com.tencentcloudapi.cvm.v20170312.models.DescribeZonesRequest)2 DescribeZonesResponse (com.tencentcloudapi.cvm.v20170312.models.DescribeZonesResponse)2 Filter (com.tencentcloudapi.cvm.v20170312.models.Filter)2 EccClient (com.tencentcloudapi.ecc.v20181213.EccClient)2 SendSmsRequest (com.tencentcloudapi.sms.v20210111.models.SendSmsRequest)2