@Test(expected = IllegalArgumentException.class) public void rollbackThrowsIfNoIdSpecified() throws Exception { rollbackActionConfig.name = "test-name"; rollbackActionConfig.id = null; rollbackAction.run(); }
@Override public void run() { try { if (rollbackActionConfig.name == null || !validName(rollbackActionConfig.name)) { throw new IllegalArgumentException( format("Invalid name, must match %s", VALID_NAME_PATTERN)); } if (rollbackActionConfig.id == null) { throw new IllegalArgumentException( "Version ID must be specified for rollback. List the secret's versions to view IDs."); } SanitizedSecret sanitizedSecret = keywhizClient.getSanitizedSecretByName(rollbackActionConfig.name); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8)); while (true) { System.out.println( format("Please confirm rollback of secret '%s' to version with ID %d: Y/N", sanitizedSecret.name(), rollbackActionConfig.id)); String line = reader.readLine(); if (line == null || line.toUpperCase().startsWith("N")) { return; } else if (line.toUpperCase().startsWith("Y")) { logger.info("Rolling back secret '{}' to version {}", sanitizedSecret.name(), rollbackActionConfig.id); keywhizClient.rollbackSecret(sanitizedSecret.name(), rollbackActionConfig.id); return; } } } catch (NotFoundException e) { throw new AssertionError("Secret does not exist: " + rollbackActionConfig.name); } catch (IOException e) { throw new AssertionError(String.format( "Error executing rollback; check whether ID %d is a valid version ID for secret %s by listing the secret's versions%nError: %s", rollbackActionConfig.id, rollbackActionConfig.name, e.getMessage())); } catch (Exception e) { throw Throwables.propagate(e); } }
RollbackAction implements Runnable { @Override public void run() { try { if (rollbackActionConfig.name == null || !validName(rollbackActionConfig.name)) { throw new IllegalArgumentException( format("Invalid name, must match %s", VALID_NAME_PATTERN)); } if (rollbackActionConfig.id == null) { throw new IllegalArgumentException( "Version ID must be specified for rollback. List the secret's versions to view IDs."); } SanitizedSecret sanitizedSecret = keywhizClient.getSanitizedSecretByName(rollbackActionConfig.name); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8)); while (true) { System.out.println( format("Please confirm rollback of secret '%s' to version with ID %d: Y/N", sanitizedSecret.name(), rollbackActionConfig.id)); String line = reader.readLine(); if (line == null || line.toUpperCase().startsWith("N")) { return; } else if (line.toUpperCase().startsWith("Y")) { logger.info("Rolling back secret '{}' to version {}", sanitizedSecret.name(), rollbackActionConfig.id); keywhizClient.rollbackSecret(sanitizedSecret.name(), rollbackActionConfig.id); return; } } } catch (NotFoundException e) { throw new AssertionError("Secret does not exist: " + rollbackActionConfig.name); } catch (IOException e) { throw new AssertionError(String.format( "Error executing rollback; check whether ID %d is a valid version ID for secret %s by listing the secret's versions%nError: %s", rollbackActionConfig.id, rollbackActionConfig.name, e.getMessage())); } catch (Exception e) { throw Throwables.propagate(e); } } }
RollbackAction implements Runnable { @Override public void run() { try { if (rollbackActionConfig.name == null || !validName(rollbackActionConfig.name)) { throw new IllegalArgumentException( format("Invalid name, must match %s", VALID_NAME_PATTERN)); } if (rollbackActionConfig.id == null) { throw new IllegalArgumentException( "Version ID must be specified for rollback. List the secret's versions to view IDs."); } SanitizedSecret sanitizedSecret = keywhizClient.getSanitizedSecretByName(rollbackActionConfig.name); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8)); while (true) { System.out.println( format("Please confirm rollback of secret '%s' to version with ID %d: Y/N", sanitizedSecret.name(), rollbackActionConfig.id)); String line = reader.readLine(); if (line == null || line.toUpperCase().startsWith("N")) { return; } else if (line.toUpperCase().startsWith("Y")) { logger.info("Rolling back secret '{}' to version {}", sanitizedSecret.name(), rollbackActionConfig.id); keywhizClient.rollbackSecret(sanitizedSecret.name(), rollbackActionConfig.id); return; } } } catch (NotFoundException e) { throw new AssertionError("Secret does not exist: " + rollbackActionConfig.name); } catch (IOException e) { throw new AssertionError(String.format( "Error executing rollback; check whether ID %d is a valid version ID for secret %s by listing the secret's versions%nError: %s", rollbackActionConfig.id, rollbackActionConfig.name, e.getMessage())); } catch (Exception e) { throw Throwables.propagate(e); } } RollbackAction(RollbackActionConfig rollbackActionConfig, KeywhizClient client); }
RollbackAction implements Runnable { @Override public void run() { try { if (rollbackActionConfig.name == null || !validName(rollbackActionConfig.name)) { throw new IllegalArgumentException( format("Invalid name, must match %s", VALID_NAME_PATTERN)); } if (rollbackActionConfig.id == null) { throw new IllegalArgumentException( "Version ID must be specified for rollback. List the secret's versions to view IDs."); } SanitizedSecret sanitizedSecret = keywhizClient.getSanitizedSecretByName(rollbackActionConfig.name); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8)); while (true) { System.out.println( format("Please confirm rollback of secret '%s' to version with ID %d: Y/N", sanitizedSecret.name(), rollbackActionConfig.id)); String line = reader.readLine(); if (line == null || line.toUpperCase().startsWith("N")) { return; } else if (line.toUpperCase().startsWith("Y")) { logger.info("Rolling back secret '{}' to version {}", sanitizedSecret.name(), rollbackActionConfig.id); keywhizClient.rollbackSecret(sanitizedSecret.name(), rollbackActionConfig.id); return; } } } catch (NotFoundException e) { throw new AssertionError("Secret does not exist: " + rollbackActionConfig.name); } catch (IOException e) { throw new AssertionError(String.format( "Error executing rollback; check whether ID %d is a valid version ID for secret %s by listing the secret's versions%nError: %s", rollbackActionConfig.id, rollbackActionConfig.name, e.getMessage())); } catch (Exception e) { throw Throwables.propagate(e); } } RollbackAction(RollbackActionConfig rollbackActionConfig, KeywhizClient client); @Override void run(); }
RollbackAction implements Runnable { @Override public void run() { try { if (rollbackActionConfig.name == null || !validName(rollbackActionConfig.name)) { throw new IllegalArgumentException( format("Invalid name, must match %s", VALID_NAME_PATTERN)); } if (rollbackActionConfig.id == null) { throw new IllegalArgumentException( "Version ID must be specified for rollback. List the secret's versions to view IDs."); } SanitizedSecret sanitizedSecret = keywhizClient.getSanitizedSecretByName(rollbackActionConfig.name); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8)); while (true) { System.out.println( format("Please confirm rollback of secret '%s' to version with ID %d: Y/N", sanitizedSecret.name(), rollbackActionConfig.id)); String line = reader.readLine(); if (line == null || line.toUpperCase().startsWith("N")) { return; } else if (line.toUpperCase().startsWith("Y")) { logger.info("Rolling back secret '{}' to version {}", sanitizedSecret.name(), rollbackActionConfig.id); keywhizClient.rollbackSecret(sanitizedSecret.name(), rollbackActionConfig.id); return; } } } catch (NotFoundException e) { throw new AssertionError("Secret does not exist: " + rollbackActionConfig.name); } catch (IOException e) { throw new AssertionError(String.format( "Error executing rollback; check whether ID %d is a valid version ID for secret %s by listing the secret's versions%nError: %s", rollbackActionConfig.id, rollbackActionConfig.name, e.getMessage())); } catch (Exception e) { throw Throwables.propagate(e); } } RollbackAction(RollbackActionConfig rollbackActionConfig, KeywhizClient client); @Override void run();  }