use of com.aliyuncs.auth.BasicSessionCredentials in project fc-java-sdk by aliyun.
the class Config method refreshCredentials.
/**
* refresh credentials if CredentialProvider set
*/
public void refreshCredentials() {
if (this.credsProvider == null)
return;
try {
AlibabaCloudCredentials creds = this.credsProvider.getCredentials();
this.accessKeyID = creds.getAccessKeyId();
this.accessKeySecret = creds.getAccessKeySecret();
if (creds instanceof BasicSessionCredentials) {
this.securityToken = ((BasicSessionCredentials) creds).getSessionToken();
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.aliyuncs.auth.BasicSessionCredentials in project fc-java-sdk by aliyun.
the class FunctionComputeClientTest method testClientCredentialProviderMock.
@Test
public void testClientCredentialProviderMock() {
// init CredentialProvider
String ak = "ak";
String sk = "sk";
String stsToken = "sts_token";
BasicSessionCredentials creds = new BasicSessionCredentials(ak, sk, stsToken);
// mock
InstanceProfileCredentialsProvider credsProvider = mock(InstanceProfileCredentialsProvider.class);
try {
when(credsProvider.getCredentials()).thenReturn(creds);
} catch (com.aliyuncs.exceptions.ClientException e) {
e.printStackTrace();
}
// init fc client
Config config = new Config(REGION, ACCOUNT_ID, credsProvider, false);
FunctionComputeClient fcClient = new FunctionComputeClient(config);
client = fcClient;
// Create a service
try {
createService(SERVICE_NAME);
} catch (Exception e) {
}
assertEquals(creds.getAccessKeyId(), config.getAccessKeyID());
assertEquals(creds.getAccessKeySecret(), config.getAccessKeySecret());
assertEquals(creds.getSessionToken(), config.getSecurityToken());
}
Aggregations