mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 23:29:28 -05:00
fix(appsync): preserve resolver callback execution scope (#7512)
This commit is contained in:
1 parent
7bc09c7925
commit
1d6ec2b9d1
6 files changed
+124
-11
No files matched your search
+2
-1
@@ -181,7 +181,8 @@ public class AppSyncExecutionController {
|
||||
parsed.operationName(), denyFields);
|
||||
}
|
||||
try (ResolverCallbackSessions.Session session =
|
||||
callbackSessions.open(apiId, authContext.identity(), authContext.authType())) {
|
||||
callbackSessions.open(apiId, authContext.identity(), authContext.authType(),
|
||||
authContext.accountId(), authContext.region())) {
|
||||
ResolveSpec resolve = new ResolveSpec(reachableEndpoint.baseUrl() + "/_floci/appsync/resolve",
|
||||
session.token(), resolveFields, RESOLVE_MAX_BATCH);
|
||||
Map<String, Object> result = sidecarClient.execute(preparedSdl, scalars, parsed.query(),
|
||||
|
||||
+10
-5
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.appsync.graphql.resolver;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RequestScopes;
|
||||
import io.github.hectorvent.floci.services.appsync.model.Resolver;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
@@ -79,11 +80,15 @@ public class ResolverCallbackResource {
|
||||
.entity(Map.of("error", "Resolver callback body is missing invocations")).build();
|
||||
}
|
||||
|
||||
List<Map<String, Object>> results = new ArrayList<>();
|
||||
for (JsonNode node : invocations) {
|
||||
results.add(answer(session.get(), node));
|
||||
}
|
||||
return Response.ok(Map.of("results", results)).build();
|
||||
ResolverCallbackSessions.Session execution = session.get();
|
||||
// A callback is a new HTTP request; its bearer token carries the operation's storage scope.
|
||||
return RequestScopes.callAs(execution.accountId(), execution.region(), () -> {
|
||||
List<Map<String, Object>> results = new ArrayList<>();
|
||||
for (JsonNode node : invocations) {
|
||||
results.add(answer(execution, node));
|
||||
}
|
||||
return Response.ok(Map.of("results", results)).build();
|
||||
});
|
||||
}
|
||||
|
||||
private Map<String, Object> answer(ResolverCallbackSessions.Session session, JsonNode node) {
|
||||
|
||||
+16
-3
@@ -38,14 +38,19 @@ public class ResolverCallbackSessions {
|
||||
private final String apiId;
|
||||
private final Object identity;
|
||||
private final String authType;
|
||||
private final String accountId;
|
||||
private final String region;
|
||||
private final List<AppSyncResolverError> appendedErrors = new CopyOnWriteArrayList<>();
|
||||
|
||||
private Session(Map<String, Session> owner, String token, String apiId, Object identity, String authType) {
|
||||
private Session(Map<String, Session> owner, String token, String apiId, Object identity, String authType,
|
||||
String accountId, String region) {
|
||||
this.owner = owner;
|
||||
this.token = token;
|
||||
this.apiId = apiId;
|
||||
this.identity = identity;
|
||||
this.authType = authType;
|
||||
this.accountId = accountId;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public String token() {
|
||||
@@ -64,6 +69,14 @@ public class ResolverCallbackSessions {
|
||||
return authType;
|
||||
}
|
||||
|
||||
public String accountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public String region() {
|
||||
return region;
|
||||
}
|
||||
|
||||
/** Errors from {@code util.appendError}, which are reported beside the data rather than instead of it. */
|
||||
public void appendErrors(List<AppSyncResolverError> errors) {
|
||||
if (errors != null && !errors.isEmpty()) {
|
||||
@@ -81,11 +94,11 @@ public class ResolverCallbackSessions {
|
||||
}
|
||||
}
|
||||
|
||||
public Session open(String apiId, Object identity, String authType) {
|
||||
public Session open(String apiId, Object identity, String authType, String accountId, String region) {
|
||||
byte[] bytes = new byte[TOKEN_BYTES];
|
||||
random.nextBytes(bytes);
|
||||
String token = Base64Url.encode(bytes);
|
||||
Session session = new Session(sessions, token, apiId, identity, authType);
|
||||
Session session = new Session(sessions, token, apiId, identity, authType, accountId, region);
|
||||
sessions.put(token, session);
|
||||
return session;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user