use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project cvs-auto-svc by dvsa.
the class AwsUtil method insertVehicle.
public static void insertVehicle(String jsonBody) {
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() + "-technical-records";
Table table = dynamoDB.getTable(tableName);
String sysNo = GenericData.getValueFromJsonPath(jsonBody, "$.systemNumber");
try {
Item item = Item.fromJSON(jsonBody);
System.out.println("Adding a new item...");
PutItemOutcome outcome = table.putItem(item);
System.out.println("PutItem succeeded:\n" + item.toJSONPretty());
} catch (Exception e) {
System.err.println("Unable to add item with systemNumber: " + sysNo);
System.err.println(e);
}
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project cvs-auto-svc by dvsa.
the class AwsUtil method insertJsonInTable.
public static void insertJsonInTable(String json, String tableName, String primaryKey) {
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);
Table table = dynamoDB.getTable("cvs-" + loader.getBranchName() + "-" + tableName);
String valueForPrimaryKey = GenericData.getValueFromJsonPath(json, "$." + primaryKey);
try {
Item item = Item.fromJSON(json);
System.out.println("Adding a new item...");
PutItemOutcome outcome = table.putItem(item);
System.out.println("PutItem succeeded:\n" + item.toJSONPretty());
} catch (Exception e) {
System.err.println("Unable to add item with " + primaryKey + ": " + valueForPrimaryKey);
e.printStackTrace();
}
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project singleton by vmware.
the class S3Client method getRoleCredentials.
private synchronized Credentials getRoleCredentials() {
AWSCredentialsProvider awsCredentialsProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(config.getAccessKey(), config.getSecretkey()));
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard().withCredentials(awsCredentialsProvider).withRegion(config.getS3Region()).build();
AssumeRoleRequest arreq = new AssumeRoleRequest();
arreq.setDurationSeconds(DURATIONSEC);
arreq.setRoleArn(config.getRoleArn());
arreq.setRoleSessionName("SingletonRoleSession");
AssumeRoleResult sessionTokenResult = stsClient.assumeRole(arreq);
long time = System.currentTimeMillis();
Credentials result = sessionTokenResult.getCredentials();
reducedTime = (result.getExpiration().getTime() - (DURATIONSEC * 1000) - time) + TIME_ERR_RANGE;
return result;
}
Aggregations