use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project micronaut-aws-sdk by agorapulse.
the class DefaultSecurityTokenService method assumeRole.
@Override
public AssumeRoleResult assumeRole(String sessionName, String roleArn, int durationInSeconds, Consumer<AssumeRoleRequest> additionParameters) {
AssumeRoleRequest request = new AssumeRoleRequest().withRoleSessionName(sessionName).withRoleArn(roleArn).withDurationSeconds(durationInSeconds);
additionParameters.accept(request);
return client.assumeRole(request);
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project knime-cloud by knime.
the class ComprehendConnection method getRoleAssumedComprehendClient.
/**
* Creates and returns a new instance of the {@link AmazonComprehend} client using rule assumption.
*
* @param connectionInformation The connection information
* @return AmazonComprehend client
* @throws Exception thrown if client could not be instantiated
*/
private static AmazonComprehend getRoleAssumedComprehendClient(final CloudConnectionInformation connectionInformation) throws Exception {
final AWSSecurityTokenServiceClientBuilder builder = AWSSecurityTokenServiceClientBuilder.standard().withRegion(connectionInformation.getHost());
if (!connectionInformation.useKeyChain()) {
final AWSCredentials credentials = getCredentials(connectionInformation);
builder.withCredentials(new AWSStaticCredentialsProvider(credentials));
}
final AWSSecurityTokenService stsClient = builder.build();
final AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withRoleArn(buildARN(connectionInformation)).withDurationSeconds(3600).withRoleSessionName("KNIME_Comprehend_Connection");
final AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRoleRequest);
final BasicSessionCredentials tempCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken());
return AmazonComprehendClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(tempCredentials)).withRegion(connectionInformation.getHost()).build();
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project knime-cloud by knime.
the class AmazonPersonalizeConnection method getRoleAssumedPersonalizeClient.
/**
* Creates and returns a new instance of the {@link AmazonPersonalize} client using rule assumption.
*
* @param connectionInformation The connection information
* @return AmazonPersonalize client
* @throws Exception thrown if client could not be instantiated
*/
private static final AmazonPersonalize getRoleAssumedPersonalizeClient(final CloudConnectionInformation connectionInformation) throws Exception {
final AWSSecurityTokenServiceClientBuilder builder = AWSSecurityTokenServiceClientBuilder.standard().withRegion(connectionInformation.getHost());
if (!connectionInformation.useKeyChain()) {
final AWSCredentials credentials = getCredentials(connectionInformation);
builder.withCredentials(new AWSStaticCredentialsProvider(credentials));
}
final AWSSecurityTokenService stsClient = builder.build();
final AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withRoleArn(buildARN(connectionInformation)).withDurationSeconds(3600).withRoleSessionName("KNIME_PersonalizeRuntime_Connection");
final AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRoleRequest);
final BasicSessionCredentials tempCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken());
final ClientConfiguration clientConfig = new ClientConfiguration().withConnectionTimeout(connectionInformation.getTimeout());
return AmazonPersonalizeClientBuilder.standard().withClientConfiguration(clientConfig).withCredentials(new AWSStaticCredentialsProvider(tempCredentials)).withRegion(connectionInformation.getHost()).build();
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project knime-cloud by knime.
the class AmazonPersonalizeRuntimeConnection method getRoleAssumedPersonalizeRuntimeClient.
/**
* Creates and returns a new instance of the {@link AmazonPersonalizeRuntime} client using rule assumption.
*
* @param connectionInformation The connection information
* @return AmazonPersonalizeRuntime client
* @throws Exception thrown if client could not be instantiated
*/
private static final AmazonPersonalizeRuntime getRoleAssumedPersonalizeRuntimeClient(final CloudConnectionInformation connectionInformation) throws Exception {
final AWSSecurityTokenServiceClientBuilder builder = AWSSecurityTokenServiceClientBuilder.standard().withRegion(connectionInformation.getHost());
if (!connectionInformation.useKeyChain()) {
final AWSCredentials credentials = getCredentials(connectionInformation);
builder.withCredentials(new AWSStaticCredentialsProvider(credentials));
}
final AWSSecurityTokenService stsClient = builder.build();
final AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withRoleArn(buildARN(connectionInformation)).withDurationSeconds(3600).withRoleSessionName("KNIME_PersonalizeRuntime_Connection");
final AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRoleRequest);
final BasicSessionCredentials tempCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken());
final ClientConfiguration clientConfig = new ClientConfiguration().withConnectionTimeout(connectionInformation.getTimeout());
return AmazonPersonalizeRuntimeClientBuilder.standard().withClientConfiguration(clientConfig).withCredentials(new AWSStaticCredentialsProvider(tempCredentials)).withRegion(connectionInformation.getHost()).build();
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project knime-cloud by knime.
the class S3Connection method getRoleAssumedS3Client.
private static AmazonS3 getRoleAssumedS3Client(final CloudConnectionInformation connectionInformation) throws Exception {
AWSSecurityTokenServiceClientBuilder builder = AWSSecurityTokenServiceClientBuilder.standard().withRegion(connectionInformation.getHost());
if (!connectionInformation.useKeyChain()) {
AWSCredentials credentials = getCredentials(connectionInformation);
builder.withCredentials(new AWSStaticCredentialsProvider(credentials));
}
AWSSecurityTokenService stsClient = builder.build();
final AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withRoleArn(buildARN(connectionInformation)).withDurationSeconds(3600).withRoleSessionName("KNIME_S3_Connection");
final AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRoleRequest);
final BasicSessionCredentials tempCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken());
return AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(tempCredentials)).withRegion(connectionInformation.getHost()).build();
}
Aggregations