@Test public void createOrUpdateSecret() throws Exception { CreateOrUpdateSecretRequestV2 request = CreateOrUpdateSecretRequestV2.builder() .content(encoder.encodeToString("supa secret".getBytes(UTF_8))) .description("desc") .metadata(ImmutableMap.of("owner", "root", "mode", "0440")) .type("password") .build(); Response httpResponse = createOrUpdate(request, "secret3"); assertThat(httpResponse.code()).isEqualTo(201); URI location = URI.create(httpResponse.header(LOCATION)); assertThat(location.getPath()).isEqualTo("/automation/v2/secrets/secret3"); httpResponse = createOrUpdate(request, "secret3"); assertThat(httpResponse.code()).isEqualTo(201); location = URI.create(httpResponse.header(LOCATION)); assertThat(location.getPath()).isEqualTo("/automation/v2/secrets/secret3"); }
@Timed @ExceptionMetered @Path("{name}") @POST @Consumes(APPLICATION_JSON) public Response createOrUpdateSecret(@Auth AutomationClient automationClient, @PathParam("name") String name, @Valid CreateOrUpdateSecretRequestV2 request) { SecretBuilder builder = secretController .builder(name, request.content(), automationClient.getName(), request.expiry()) .withDescription(request.description()) .withMetadata(request.metadata()) .withType(request.type()); builder.createOrUpdate(); Map<String, String> extraInfo = new HashMap<>(); 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_CREATEORUPDATE, automationClient.getName(), name, extraInfo)); UriBuilder uriBuilder = UriBuilder.fromResource(SecretResource.class).path(name); return Response.created(uriBuilder.build()).build(); }
SecretResource { @Timed @ExceptionMetered @Path("{name}") @POST @Consumes(APPLICATION_JSON) public Response createOrUpdateSecret(@Auth AutomationClient automationClient, @PathParam("name") String name, @Valid CreateOrUpdateSecretRequestV2 request) { SecretBuilder builder = secretController .builder(name, request.content(), automationClient.getName(), request.expiry()) .withDescription(request.description()) .withMetadata(request.metadata()) .withType(request.type()); builder.createOrUpdate(); Map<String, String> extraInfo = new HashMap<>(); 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_CREATEORUPDATE, automationClient.getName(), name, extraInfo)); UriBuilder uriBuilder = UriBuilder.fromResource(SecretResource.class).path(name); return Response.created(uriBuilder.build()).build(); } }
SecretResource { @Timed @ExceptionMetered @Path("{name}") @POST @Consumes(APPLICATION_JSON) public Response createOrUpdateSecret(@Auth AutomationClient automationClient, @PathParam("name") String name, @Valid CreateOrUpdateSecretRequestV2 request) { SecretBuilder builder = secretController .builder(name, request.content(), automationClient.getName(), request.expiry()) .withDescription(request.description()) .withMetadata(request.metadata()) .withType(request.type()); builder.createOrUpdate(); Map<String, String> extraInfo = new HashMap<>(); 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_CREATEORUPDATE, automationClient.getName(), name, extraInfo)); UriBuilder uriBuilder = UriBuilder.fromResource(SecretResource.class).path(name); return Response.created(uriBuilder.build()).build(); } @Inject  SecretResource(SecretController secretController, AclDAOFactory aclDAOFactory,
      GroupDAOFactory groupDAOFactory, SecretDAOFactory secretDAOFactory, AuditLog auditLog,
      SecretSeriesDAOFactory secretSeriesDAOFactory, ContentCryptographer cryptographer,
      @Readonly SecretController secretControllerReadOnly); }
