class 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) {
          // group does not exist, continue to add it
        } 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) {
          // secret does not exist, continue to add it
        } 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) {
          // client does not exist, continue to add it
        } 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);
    }
  }

  public  AddAction(AddActionConfig config, KeywhizClient client, ObjectMapper mapper);

}