@Test(expected = AssertionError.class) public void deleteThrowsIfDeleteClientFails() throws Exception { deleteActionConfig.deleteType = Arrays.asList("client"); deleteActionConfig.name = "nonexistent-client-name"; when(keywhizClient.getClientByName(deleteActionConfig.name)).thenThrow(new NotFoundException()); deleteAction.run(); }
@Override public void run() { List<String> type = deleteActionConfig.deleteType; if (type == null || type.isEmpty()) { throw new IllegalArgumentException("Must specify a single type to delete."); } if (deleteActionConfig.name == null || !validName(deleteActionConfig.name)) { throw new IllegalArgumentException(format("Invalid name, must match %s", VALID_NAME_PATTERN)); } String firstType = type.get(0).toLowerCase().trim(); switch (firstType) { case "group": try { Group group = keywhizClient.getGroupByName(deleteActionConfig.name); logger.info("Deleting group '{}'.", group.getName()); keywhizClient.deleteGroupWithId(group.getId()); } catch (NotFoundException e) { throw new AssertionError("Group does not exist."); } catch (IOException e) { throw Throwables.propagate(e); } break; case "client": try { Client client = keywhizClient.getClientByName(deleteActionConfig.name); logger.info("Deleting client '{}'.", client.getName()); keywhizClient.deleteClientWithId(client.getId()); } catch (NotFoundException e) { throw new AssertionError("Client does not exist."); } catch (IOException e) { throw Throwables.propagate(e); } break; case "secret": try { SanitizedSecret sanitizedSecret = keywhizClient.getSanitizedSecretByName(deleteActionConfig.name); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8)); while (true) { System.out.println( format("Please confirm deletion of secret '%s': Y/N", sanitizedSecret.name())); String line = reader.readLine(); if (line == null || line.toUpperCase().startsWith("N")) { return; } else if (line.toUpperCase().startsWith("Y")) { logger.info("Deleting secret '{}'.", sanitizedSecret.name()); keywhizClient.deleteSecretWithId(sanitizedSecret.id()); return; } } } catch (NotFoundException e) { throw new AssertionError("Secret does not exist: " + deleteActionConfig.name); } catch (IOException e) { throw new AssertionError(e); } default: throw new IllegalArgumentException("Invalid delete type specified: " + type); } }
DeleteAction implements Runnable { @Override public void run() { List<String> type = deleteActionConfig.deleteType; if (type == null || type.isEmpty()) { throw new IllegalArgumentException("Must specify a single type to delete."); } if (deleteActionConfig.name == null || !validName(deleteActionConfig.name)) { throw new IllegalArgumentException(format("Invalid name, must match %s", VALID_NAME_PATTERN)); } String firstType = type.get(0).toLowerCase().trim(); switch (firstType) { case "group": try { Group group = keywhizClient.getGroupByName(deleteActionConfig.name); logger.info("Deleting group '{}'.", group.getName()); keywhizClient.deleteGroupWithId(group.getId()); } catch (NotFoundException e) { throw new AssertionError("Group does not exist."); } catch (IOException e) { throw Throwables.propagate(e); } break; case "client": try { Client client = keywhizClient.getClientByName(deleteActionConfig.name); logger.info("Deleting client '{}'.", client.getName()); keywhizClient.deleteClientWithId(client.getId()); } catch (NotFoundException e) { throw new AssertionError("Client does not exist."); } catch (IOException e) { throw Throwables.propagate(e); } break; case "secret": try { SanitizedSecret sanitizedSecret = keywhizClient.getSanitizedSecretByName(deleteActionConfig.name); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8)); while (true) { System.out.println( format("Please confirm deletion of secret '%s': Y/N", sanitizedSecret.name())); String line = reader.readLine(); if (line == null || line.toUpperCase().startsWith("N")) { return; } else if (line.toUpperCase().startsWith("Y")) { logger.info("Deleting secret '{}'.", sanitizedSecret.name()); keywhizClient.deleteSecretWithId(sanitizedSecret.id()); return; } } } catch (NotFoundException e) { throw new AssertionError("Secret does not exist: " + deleteActionConfig.name); } catch (IOException e) { throw new AssertionError(e); } default: throw new IllegalArgumentException("Invalid delete type specified: " + type); } } }
DeleteAction implements Runnable { @Override public void run() { List<String> type = deleteActionConfig.deleteType; if (type == null || type.isEmpty()) { throw new IllegalArgumentException("Must specify a single type to delete."); } if (deleteActionConfig.name == null || !validName(deleteActionConfig.name)) { throw new IllegalArgumentException(format("Invalid name, must match %s", VALID_NAME_PATTERN)); } String firstType = type.get(0).toLowerCase().trim(); switch (firstType) { case "group": try { Group group = keywhizClient.getGroupByName(deleteActionConfig.name); logger.info("Deleting group '{}'.", group.getName()); keywhizClient.deleteGroupWithId(group.getId()); } catch (NotFoundException e) { throw new AssertionError("Group does not exist."); } catch (IOException e) { throw Throwables.propagate(e); } break; case "client": try { Client client = keywhizClient.getClientByName(deleteActionConfig.name); logger.info("Deleting client '{}'.", client.getName()); keywhizClient.deleteClientWithId(client.getId()); } catch (NotFoundException e) { throw new AssertionError("Client does not exist."); } catch (IOException e) { throw Throwables.propagate(e); } break; case "secret": try { SanitizedSecret sanitizedSecret = keywhizClient.getSanitizedSecretByName(deleteActionConfig.name); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8)); while (true) { System.out.println( format("Please confirm deletion of secret '%s': Y/N", sanitizedSecret.name())); String line = reader.readLine(); if (line == null || line.toUpperCase().startsWith("N")) { return; } else if (line.toUpperCase().startsWith("Y")) { logger.info("Deleting secret '{}'.", sanitizedSecret.name()); keywhizClient.deleteSecretWithId(sanitizedSecret.id()); return; } } } catch (NotFoundException e) { throw new AssertionError("Secret does not exist: " + deleteActionConfig.name); } catch (IOException e) { throw new AssertionError(e); } default: throw new IllegalArgumentException("Invalid delete type specified: " + type); } } DeleteAction(DeleteActionConfig deleteActionConfig, KeywhizClient client); }
DeleteAction implements Runnable { @Override public void run() { List<String> type = deleteActionConfig.deleteType; if (type == null || type.isEmpty()) { throw new IllegalArgumentException("Must specify a single type to delete."); } if (deleteActionConfig.name == null || !validName(deleteActionConfig.name)) { throw new IllegalArgumentException(format("Invalid name, must match %s", VALID_NAME_PATTERN)); } String firstType = type.get(0).toLowerCase().trim(); switch (firstType) { case "group": try { Group group = keywhizClient.getGroupByName(deleteActionConfig.name); logger.info("Deleting group '{}'.", group.getName()); keywhizClient.deleteGroupWithId(group.getId()); } catch (NotFoundException e) { throw new AssertionError("Group does not exist."); } catch (IOException e) { throw Throwables.propagate(e); } break; case "client": try { Client client = keywhizClient.getClientByName(deleteActionConfig.name); logger.info("Deleting client '{}'.", client.getName()); keywhizClient.deleteClientWithId(client.getId()); } catch (NotFoundException e) { throw new AssertionError("Client does not exist."); } catch (IOException e) { throw Throwables.propagate(e); } break; case "secret": try { SanitizedSecret sanitizedSecret = keywhizClient.getSanitizedSecretByName(deleteActionConfig.name); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8)); while (true) { System.out.println( format("Please confirm deletion of secret '%s': Y/N", sanitizedSecret.name())); String line = reader.readLine(); if (line == null || line.toUpperCase().startsWith("N")) { return; } else if (line.toUpperCase().startsWith("Y")) { logger.info("Deleting secret '{}'.", sanitizedSecret.name()); keywhizClient.deleteSecretWithId(sanitizedSecret.id()); return; } } } catch (NotFoundException e) { throw new AssertionError("Secret does not exist: " + deleteActionConfig.name); } catch (IOException e) { throw new AssertionError(e); } default: throw new IllegalArgumentException("Invalid delete type specified: " + type); } } DeleteAction(DeleteActionConfig deleteActionConfig, KeywhizClient client); @Override void run(); }
DeleteAction implements Runnable { @Override public void run() { List<String> type = deleteActionConfig.deleteType; if (type == null || type.isEmpty()) { throw new IllegalArgumentException("Must specify a single type to delete."); } if (deleteActionConfig.name == null || !validName(deleteActionConfig.name)) { throw new IllegalArgumentException(format("Invalid name, must match %s", VALID_NAME_PATTERN)); } String firstType = type.get(0).toLowerCase().trim(); switch (firstType) { case "group": try { Group group = keywhizClient.getGroupByName(deleteActionConfig.name); logger.info("Deleting group '{}'.", group.getName()); keywhizClient.deleteGroupWithId(group.getId()); } catch (NotFoundException e) { throw new AssertionError("Group does not exist."); } catch (IOException e) { throw Throwables.propagate(e); } break; case "client": try { Client client = keywhizClient.getClientByName(deleteActionConfig.name); logger.info("Deleting client '{}'.", client.getName()); keywhizClient.deleteClientWithId(client.getId()); } catch (NotFoundException e) { throw new AssertionError("Client does not exist."); } catch (IOException e) { throw Throwables.propagate(e); } break; case "secret": try { SanitizedSecret sanitizedSecret = keywhizClient.getSanitizedSecretByName(deleteActionConfig.name); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8)); while (true) { System.out.println( format("Please confirm deletion of secret '%s': Y/N", sanitizedSecret.name())); String line = reader.readLine(); if (line == null || line.toUpperCase().startsWith("N")) { return; } else if (line.toUpperCase().startsWith("Y")) { logger.info("Deleting secret '{}'.", sanitizedSecret.name()); keywhizClient.deleteSecretWithId(sanitizedSecret.id()); return; } } } catch (NotFoundException e) { throw new AssertionError("Secret does not exist: " + deleteActionConfig.name); } catch (IOException e) { throw new AssertionError(e); } default: throw new IllegalArgumentException("Invalid delete type specified: " + type); } } DeleteAction(DeleteActionConfig deleteActionConfig, KeywhizClient client); @Override void run();  }