@Test(expected = AssertionError.class) public void addThrowsIfInvalidType() throws Exception { addActionConfig.addType = Arrays.asList("invalid_type"); addActionConfig.name = "any-name"; addAction.run(); }
@Override public void run() { List<String> types = config.addType; if (types == null || types.isEmpty()) { throw new IllegalArgumentException("Must specify a single type to add."); } String firstType = types.get(0).toLowerCase().trim(); String name = config.name; if (name == null || !validName(name)) { throw new IllegalArgumentException(format("Invalid name, must match %s", VALID_NAME_PATTERN)); } switch (firstType) { case "group": try { keywhizClient.getGroupByName(name); throw new AssertionError("Group already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } try { keywhizClient.createGroup(name, config.getDescription(), config.getMetadata(mapper)); logger.info("Creating group '{}'.", name); } catch (IOException e) { throw Throwables.propagate(e); } break; case "secret": try { keywhizClient.getSanitizedSecretByName(name); throw new AssertionError("Secret already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } byte[] content = readSecretContent(); ImmutableMap<String, String> metadata = config.getMetadata(mapper); createAndAssignSecret(name, config.getDescription(), content, metadata, config.getExpiry()); break; case "client": try { keywhizClient.getClientByName(name); throw new AssertionError("Client name already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } try { keywhizClient.createClient(name, config.getDescription(), config.getSpiffeId()); logger.info("Creating client '{}'.", name); } catch (IOException e) { throw Throwables.propagate(e); } break; default: throw new AssertionError("Invalid add type specified: " + firstType); } }
AddAction implements Runnable { @Override public void run() { List<String> types = config.addType; if (types == null || types.isEmpty()) { throw new IllegalArgumentException("Must specify a single type to add."); } String firstType = types.get(0).toLowerCase().trim(); String name = config.name; if (name == null || !validName(name)) { throw new IllegalArgumentException(format("Invalid name, must match %s", VALID_NAME_PATTERN)); } switch (firstType) { case "group": try { keywhizClient.getGroupByName(name); throw new AssertionError("Group already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } try { keywhizClient.createGroup(name, config.getDescription(), config.getMetadata(mapper)); logger.info("Creating group '{}'.", name); } catch (IOException e) { throw Throwables.propagate(e); } break; case "secret": try { keywhizClient.getSanitizedSecretByName(name); throw new AssertionError("Secret already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } byte[] content = readSecretContent(); ImmutableMap<String, String> metadata = config.getMetadata(mapper); createAndAssignSecret(name, config.getDescription(), content, metadata, config.getExpiry()); break; case "client": try { keywhizClient.getClientByName(name); throw new AssertionError("Client name already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } try { keywhizClient.createClient(name, config.getDescription(), config.getSpiffeId()); logger.info("Creating client '{}'.", name); } catch (IOException e) { throw Throwables.propagate(e); } break; default: throw new AssertionError("Invalid add type specified: " + firstType); } } }
AddAction implements Runnable { @Override public void run() { List<String> types = config.addType; if (types == null || types.isEmpty()) { throw new IllegalArgumentException("Must specify a single type to add."); } String firstType = types.get(0).toLowerCase().trim(); String name = config.name; if (name == null || !validName(name)) { throw new IllegalArgumentException(format("Invalid name, must match %s", VALID_NAME_PATTERN)); } switch (firstType) { case "group": try { keywhizClient.getGroupByName(name); throw new AssertionError("Group already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } try { keywhizClient.createGroup(name, config.getDescription(), config.getMetadata(mapper)); logger.info("Creating group '{}'.", name); } catch (IOException e) { throw Throwables.propagate(e); } break; case "secret": try { keywhizClient.getSanitizedSecretByName(name); throw new AssertionError("Secret already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } byte[] content = readSecretContent(); ImmutableMap<String, String> metadata = config.getMetadata(mapper); createAndAssignSecret(name, config.getDescription(), content, metadata, config.getExpiry()); break; case "client": try { keywhizClient.getClientByName(name); throw new AssertionError("Client name already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } try { keywhizClient.createClient(name, config.getDescription(), config.getSpiffeId()); logger.info("Creating client '{}'.", name); } catch (IOException e) { throw Throwables.propagate(e); } break; default: throw new AssertionError("Invalid add type specified: " + firstType); } } AddAction(AddActionConfig config, KeywhizClient client, ObjectMapper mapper); }
AddAction implements Runnable { @Override public void run() { List<String> types = config.addType; if (types == null || types.isEmpty()) { throw new IllegalArgumentException("Must specify a single type to add."); } String firstType = types.get(0).toLowerCase().trim(); String name = config.name; if (name == null || !validName(name)) { throw new IllegalArgumentException(format("Invalid name, must match %s", VALID_NAME_PATTERN)); } switch (firstType) { case "group": try { keywhizClient.getGroupByName(name); throw new AssertionError("Group already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } try { keywhizClient.createGroup(name, config.getDescription(), config.getMetadata(mapper)); logger.info("Creating group '{}'.", name); } catch (IOException e) { throw Throwables.propagate(e); } break; case "secret": try { keywhizClient.getSanitizedSecretByName(name); throw new AssertionError("Secret already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } byte[] content = readSecretContent(); ImmutableMap<String, String> metadata = config.getMetadata(mapper); createAndAssignSecret(name, config.getDescription(), content, metadata, config.getExpiry()); break; case "client": try { keywhizClient.getClientByName(name); throw new AssertionError("Client name already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } try { keywhizClient.createClient(name, config.getDescription(), config.getSpiffeId()); logger.info("Creating client '{}'.", name); } catch (IOException e) { throw Throwables.propagate(e); } break; default: throw new AssertionError("Invalid add type specified: " + firstType); } } AddAction(AddActionConfig config, KeywhizClient client, ObjectMapper mapper); @Override void run(); }
AddAction implements Runnable { @Override public void run() { List<String> types = config.addType; if (types == null || types.isEmpty()) { throw new IllegalArgumentException("Must specify a single type to add."); } String firstType = types.get(0).toLowerCase().trim(); String name = config.name; if (name == null || !validName(name)) { throw new IllegalArgumentException(format("Invalid name, must match %s", VALID_NAME_PATTERN)); } switch (firstType) { case "group": try { keywhizClient.getGroupByName(name); throw new AssertionError("Group already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } try { keywhizClient.createGroup(name, config.getDescription(), config.getMetadata(mapper)); logger.info("Creating group '{}'.", name); } catch (IOException e) { throw Throwables.propagate(e); } break; case "secret": try { keywhizClient.getSanitizedSecretByName(name); throw new AssertionError("Secret already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } byte[] content = readSecretContent(); ImmutableMap<String, String> metadata = config.getMetadata(mapper); createAndAssignSecret(name, config.getDescription(), content, metadata, config.getExpiry()); break; case "client": try { keywhizClient.getClientByName(name); throw new AssertionError("Client name already exists."); } catch (NotFoundException e) { } catch (IOException e) { throw Throwables.propagate(e); } try { keywhizClient.createClient(name, config.getDescription(), config.getSpiffeId()); logger.info("Creating client '{}'.", name); } catch (IOException e) { throw Throwables.propagate(e); } break; default: throw new AssertionError("Invalid add type specified: " + firstType); } } AddAction(AddActionConfig config, KeywhizClient client, ObjectMapper mapper); @Override void run();  }