@Test public void rollbackSuccess() { Secret secret1 = new Secret(1, "name1", "desc", () -> "secret", "checksum", NOW, "user", NOW, "user", emptyMap, null, null, 1136214245, 125L, NOW, "user"); when(secretController.getSecretByName("name1")).thenReturn(Optional.of(secret1)); Response response = resource.resetSecretVersion(user, "name1", new LongParam("125")); assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CREATED); }
@Path("rollback/{secretName}/{versionId}") @Timed @ExceptionMetered @POST public Response resetSecretVersion(@Auth User user, @PathParam("secretName") String secretName, @PathParam("versionId") LongParam versionId) { logger.info("User '{}' rolling back secret '{}' to version with ID '{}'.", user, secretName, versionId); secretDAOReadWrite.setCurrentSecretVersionByName(secretName, versionId.get(), user.getName()); Map<String, String> extraInfo = new HashMap<>(); extraInfo.put("new version", versionId.toString()); auditLog.recordEvent( new Event(Instant.now(), EventTag.SECRET_CHANGEVERSION, user.getName(), secretName, extraInfo)); URI uri = UriBuilder.fromResource(SecretsResource.class) .path("rollback/{secretName}/{versionID}") .build(secretName, versionId); return Response.created(uri).entity(secretDetailResponseFromName(secretName)).build(); }
SecretsResource { @Path("rollback/{secretName}/{versionId}") @Timed @ExceptionMetered @POST public Response resetSecretVersion(@Auth User user, @PathParam("secretName") String secretName, @PathParam("versionId") LongParam versionId) { logger.info("User '{}' rolling back secret '{}' to version with ID '{}'.", user, secretName, versionId); secretDAOReadWrite.setCurrentSecretVersionByName(secretName, versionId.get(), user.getName()); Map<String, String> extraInfo = new HashMap<>(); extraInfo.put("new version", versionId.toString()); auditLog.recordEvent( new Event(Instant.now(), EventTag.SECRET_CHANGEVERSION, user.getName(), secretName, extraInfo)); URI uri = UriBuilder.fromResource(SecretsResource.class) .path("rollback/{secretName}/{versionID}") .build(secretName, versionId); return Response.created(uri).entity(secretDetailResponseFromName(secretName)).build(); } }
SecretsResource { @Path("rollback/{secretName}/{versionId}") @Timed @ExceptionMetered @POST public Response resetSecretVersion(@Auth User user, @PathParam("secretName") String secretName, @PathParam("versionId") LongParam versionId) { logger.info("User '{}' rolling back secret '{}' to version with ID '{}'.", user, secretName, versionId); secretDAOReadWrite.setCurrentSecretVersionByName(secretName, versionId.get(), user.getName()); Map<String, String> extraInfo = new HashMap<>(); extraInfo.put("new version", versionId.toString()); auditLog.recordEvent( new Event(Instant.now(), EventTag.SECRET_CHANGEVERSION, user.getName(), secretName, extraInfo)); URI uri = UriBuilder.fromResource(SecretsResource.class) .path("rollback/{secretName}/{versionID}") .build(secretName, versionId); return Response.created(uri).entity(secretDetailResponseFromName(secretName)).build(); } @SuppressWarnings("unused") @Inject  SecretsResource(SecretController secretController, AclDAOFactory aclDAOFactory,
      SecretDAOFactory secretDAOFactory, AuditLog auditLog); @VisibleForTesting  SecretsResource(SecretController secretController, AclDAO aclDAOReadOnly,
      SecretDAO secretDAOReadWrite, AuditLog auditLog); }
