Search in sources :

Example 1 with TempCredential

use of com.mizhousoft.cloudsdk.TempCredential in project cloud-sdk by mizhousoft.

the class TestTencentOCRServiceImpl method getTempCredential.

@Test
public void getTempCredential() {
    try {
        TempCredential tempCredential = ocrService.getTempCredential(30);
        Assert.assertNotNull(tempCredential);
    } catch (CloudSDKException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TempCredential(com.mizhousoft.cloudsdk.TempCredential) Test(org.junit.Test)

Example 2 with TempCredential

use of com.mizhousoft.cloudsdk.TempCredential in project cloud-sdk by mizhousoft.

the class TencentOCRServiceImpl method getTempCredential.

/**
 * {@inheritDoc}
 */
@Override
public TempCredential getTempCredential(long durationSecond) throws CloudSDKException {
    GetFederationTokenRequest request = new GetFederationTokenRequest();
    request.setName("ocr");
    request.setDurationSeconds(durationSecond);
    request.setPolicy("{\"version\": \"2.0\", \"statement\": [{\"action\": [\"ocr:*\"], \"resource\": \"*\", \"effect\": \"allow\"}]}");
    try {
        GetFederationTokenResponse response = cosClient.GetFederationToken(request);
        Credentials credential = response.getCredentials();
        TempCredential tempCredential = new TempCredential();
        tempCredential.setSecretId(credential.getTmpSecretId());
        tempCredential.setSecretKey(credential.getTmpSecretKey());
        tempCredential.setToken(credential.getToken());
        tempCredential.setExpiredTime(response.getExpiredTime());
        return tempCredential;
    } catch (TencentCloudSDKException e) {
        throw new CloudSDKException(e.getMessage(), e);
    }
}
Also used : TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) TempCredential(com.mizhousoft.cloudsdk.TempCredential) GetFederationTokenResponse(com.tencentcloudapi.sts.v20180813.models.GetFederationTokenResponse) GetFederationTokenRequest(com.tencentcloudapi.sts.v20180813.models.GetFederationTokenRequest) Credentials(com.tencentcloudapi.sts.v20180813.models.Credentials)

Aggregations

CloudSDKException (com.mizhousoft.cloudsdk.CloudSDKException)2 TempCredential (com.mizhousoft.cloudsdk.TempCredential)2 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)1 Credentials (com.tencentcloudapi.sts.v20180813.models.Credentials)1 GetFederationTokenRequest (com.tencentcloudapi.sts.v20180813.models.GetFederationTokenRequest)1 GetFederationTokenResponse (com.tencentcloudapi.sts.v20180813.models.GetFederationTokenResponse)1 Test (org.junit.Test)1