Repository navigation
Feature/appsync events cfn #8912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
MasterOfMastersDestoyerOfWorlds
wants to merge
2
commits into
floci-io:main
from
MasterOfMastersDestoyerOfWorlds:feature/appsync-events-cfn
+1,954
−52
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/main/java/io/floci/aws/services/appsync/AppSyncApiController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package io.floci.aws.services.appsync; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.node.ArrayNode; | ||
| import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| import io.floci.aws.core.common.AwsException; | ||
| import io.floci.aws.core.common.RegionResolver; | ||
| import io.floci.aws.services.appsync.model.Api; | ||
| 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.Path; | ||
| import jakarta.ws.rs.PathParam; | ||
| import jakarta.ws.rs.Produces; | ||
| import jakarta.ws.rs.QueryParam; | ||
| 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 java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * AppSync Events API management: {@code CreateApi}, {@code GetApi}, {@code UpdateApi}, | ||
| * {@code DeleteApi} and {@code ListApis}. AWS serves them on {@code /v2/apis}, which API Gateway | ||
| * v2 also claims, so {@link AppSyncEventsRouteFilter} moves an appsync-signed request onto this | ||
| * controller's internal prefix. | ||
| */ | ||
| @Path(AppSyncEventsRouteFilter.INTERNAL_PREFIX + "/v2/apis") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @Consumes(MediaType.APPLICATION_JSON) | ||
| public class AppSyncApiController { | ||
|
|
||
| private final AppSyncService service; | ||
| private final RegionResolver regionResolver; | ||
| private final ObjectMapper objectMapper; | ||
|
|
||
| @Inject | ||
| public AppSyncApiController(AppSyncService service, RegionResolver regionResolver, ObjectMapper objectMapper) { | ||
| this.service = service; | ||
| this.regionResolver = regionResolver; | ||
| this.objectMapper = objectMapper; | ||
| } | ||
|
|
||
| @POST | ||
| public Response createApi(@Context HttpHeaders headers, String body) throws IOException { | ||
| Api api = service.createApi(readRequest(body), regionResolver.resolveRegion(headers)); | ||
| return Response.ok(wrap(api)).build(); | ||
|
Comment on lines
+50
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 5. Query-signed apis get the wrong region createApi passes RegionResolver.resolveRegion(headers) to the service, but that method does not read the credential in a query-signed request. When such a request has no Authorization header and signs for a region other than the configured default, the created API receives the default region in its ARN and DNS names. Agent Prompt
|
||
| } | ||
|
|
||
| @GET | ||
| public Response listApis(@QueryParam("maxResults") Integer maxResults, | ||
| @QueryParam("nextToken") String nextToken) { | ||
| AppSyncService.Page<Api> page = service.listApis(maxResults, nextToken); | ||
| ObjectNode root = objectMapper.createObjectNode(); | ||
| ArrayNode items = root.putArray("apis"); | ||
| for (Api api : page.items()) { | ||
| items.add(objectMapper.valueToTree(api)); | ||
| } | ||
| if (page.nextToken() != null) { | ||
| root.put("nextToken", page.nextToken()); | ||
| } | ||
| return Response.ok(root).build(); | ||
| } | ||
|
|
||
| @GET | ||
| @Path("/{apiId}") | ||
| public Response getApi(@PathParam("apiId") String apiId) { | ||
| return Response.ok(wrap(service.getApi(apiId))).build(); | ||
| } | ||
|
|
||
| @POST | ||
| @Path("/{apiId}") | ||
| public Response updateApi(@PathParam("apiId") String apiId, String body) throws IOException { | ||
| return Response.ok(wrap(service.updateApi(apiId, readRequest(body)))).build(); | ||
| } | ||
|
|
||
| @DELETE | ||
| @Path("/{apiId}") | ||
| public Response deleteApi(@PathParam("apiId") String apiId) { | ||
| service.deleteApi(apiId); | ||
| return Response.ok(objectMapper.createObjectNode()).build(); | ||
| } | ||
|
|
||
| private ObjectNode wrap(Api api) { | ||
| ObjectNode root = objectMapper.createObjectNode(); | ||
| root.set("api", objectMapper.valueToTree(api)); | ||
| return root; | ||
| } | ||
|
|
||
| private Map<String, Object> readRequest(String body) throws IOException { | ||
| if (body == null || body.isBlank()) { | ||
| return Map.of(); | ||
| } | ||
| Map<String, Object> request = objectMapper.readValue(body, new TypeReference<Map<String, Object>>() {}); | ||
| if (request == null) { | ||
| throw new AwsException("BadRequestException", "The request body must be a JSON object", 400); | ||
| } | ||
| return request; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7. Docs promise a failure that updates never raise
🐞 Bug⚙ MaintainabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation toolsDismiss ↗ | View ↗