use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project knime-cloud by knime.
the class TranslateConnection method getRoleAssumedComprehendClient.
/**
* Creates and returns a new instance of the {@link AmazonTranslate} client using rule assumption.
*
* @param connectionInformation The connection information
* @return AmazonComprehend client
* @throws Exception thrown if client could not be instantiated
*/
private static final AmazonTranslate 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_Translate_Connection");
final AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRoleRequest);
final BasicSessionCredentials tempCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken());
return AmazonTranslateClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(tempCredentials)).withRegion(connectionInformation.getHost()).build();
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project cvs-auto-svc by dvsa.
the class AwsUtil method checkLogsFor.
public static boolean checkLogsFor(String log, String keyValuePair) {
Regions clientRegion = Regions.EU_WEST_1;
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard().withRegion(clientRegion).build();
System.out.println(System.getProperty("AWS_ROLE"));
AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(System.getProperty("AWS_ROLE")).withDurationSeconds(3600).withRoleSessionName(UUID.randomUUID().toString());
AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);
BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken());
AWSLogs logsClient = new AWSLogsClient(temporaryCredentials).withRegion(clientRegion);
String logGroup = log + "-" + loader.getBranchName();
for (int times = 0; times < 15; times++) {
System.out.println("... " + times + " ...");
DescribeLogStreamsRequest describeLogStreamsRequest = new DescribeLogStreamsRequest().withLogGroupName(logGroup).withOrderBy("LastEventTime").withDescending(true).withLimit(1);
DescribeLogStreamsResult describeLogStreamsResult = logsClient.describeLogStreams(describeLogStreamsRequest);
LogStream logStream = describeLogStreamsResult.getLogStreams().get(0);
GetLogEventsRequest getLogEventsRequest = new GetLogEventsRequest().withLogGroupName(logGroup).withLogStreamName(logStream.getLogStreamName());
GetLogEventsResult result = logsClient.getLogEvents(getLogEventsRequest);
for (OutputLogEvent event : result.getEvents()) {
System.out.println("*****************************");
System.out.println("# event: " + event.getMessage());
System.out.println("Looking for: " + keyValuePair);
if (event.getMessage().contains(keyValuePair)) {
System.out.println("!!!!!!!!!!!!!!!###### FOUND !!! ######!!!!!!!!!!!!!!!");
System.out.println("$$$$$$$$$$$ " + logStream.getLogStreamName() + " $$$$$$$$$$$");
return true;
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return false;
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project cvs-auto-svc by dvsa.
the class AwsUtil method checkDispatcherLogsForData.
public static boolean checkDispatcherLogsForData(String... keyValuePairs) {
Regions clientRegion = Regions.EU_WEST_1;
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard().withRegion(clientRegion).build();
System.out.println(System.getProperty("AWS_ROLE"));
AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(System.getProperty("AWS_ROLE")).withDurationSeconds(3600).withRoleSessionName(UUID.randomUUID().toString());
AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);
BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken());
AWSLogs logsClient = new AWSLogsClient(temporaryCredentials).withRegion(clientRegion);
String logGroup = "/aws/lambda/edh-dispatcher-" + loader.getBranchName();
logStreamLoop: for (int times = 0; times < 50; times++) {
System.out.println("... " + times + " ...");
DescribeLogStreamsRequest describeLogStreamsRequest = new DescribeLogStreamsRequest().withLogGroupName(logGroup).withOrderBy("LastEventTime").withDescending(true).withLimit(20);
DescribeLogStreamsResult describeLogStreamsResult = logsClient.describeLogStreams(describeLogStreamsRequest);
LogStream logStream = describeLogStreamsResult.getLogStreams().get(0);
GetLogEventsRequest getLogEventsRequest = new GetLogEventsRequest().withLogGroupName(logGroup).withLogStreamName(logStream.getLogStreamName());
GetLogEventsResult result = logsClient.getLogEvents(getLogEventsRequest);
eventLoop: for (OutputLogEvent event : result.getEvents()) {
System.out.println("\n----------------------------------------------------------------------");
for (String keyValuePair : keyValuePairs) {
System.out.println("searching inside event for: " + keyValuePair);
if (!event.getMessage().contains(keyValuePair)) {
System.out.println("########################## " + keyValuePair + " NOT FOUND in event: \n" + event.getMessage() + "\n ##########################");
continue eventLoop;
}
}
System.out.println("!!!!!!!!!!!!!!!###### FOUND !!! ######!!!!!!!!!!!!!!!");
System.out.println("$$$$$$$$$$$ " + logStream.getLogStreamName() + " $$$$$$$$$$$");
return true;
}
try {
System.out.println("########################## " + keyValuePairs + " NOT FOUND in log stream: \n" + logStream.getLogStreamName() + "\n ##########################");
System.out.println("waiting 2 seconds");
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return false;
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project cvs-auto-svc by dvsa.
the class AwsUtil method deleteTestResultId.
public static void deleteTestResultId(String testResultId) {
System.out.println("deleting the test-result: " + testResultId);
Regions clientRegion = Regions.EU_WEST_1;
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard().withRegion(clientRegion).build();
String uuid = String.valueOf(UUID.randomUUID());
AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(System.getProperty("AWS_ROLE")).withDurationSeconds(3600).withRoleSessionName(uuid);
AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);
BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken());
AmazonDynamoDBClient client = new AmazonDynamoDBClient(temporaryCredentials);
client.setRegion(Region.getRegion(clientRegion));
DynamoDB dynamoDB = new DynamoDB(client);
String tableName = "cvs-" + loader.getBranchName() + "-test-results";
Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>();
expressionAttributeValues.put(":result_id", new AttributeValue().withS(testResultId));
ScanRequest scanRequest = new ScanRequest().withTableName(tableName).withFilterExpression("testResultId = :result_id").withProjectionExpression("vin, testResultId").withExpressionAttributeValues(expressionAttributeValues);
ScanResult result = client.scan(scanRequest);
System.out.println("result.toString: " + result.toString());
System.out.println("result.getCount: " + result.getCount());
System.out.println("result.getItems:" + result.getItems());
Table table = dynamoDB.getTable(tableName);
for (Map<String, AttributeValue> item : result.getItems()) {
System.out.println("item.size: " + item.size());
System.out.println("item.values: " + item.values());
System.out.println("item.get(vin).getS(): " + item.get("vin").getS());
DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey("vin", item.get("vin").getS(), "testResultId", testResultId);
DeleteItemOutcome outcome = table.deleteItem(deleteItemSpec);
}
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project cvs-auto-svc by dvsa.
the class AwsUtil method deleteActivityById.
public static void deleteActivityById(String id) {
Regions clientRegion = Regions.EU_WEST_1;
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard().withRegion(clientRegion).build();
String uuid = String.valueOf(UUID.randomUUID());
AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(System.getProperty("AWS_ROLE")).withDurationSeconds(3600).withRoleSessionName(uuid);
AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);
BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken());
AmazonDynamoDBClient client = new AmazonDynamoDBClient(temporaryCredentials);
client.setRegion(Region.getRegion(clientRegion));
DynamoDB dynamoDB = new DynamoDB(client);
String tableName = "cvs-" + loader.getBranchName() + "-activities";
Table table = dynamoDB.getTable(tableName);
try {
System.out.println("deleting item with id: " + id + " ....");
DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey("id", id);
DeleteItemOutcome outcome = table.deleteItem(deleteItemSpec);
System.out.println("Printing item that was deleted...");
} catch (Exception e) {
System.err.println("Error deleting item in " + tableName);
System.err.println(e.getMessage());
}
}
Aggregations