class AutomationSecretResource {

  @Timed @ExceptionMetered
  @POST
  @Consumes(APPLICATION_JSON)
  public AutomationSecretResponse createSecret(
      @Auth AutomationClient automationClient,
      @Valid CreateSecretRequest request) {

    SecretController.SecretBuilder builder = secretController.builder(request.name, request.content,
        automationClient.getName(), request.expiry)
        .withDescription(nullToEmpty(request.description));

    if (request.metadata != null) {
      builder.withMetadata(request.metadata);
    }

    Secret secret;
    try {
      secret = builder.create();
    } catch (DataAccessException e) {
      logger.info(format("Cannot create secret %s", request.name), e);
      throw new ConflictException(format("Cannot create secret %s.", request.name));
    }
    ImmutableList<Group> groups =
        ImmutableList.copyOf(aclDAO.getGroupsFor(secret));

    Map<String, String> extraInfo = new HashMap<>();
    extraInfo.put("deprecated", "true");
    if (request.description != null) {
      extraInfo.put("description", request.description);
    }
    if (request.metadata != null) {
      extraInfo.put("metadata", request.metadata.toString());
    }
    extraInfo.put("expiry", Long.toString(request.expiry));
    auditLog.recordEvent(new Event(Instant.now(), EventTag.SECRET_CREATE, automationClient.getName(), request.name, extraInfo));

    return AutomationSecretResponse.fromSecret(secret, groups);
  }

  @Inject public  AutomationSecretResource(SecretController secretController,
                                          SecretDAOFactory secretDAOFactory, AclDAOFactory aclDAOFactory, AuditLog auditLog);
  @VisibleForTesting  AutomationSecretResource(SecretController secretController,
                                              SecretDAO secretDAO, AclDAO aclDAO, AuditLog auditLog);

}