SecretsResource { @Path("rollback/{secretName}/{versionId}") @Timed @ExceptionMetered @POST public Response resetSecretVersion(@Auth User user, @PathParam("secretName") String secretName, @PathParam("versionId") LongParam versionId) { logger.info("User '{}' rolling back secret '{}' to version with ID '{}'.", user, secretName, versionId); secretDAOReadWrite.setCurrentSecretVersionByName(secretName, versionId.get(), user.getName()); Map<String, String> extraInfo = new HashMap<>(); extraInfo.put("new version", versionId.toString()); auditLog.recordEvent( new Event(Instant.now(), EventTag.SECRET_CHANGEVERSION, user.getName(), secretName, extraInfo)); URI uri = UriBuilder.fromResource(SecretsResource.class) .path("rollback/{secretName}/{versionID}") .build(secretName, versionId); return Response.created(uri).entity(secretDetailResponseFromName(secretName)).build(); } @SuppressWarnings("unused") @Inject  SecretsResource(SecretController secretController, AclDAOFactory aclDAOFactory,
      SecretDAOFactory secretDAOFactory, AuditLog auditLog); @VisibleForTesting  SecretsResource(SecretController secretController, AclDAO aclDAOReadOnly,
      SecretDAO secretDAOReadWrite, AuditLog auditLog); @Timed @ExceptionMetered @GET Response findSecrets(@Auth User user, @DefaultValue("") @QueryParam("name") String name,
      @DefaultValue("") @QueryParam("nameOnly") String nameOnly, @QueryParam("idx") Integer idx,
      @QueryParam("num") Integer num,
      @DefaultValue("true") @QueryParam("newestFirst") Boolean newestFirst); @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response createSecret(@Auth User user, @Valid CreateSecretRequestV2 request); @Path("{name}") @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response createOrUpdateSecret(@Auth User user, @PathParam("name") String secretName,
      @Valid CreateOrUpdateSecretRequestV2 request); @Path("{name}/partialupdate") @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response partialUpdateSecret(@Auth User user, @PathParam("name") String secretName, @Valid
      PartialUpdateSecretRequestV2 request); @Path("{secretId}") @Timed @ExceptionMetered @GET SecretDetailResponse retrieveSecret(@Auth User user,
      @PathParam("secretId") LongParam secretId); @Timed @ExceptionMetered @GET @Path("versions/{name}") @Produces(APPLICATION_JSON) List<SanitizedSecret> secretVersions(@Auth User user,
      @PathParam("name") String name, @QueryParam("versionIdx") int versionIdx,
      @QueryParam("numVersions") int numVersions); @Path("rollback/{secretName}/{versionId}") @Timed @ExceptionMetered @POST Response resetSecretVersion(@Auth User user, @PathParam("secretName") String secretName,
      @PathParam("versionId") LongParam versionId); @Path("{secretId}") @Timed @ExceptionMetered @DELETE Response deleteSecret(@Auth User user, @PathParam("secretId") LongParam secretId); }
SecretsResource { @Path("rollback/{secretName}/{versionId}") @Timed @ExceptionMetered @POST public Response resetSecretVersion(@Auth User user, @PathParam("secretName") String secretName, @PathParam("versionId") LongParam versionId) { logger.info("User '{}' rolling back secret '{}' to version with ID '{}'.", user, secretName, versionId); secretDAOReadWrite.setCurrentSecretVersionByName(secretName, versionId.get(), user.getName()); Map<String, String> extraInfo = new HashMap<>(); extraInfo.put("new version", versionId.toString()); auditLog.recordEvent( new Event(Instant.now(), EventTag.SECRET_CHANGEVERSION, user.getName(), secretName, extraInfo)); URI uri = UriBuilder.fromResource(SecretsResource.class) .path("rollback/{secretName}/{versionID}") .build(secretName, versionId); return Response.created(uri).entity(secretDetailResponseFromName(secretName)).build(); } @SuppressWarnings("unused") @Inject  SecretsResource(SecretController secretController, AclDAOFactory aclDAOFactory,
      SecretDAOFactory secretDAOFactory, AuditLog auditLog); @VisibleForTesting  SecretsResource(SecretController secretController, AclDAO aclDAOReadOnly,
      SecretDAO secretDAOReadWrite, AuditLog auditLog); @Timed @ExceptionMetered @GET Response findSecrets(@Auth User user, @DefaultValue("") @QueryParam("name") String name,
      @DefaultValue("") @QueryParam("nameOnly") String nameOnly, @QueryParam("idx") Integer idx,
      @QueryParam("num") Integer num,
      @DefaultValue("true") @QueryParam("newestFirst") Boolean newestFirst); @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response createSecret(@Auth User user, @Valid CreateSecretRequestV2 request); @Path("{name}") @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response createOrUpdateSecret(@Auth User user, @PathParam("name") String secretName,
      @Valid CreateOrUpdateSecretRequestV2 request); @Path("{name}/partialupdate") @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response partialUpdateSecret(@Auth User user, @PathParam("name") String secretName, @Valid
      PartialUpdateSecretRequestV2 request); @Path("{secretId}") @Timed @ExceptionMetered @GET SecretDetailResponse retrieveSecret(@Auth User user,
      @PathParam("secretId") LongParam secretId); @Timed @ExceptionMetered @GET @Path("versions/{name}") @Produces(APPLICATION_JSON) List<SanitizedSecret> secretVersions(@Auth User user,
      @PathParam("name") String name, @QueryParam("versionIdx") int versionIdx,
      @QueryParam("numVersions") int numVersions); @Path("rollback/{secretName}/{versionId}") @Timed @ExceptionMetered @POST Response resetSecretVersion(@Auth User user, @PathParam("secretName") String secretName,
      @PathParam("versionId") LongParam versionId); @Path("{secretId}") @Timed @ExceptionMetered @DELETE Response deleteSecret(@Auth User user, @PathParam("secretId") LongParam secretId);  }