mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
* refactor(tagging): deduplicate tag-dispatch logic across tag controllers (#3594) * fix(docs): support superclass REST method extraction in regen_action_docs - Read inherited JAX-RS methods from superclass when a REST controller extends a base class - Add test_extract_rest_inherits_methods_from_superclass test
This commit is contained in:
1 parent
e82836348b
commit
7981e23dcd
6 files changed
+231
-110
No files matched your search
@@ -0,0 +1,73 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.DELETE;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.PUT;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
|
||||
/**
|
||||
* Base REST controller for tag endpoints mounted at {@code /{arn: .+}}.
|
||||
*
|
||||
* <p>Shared between {@link SharedTagsController} (mounted at {@code /tags}) and
|
||||
* {@link V1TagsController} (mounted at {@code /v1/tags}).
|
||||
*/
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public abstract class AbstractTagsController {
|
||||
|
||||
private final TagDispatcher dispatcher;
|
||||
|
||||
protected AbstractTagsController(TagDispatcher dispatcher) {
|
||||
this.dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
protected TagDispatcher dispatcher() {
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{arn: .+}")
|
||||
public Response listTags(@Context HttpHeaders headers, @PathParam("arn") String arn) {
|
||||
return dispatcher.listTagsForArn(headers, arn);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/{arn: .+}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response tagResourcePost(@Context HttpHeaders headers,
|
||||
@PathParam("arn") String arn,
|
||||
String body) {
|
||||
TagHandler handler = dispatcher.resolveHandler(arn);
|
||||
return dispatcher.tagResourcePost(headers, arn, body,
|
||||
Response.status(handler.tagResourceSuccessStatus()).build());
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{arn: .+}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response tagResourcePut(@Context HttpHeaders headers,
|
||||
@PathParam("arn") String arn,
|
||||
String body) {
|
||||
TagHandler handler = dispatcher.resolveHandler(arn);
|
||||
return dispatcher.tagResourcePut(headers, arn, body,
|
||||
Response.status(handler.tagResourceSuccessStatus()).build());
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{arn: .+}")
|
||||
public Response untagResource(@Context HttpHeaders headers,
|
||||
@Context UriInfo uriInfo,
|
||||
@PathParam("arn") String arn) {
|
||||
TagHandler handler = dispatcher.resolveHandler(arn);
|
||||
return dispatcher.untagResourceForArn(headers, uriInfo, arn,
|
||||
Response.status(handler.untagResourceSuccessStatus()).build(), handler);
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,7 @@ import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.DELETE;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.PUT;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
@@ -34,75 +32,35 @@ import jakarta.ws.rs.core.UriInfo;
|
||||
*/
|
||||
@Path("/tags")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public class SharedTagsController {
|
||||
|
||||
private final TagDispatcher dispatcher;
|
||||
public class SharedTagsController extends AbstractTagsController {
|
||||
|
||||
@Inject
|
||||
public SharedTagsController(Instance<TagHandler> handlers,
|
||||
RegionResolver regionResolver,
|
||||
ObjectMapper objectMapper) {
|
||||
this.dispatcher = new TagDispatcher(handlers, regionResolver, objectMapper);
|
||||
super(new TagDispatcher(handlers, regionResolver, objectMapper));
|
||||
}
|
||||
|
||||
@GET
|
||||
public Response listTagsByQuery(@Context HttpHeaders headers,
|
||||
@QueryParam("resourceArn") String arn) {
|
||||
return dispatcher.listTagsForArn(headers, arn);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{arn: .+}")
|
||||
public Response listTags(@Context HttpHeaders headers, @PathParam("arn") String arn) {
|
||||
return dispatcher.listTagsForArn(headers, arn);
|
||||
return dispatcher().listTagsForArn(headers, arn);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response tagResourceByBody(@Context HttpHeaders headers, String body) {
|
||||
String arn = dispatcher.readResourceArn(body);
|
||||
TagHandler handler = dispatcher.resolveHandler(arn);
|
||||
return dispatcher.doTagResource(headers, handler, arn, body,
|
||||
Response.ok(dispatcher.emptyObject()).build());
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/{arn: .+}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response tagResourcePost(@Context HttpHeaders headers,
|
||||
@PathParam("arn") String arn,
|
||||
String body) {
|
||||
TagHandler handler = dispatcher.resolveHandler(arn);
|
||||
return dispatcher.tagResourcePost(headers, arn, body,
|
||||
Response.status(handler.tagResourceSuccessStatus()).build());
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{arn: .+}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response tagResourcePut(@Context HttpHeaders headers,
|
||||
@PathParam("arn") String arn,
|
||||
String body) {
|
||||
TagHandler handler = dispatcher.resolveHandler(arn);
|
||||
return dispatcher.tagResourcePut(headers, arn, body,
|
||||
Response.status(handler.tagResourceSuccessStatus()).build());
|
||||
String arn = dispatcher().readResourceArn(body);
|
||||
TagHandler handler = dispatcher().resolveHandler(arn);
|
||||
return dispatcher().doTagResource(headers, handler, arn, body,
|
||||
Response.ok(dispatcher().emptyObject()).build());
|
||||
}
|
||||
|
||||
@DELETE
|
||||
public Response untagResourceByQuery(@Context HttpHeaders headers,
|
||||
@Context UriInfo uriInfo,
|
||||
@QueryParam("resourceArn") String arn) {
|
||||
return dispatcher.untagResourceForArn(headers, uriInfo, arn,
|
||||
Response.ok(dispatcher.emptyObject()).build());
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{arn: .+}")
|
||||
public Response untagResource(@Context HttpHeaders headers,
|
||||
@Context UriInfo uriInfo,
|
||||
@PathParam("arn") String arn) {
|
||||
TagHandler handler = dispatcher.resolveHandler(arn);
|
||||
return dispatcher.untagResourceForArn(headers, uriInfo, arn,
|
||||
Response.status(handler.untagResourceSuccessStatus()).build(), handler);
|
||||
return dispatcher().untagResourceForArn(headers, uriInfo, arn,
|
||||
Response.ok(dispatcher().emptyObject()).build());
|
||||
}
|
||||
}
|
||||
@@ -3,19 +3,9 @@ package io.github.hectorvent.floci.core.common;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.enterprise.inject.Instance;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.DELETE;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.PUT;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
|
||||
/**
|
||||
* Dispatcher for the AWS services that put their tag endpoints on {@code /v1/tags/{resourceArn}}
|
||||
@@ -28,52 +18,12 @@ import jakarta.ws.rs.core.UriInfo;
|
||||
*/
|
||||
@Path("/v1/tags")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public class V1TagsController {
|
||||
|
||||
private final TagDispatcher dispatcher;
|
||||
public class V1TagsController extends AbstractTagsController {
|
||||
|
||||
@Inject
|
||||
public V1TagsController(@V1Tags Instance<TagHandler> handlers,
|
||||
RegionResolver regionResolver,
|
||||
ObjectMapper objectMapper) {
|
||||
this.dispatcher = new TagDispatcher(handlers, regionResolver, objectMapper);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{arn: .+}")
|
||||
public Response listTags(@Context HttpHeaders headers, @PathParam("arn") String arn) {
|
||||
return dispatcher.listTagsForArn(headers, arn);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/{arn: .+}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response tagResourcePost(@Context HttpHeaders headers,
|
||||
@PathParam("arn") String arn,
|
||||
String body) {
|
||||
TagHandler handler = dispatcher.resolveHandler(arn);
|
||||
return dispatcher.tagResourcePost(headers, arn, body,
|
||||
Response.status(handler.tagResourceSuccessStatus()).build());
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{arn: .+}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response tagResourcePut(@Context HttpHeaders headers,
|
||||
@PathParam("arn") String arn,
|
||||
String body) {
|
||||
TagHandler handler = dispatcher.resolveHandler(arn);
|
||||
return dispatcher.tagResourcePut(headers, arn, body,
|
||||
Response.status(handler.tagResourceSuccessStatus()).build());
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{arn: .+}")
|
||||
public Response untagResource(@Context HttpHeaders headers,
|
||||
@Context UriInfo uriInfo,
|
||||
@PathParam("arn") String arn) {
|
||||
TagHandler handler = dispatcher.resolveHandler(arn);
|
||||
return dispatcher.untagResourceForArn(headers, uriInfo, arn,
|
||||
Response.status(handler.untagResourceSuccessStatus()).build(), handler);
|
||||
super(new TagDispatcher(handlers, regionResolver, objectMapper));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user