在使用普通的身份验证凭据,我可以做的:
When using plain auth credentials I can do:
ContextBuilder.newBuilder("aws-s3").credentials(keyId, key).buildView(BlobStoreContext.class);
...访问BlobStoreContext为S3。
... to access BlobStoreContext for S3.
在本机亚马逊的Java API,我可以使用安全令牌服务(STS)承担的角色,并使用临时凭据访问S3或任何其他AWS服务。
In native Amazon java api I can use Security Token Service (STS) to assume role and use temporary credentials to access S3 or any other AWS service.
我如何做到这一点的jclouds?
How do I do this in jclouds?
我想它了。
这code段允许承担的角色和使用温度凭据访问S3:
This code snippet allows to assume role and use temp credentials to access S3:
STSApi api = ContextBuilder.newBuilder("sts").credentials(keyId,
key).buildApi(STSApi.class);
AssumeRoleOptions assumeRoleOptions = new AssumeRoleOptions().durationSeconds(3600).externalId(externalId);
final UserAndSessionCredentials credentials = api.assumeRole(roleArn, sessionName, assumeRoleOptions);
Supplier<Credentials> credentialsSupplier = new Supplier<Credentials>() {
@Override
public Credentials get() {
return credentials.getCredentials();
}
};
BlobStoreContext context = ContextBuilder.newBuilder("aws-s3").credentialsSupplier(credentialsSupplier).buildView(BlobStoreContext.class);