@Test public void testDeletingCredentialWith1Versions() throws Exception { QueryResult queryResult = getMockQueryResult(1); AmazonDynamoDBClient amazonDynamoDBClient = spy(AmazonDynamoDBClient.class); DynamoDB dynamoDB = mock(DynamoDB.class); JCredStash jCredStash = new JCredStash(); BatchWriteItemResult result = new BatchWriteItemResult().withUnprocessedItems(new HashMap<>()); BatchWriteItemOutcome outcome = new BatchWriteItemOutcome(result); jCredStash.amazonDynamoDBClient = amazonDynamoDBClient; jCredStash.dynamoDB = dynamoDB; doReturn(queryResult).when(amazonDynamoDBClient).query(anyObject()); doReturn(outcome).when(dynamoDB).batchWriteItem(any(TableWriteItems.class)); jCredStash.deleteSecret("test", "secret"); verify(dynamoDB,times(1)).batchWriteItem(any(TableWriteItems.class)); }
protected void deleteSecret(String tableName, String secretName) throws InterruptedException { QueryResult queryResult = getCredentials(tableName, secretName); TableWriteItems itemsToDelete = new TableWriteItems(tableName); for ( Map<String, AttributeValue> item :queryResult.getItems()) { itemsToDelete.addHashAndRangePrimaryKeyToDelete( "name", item.get("name").getS(), "version", item.get("version").getS()); } Map<String, List<WriteRequest>> unprocessed = null ; int attempts = 0; do { if (attempts > 0) { Thread.sleep((1 << attempts) * 1000); } attempts++; BatchWriteItemOutcome outcome; if (unprocessed == null || unprocessed.size() > 0) { outcome = dynamoDB.batchWriteItem(itemsToDelete); } else { outcome = dynamoDB.batchWriteItemUnprocessed(unprocessed); } unprocessed = outcome.getUnprocessedItems(); } while (unprocessed.size() > 0 && attempts < 6); if(unprocessed.size() > 0) throw new RuntimeException("Error deleting secret " + secretName + " with " + unprocessed.size() + " versions not deleted"); }
JCredStash { protected void deleteSecret(String tableName, String secretName) throws InterruptedException { QueryResult queryResult = getCredentials(tableName, secretName); TableWriteItems itemsToDelete = new TableWriteItems(tableName); for ( Map<String, AttributeValue> item :queryResult.getItems()) { itemsToDelete.addHashAndRangePrimaryKeyToDelete( "name", item.get("name").getS(), "version", item.get("version").getS()); } Map<String, List<WriteRequest>> unprocessed = null ; int attempts = 0; do { if (attempts > 0) { Thread.sleep((1 << attempts) * 1000); } attempts++; BatchWriteItemOutcome outcome; if (unprocessed == null || unprocessed.size() > 0) { outcome = dynamoDB.batchWriteItem(itemsToDelete); } else { outcome = dynamoDB.batchWriteItemUnprocessed(unprocessed); } unprocessed = outcome.getUnprocessedItems(); } while (unprocessed.size() > 0 && attempts < 6); if(unprocessed.size() > 0) throw new RuntimeException("Error deleting secret " + secretName + " with " + unprocessed.size() + " versions not deleted"); } }
JCredStash { protected void deleteSecret(String tableName, String secretName) throws InterruptedException { QueryResult queryResult = getCredentials(tableName, secretName); TableWriteItems itemsToDelete = new TableWriteItems(tableName); for ( Map<String, AttributeValue> item :queryResult.getItems()) { itemsToDelete.addHashAndRangePrimaryKeyToDelete( "name", item.get("name").getS(), "version", item.get("version").getS()); } Map<String, List<WriteRequest>> unprocessed = null ; int attempts = 0; do { if (attempts > 0) { Thread.sleep((1 << attempts) * 1000); } attempts++; BatchWriteItemOutcome outcome; if (unprocessed == null || unprocessed.size() > 0) { outcome = dynamoDB.batchWriteItem(itemsToDelete); } else { outcome = dynamoDB.batchWriteItemUnprocessed(unprocessed); } unprocessed = outcome.getUnprocessedItems(); } while (unprocessed.size() > 0 && attempts < 6); if(unprocessed.size() > 0) throw new RuntimeException("Error deleting secret " + secretName + " with " + unprocessed.size() + " versions not deleted"); } protected  JCredStash(); protected  JCredStash(AWSCredentialsProvider awsCredentialsProvider); protected  JCredStash(AmazonDynamoDB amazonDynamoDBClient, AWSKMS awskmsClient); protected  JCredStash(AmazonDynamoDB amazonDynamoDBClient, AWSKMS awskmsClient, AWSSecurityTokenService awsSecurityTokenService); }
JCredStash { protected void deleteSecret(String tableName, String secretName) throws InterruptedException { QueryResult queryResult = getCredentials(tableName, secretName); TableWriteItems itemsToDelete = new TableWriteItems(tableName); for ( Map<String, AttributeValue> item :queryResult.getItems()) { itemsToDelete.addHashAndRangePrimaryKeyToDelete( "name", item.get("name").getS(), "version", item.get("version").getS()); } Map<String, List<WriteRequest>> unprocessed = null ; int attempts = 0; do { if (attempts > 0) { Thread.sleep((1 << attempts) * 1000); } attempts++; BatchWriteItemOutcome outcome; if (unprocessed == null || unprocessed.size() > 0) { outcome = dynamoDB.batchWriteItem(itemsToDelete); } else { outcome = dynamoDB.batchWriteItemUnprocessed(unprocessed); } unprocessed = outcome.getUnprocessedItems(); } while (unprocessed.size() > 0 && attempts < 6); if(unprocessed.size() > 0) throw new RuntimeException("Error deleting secret " + secretName + " with " + unprocessed.size() + " versions not deleted"); } protected  JCredStash(); protected  JCredStash(AWSCredentialsProvider awsCredentialsProvider); protected  JCredStash(AmazonDynamoDB amazonDynamoDBClient, AWSKMS awskmsClient); protected  JCredStash(AmazonDynamoDB amazonDynamoDBClient, AWSKMS awskmsClient, AWSSecurityTokenService awsSecurityTokenService);  }
JCredStash { protected void deleteSecret(String tableName, String secretName) throws InterruptedException { QueryResult queryResult = getCredentials(tableName, secretName); TableWriteItems itemsToDelete = new TableWriteItems(tableName); for ( Map<String, AttributeValue> item :queryResult.getItems()) { itemsToDelete.addHashAndRangePrimaryKeyToDelete( "name", item.get("name").getS(), "version", item.get("version").getS()); } Map<String, List<WriteRequest>> unprocessed = null ; int attempts = 0; do { if (attempts > 0) { Thread.sleep((1 << attempts) * 1000); } attempts++; BatchWriteItemOutcome outcome; if (unprocessed == null || unprocessed.size() > 0) { outcome = dynamoDB.batchWriteItem(itemsToDelete); } else { outcome = dynamoDB.batchWriteItemUnprocessed(unprocessed); } unprocessed = outcome.getUnprocessedItems(); } while (unprocessed.size() > 0 && attempts < 6); if(unprocessed.size() > 0) throw new RuntimeException("Error deleting secret " + secretName + " with " + unprocessed.size() + " versions not deleted"); } protected  JCredStash(); protected  JCredStash(AWSCredentialsProvider awsCredentialsProvider); protected  JCredStash(AmazonDynamoDB amazonDynamoDBClient, AWSKMS awskmsClient); protected  JCredStash(AmazonDynamoDB amazonDynamoDBClient, AWSKMS awskmsClient, AWSSecurityTokenService awsSecurityTokenService);   }