SecretResource { @Timed @ExceptionMetered @Path("{name}") @POST @Consumes(APPLICATION_JSON) public Response createOrUpdateSecret(@Auth AutomationClient automationClient, @PathParam("name") String name, @Valid CreateOrUpdateSecretRequestV2 request) { SecretBuilder builder = secretController .builder(name, request.content(), automationClient.getName(), request.expiry()) .withDescription(request.description()) .withMetadata(request.metadata()) .withType(request.type()); builder.createOrUpdate(); Map<String, String> extraInfo = new HashMap<>(); 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_CREATEORUPDATE, automationClient.getName(), name, extraInfo)); UriBuilder uriBuilder = UriBuilder.fromResource(SecretResource.class).path(name); return Response.created(uriBuilder.build()).build(); } @Inject  SecretResource(SecretController secretController, AclDAOFactory aclDAOFactory,
      GroupDAOFactory groupDAOFactory, SecretDAOFactory secretDAOFactory, AuditLog auditLog,
      SecretSeriesDAOFactory secretSeriesDAOFactory, ContentCryptographer cryptographer,
      @Readonly SecretController secretControllerReadOnly); @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response createSecret(@Auth AutomationClient automationClient,
      @Valid CreateSecretRequestV2 request); @Timed @ExceptionMetered @Path("{name}") @POST @Consumes(APPLICATION_JSON) Response createOrUpdateSecret(@Auth AutomationClient automationClient,
      @PathParam("name") String name,
      @Valid CreateOrUpdateSecretRequestV2 request); @Timed @ExceptionMetered @Path("{name}/partialupdate") @POST @Consumes(APPLICATION_JSON) Response partialUpdateSecret(@Auth AutomationClient automationClient,
      @PathParam("name") String name,
      @Valid PartialUpdateSecretRequestV2 request); @Timed @ExceptionMetered @GET @Produces(APPLICATION_JSON) Iterable<String> secretListing(@Auth AutomationClient automationClient,
      @QueryParam("idx") Integer idx, @QueryParam("num") Integer num,
      @DefaultValue("true") @QueryParam("newestFirst") boolean newestFirst); @Timed @ExceptionMetered @Path("/v2") @GET @Produces(APPLICATION_JSON) Iterable<SanitizedSecret> secretListingV2(@Auth AutomationClient automationClient,
      @QueryParam("idx") Integer idx, @QueryParam("num") Integer num,
      @DefaultValue("true") @QueryParam("newestFirst") boolean newestFirst); @Timed @ExceptionMetered @Path("expiring/{time}") @GET @Produces(APPLICATION_JSON) Iterable<String> secretListingExpiring(@Auth AutomationClient automationClient, @PathParam("time") Long time); @Timed @ExceptionMetered @Path("expiring/v2/{time}") @GET @Produces(APPLICATION_JSON) Iterable<SanitizedSecret> secretListingExpiringV2(@Auth AutomationClient automationClient, @PathParam("time") Long time); @Timed @ExceptionMetered @Path("expiring/v3/{time}") @GET @Produces(APPLICATION_JSON) Iterable<SanitizedSecretWithGroups> secretListingExpiringV3(@Auth AutomationClient automationClient,
      @PathParam("time") Long maxTime); @Timed @ExceptionMetered @Path("expiring/v4") @GET @Produces(APPLICATION_JSON) SanitizedSecretWithGroupsListAndCursor secretListingExpiringV4(
      @Auth AutomationClient automationClient,
      @QueryParam("maxTime") Long maxTime,
      @QueryParam("limit") Integer limit,
      @QueryParam("cursor") String cursor); @Timed @ExceptionMetered @Path("{name}/backfill-expiration") @POST @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) boolean backfillExpiration(@Auth AutomationClient automationClient, @PathParam("name") String name, List<String> passwords); @Timed @ExceptionMetered @Path("{name}/backfill-hmac") @POST @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) boolean backfillHmac(@Auth AutomationClient automationClient, @PathParam("name") String name); @Timed @ExceptionMetered @Path("expiring/{time}/{name}") @GET @Produces(APPLICATION_JSON) Iterable<String> secretListingExpiringForGroup(@Auth AutomationClient automationClient,
      @PathParam("time") Long time, @PathParam("name") String name); @Timed @ExceptionMetered @GET @Path("{name}") @Produces(APPLICATION_JSON) SecretDetailResponseV2 secretInfo(@Auth AutomationClient automationClient,
      @PathParam("name") String name); @Timed @ExceptionMetered @GET @Path("{name}/sanitized") @Produces(APPLICATION_JSON) SanitizedSecret getSanitizedSecret(@Auth AutomationClient automationClient,
      @PathParam("name") String name); @Timed @ExceptionMetered @POST @Path("request/contents") @Produces(APPLICATION_JSON) SecretContentsResponseV2 secretContents(@Auth AutomationClient automationClient,
      @Valid SecretContentsRequestV2 request); @Timed @ExceptionMetered @GET @Path("{name}/versions") @Produces(APPLICATION_JSON) Iterable<SecretDetailResponseV2> secretVersions(@Auth AutomationClient automationClient,
      @PathParam("name") String name, @QueryParam("versionIdx") int versionIdx,
      @QueryParam("numVersions") int numVersions); @Timed @ExceptionMetered @Path("{name}/setversion") @POST Response resetSecretVersion(@Auth AutomationClient automationClient,
      @Valid SetSecretVersionRequestV2 request); @Timed @ExceptionMetered @GET @Path("{name}/groups") @Produces(APPLICATION_JSON) Iterable<String> secretGroupsListing(@Auth AutomationClient automationClient,
      @PathParam("name") String name); @Timed @ExceptionMetered @PUT @Path("{name}/groups") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) Iterable<String> modifySecretGroups(@Auth AutomationClient automationClient,
      @PathParam("name") String name, @Valid ModifyGroupsRequestV2 request); @Timed @ExceptionMetered @DELETE @Path("{name}") Response deleteSecretSeries(@Auth AutomationClient automationClient,
      @PathParam("name") String name); }
