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