Search in sources :

Example 46 with Credential

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

Example 47 with Credential

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

Example 48 with 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());
    }
}
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 49 with Credential

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());
    }
}
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 50 with Credential

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());
    }
}
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)

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