SecretResource { @Timed @ExceptionMetered @Path("{name}") @POST @Consumes(APPLICATION_JSON) public Response createOrUpdateSecret(@Auth AutomationClient automationClient, @PathParam("name") String name, @Valid CreateOrUpdateSecretRequestV2 request) { SecretBuilder builder = secretController .builder(name, request.content(), automationClient.getName(), request.expiry()) .withDescription(request.description()) .withMetadata(request.metadata()) .withType(request.type()); builder.createOrUpdate(); Map<String, String> extraInfo = new HashMap<>(); 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_CREATEORUPDATE, automationClient.getName(), name, extraInfo)); UriBuilder uriBuilder = UriBuilder.fromResource(SecretResource.class).path(name); return Response.created(uriBuilder.build()).build(); } @Inject  SecretResource(SecretController secretController, AclDAOFactory aclDAOFactory,
      GroupDAOFactory groupDAOFactory, SecretDAOFactory secretDAOFactory, AuditLog auditLog,
      SecretSeriesDAOFactory secretSeriesDAOFactory, ContentCryptographer cryptographer,
      @Readonly SecretController secretControllerReadOnly); @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response createSecret(@Auth AutomationClient automationClient,
      @Valid CreateSecretRequestV2 request); @Timed @ExceptionMetered @Path("{name}") @POST @Consumes(APPLICATION_JSON) Response createOrUpdateSecret(@Auth AutomationClient automationClient,
      @PathParam("name") String name,
      @Valid CreateOrUpdateSecretRequestV2 request); @Timed @ExceptionMetered @Path("{name}/partialupdate") @POST @Consumes(APPLICATION_JSON) Response partialUpdateSecret(@Auth AutomationClient automationClient,
      @PathParam("name") String name,
      @Valid PartialUpdateSecretRequestV2 request); @Timed @ExceptionMetered @GET @Produces(APPLICATION_JSON) Iterable<String> secretListing(@Auth AutomationClient automationClient,
      @QueryParam("idx") Integer idx, @QueryParam("num") Integer num,
      @DefaultValue("true") @QueryParam("newestFirst") boolean newestFirst); @Timed @ExceptionMetered @Path("/v2") @GET @Produces(APPLICATION_JSON) Iterable<SanitizedSecret> secretListingV2(@Auth AutomationClient automationClient,
      @QueryParam("idx") Integer idx, @QueryParam("num") Integer num,
      @DefaultValue("true") @QueryParam("newestFirst") boolean newestFirst); @Timed @ExceptionMetered @Path("expiring/{time}") @GET @Produces(APPLICATION_JSON) Iterable<String> secretListingExpiring(@Auth AutomationClient automationClient, @PathParam("time") Long time); @Timed @ExceptionMetered @Path("expiring/v2/{time}") @GET @Produces(APPLICATION_JSON) Iterable<SanitizedSecret> secretListingExpiringV2(@Auth AutomationClient automationClient, @PathParam("time") Long time); @Timed @ExceptionMetered @Path("expiring/v3/{time}") @GET @Produces(APPLICATION_JSON) Iterable<SanitizedSecretWithGroups> secretListingExpiringV3(@Auth AutomationClient automationClient,
      @PathParam("time") Long maxTime); @Timed @ExceptionMetered @Path("expiring/v4") @GET @Produces(APPLICATION_JSON) SanitizedSecretWithGroupsListAndCursor secretListingExpiringV4(
      @Auth AutomationClient automationClient,
      @QueryParam("maxTime") Long maxTime,
      @QueryParam("limit") Integer limit,
      @QueryParam("cursor") String cursor); @Timed @ExceptionMetered @Path("{name}/backfill-expiration") @POST @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) boolean backfillExpiration(@Auth AutomationClient automationClient, @PathParam("name") String name, List<String> passwords); @Timed @ExceptionMetered @Path("{name}/backfill-hmac") @POST @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) boolean backfillHmac(@Auth AutomationClient automationClient, @PathParam("name") String name); @Timed @ExceptionMetered @Path("expiring/{time}/{name}") @GET @Produces(APPLICATION_JSON) Iterable<String> secretListingExpiringForGroup(@Auth AutomationClient automationClient,
      @PathParam("time") Long time, @PathParam("name") String name); @Timed @ExceptionMetered @GET @Path("{name}") @Produces(APPLICATION_JSON) SecretDetailResponseV2 secretInfo(@Auth AutomationClient automationClient,
      @PathParam("name") String name); @Timed @ExceptionMetered @GET @Path("{name}/sanitized") @Produces(APPLICATION_JSON) SanitizedSecret getSanitizedSecret(@Auth AutomationClient automationClient,
      @PathParam("name") String name); @Timed @ExceptionMetered @POST @Path("request/contents") @Produces(APPLICATION_JSON) SecretContentsResponseV2 secretContents(@Auth AutomationClient automationClient,
      @Valid SecretContentsRequestV2 request); @Timed @ExceptionMetered @GET @Path("{name}/versions") @Produces(APPLICATION_JSON) Iterable<SecretDetailResponseV2> secretVersions(@Auth AutomationClient automationClient,
      @PathParam("name") String name, @QueryParam("versionIdx") int versionIdx,
      @QueryParam("numVersions") int numVersions); @Timed @ExceptionMetered @Path("{name}/setversion") @POST Response resetSecretVersion(@Auth AutomationClient automationClient,
      @Valid SetSecretVersionRequestV2 request); @Timed @ExceptionMetered @GET @Path("{name}/groups") @Produces(APPLICATION_JSON) Iterable<String> secretGroupsListing(@Auth AutomationClient automationClient,
      @PathParam("name") String name); @Timed @ExceptionMetered @PUT @Path("{name}/groups") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) Iterable<String> modifySecretGroups(@Auth AutomationClient automationClient,
      @PathParam("name") String name, @Valid ModifyGroupsRequestV2 request); @Timed @ExceptionMetered @DELETE @Path("{name}") Response deleteSecretSeries(@Auth AutomationClient automationClient,
      @PathParam("name") String name);  }