mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(eventbridge): deliver AppSync mutation targets (#7488)
This commit is contained in:
1 parent
50aef92124
commit
ca854a4194
25 files changed
+1406
-39
No files matched your search
+27
@@ -21,6 +21,7 @@ import io.github.hectorvent.floci.services.appsync.graphql.auth.SidecarFieldAuth
|
||||
import io.github.hectorvent.floci.services.appsync.graphql.resolver.AppSyncResolverError;
|
||||
import io.github.hectorvent.floci.services.appsync.graphql.resolver.AppSyncResolverExecutor;
|
||||
import io.github.hectorvent.floci.services.appsync.graphql.resolver.ResolverCallbackSessions;
|
||||
import io.github.hectorvent.floci.services.appsync.model.AuthenticationType;
|
||||
import io.github.hectorvent.floci.services.appsync.model.GraphqlApi;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.POST;
|
||||
@@ -43,6 +44,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* AppSync GraphQL data-plane HTTP endpoint (separate from management {@code AppSyncController}).
|
||||
@@ -167,6 +169,31 @@ public class AppSyncExecutionController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal service delivery, after the adapter has resolved and checked the target role.
|
||||
* Authorization failures reject the complete plan before any mutation can have side effects.
|
||||
*/
|
||||
public Map<String, Object> executeServiceMutation(String apiId, String query, Map<String, Object> variables,
|
||||
AppSyncAuthContext auth, Predicate<PlannedField> permission) {
|
||||
if (auth == null || auth.authenticationType() != AuthenticationType.AWS_IAM
|
||||
|| auth.graphqlApi() == null || !apiId.equals(auth.graphqlApi().getApiId())) {
|
||||
throw new AwsException("AccessDeniedException", "A service mutation requires an IAM identity.", 403);
|
||||
}
|
||||
String sdl = schemaRegistry.getSdl(apiId).orElseThrow(() -> new AppSyncTransportException(
|
||||
502, "GraphQLSchemaException", AppSyncErrorFormatter.MSG_NO_SCHEMA));
|
||||
String preparedSdl = schemaCompiler.withDirectivesAndScalars(sdl);
|
||||
Map<String, String> scalars = schemaCompiler.scalarKindMapping();
|
||||
PlanResult plan = sidecarClient.plan(preparedSdl, scalars, query, null);
|
||||
if (!"MUTATION".equals(plan.operationType())) {
|
||||
throw new AwsException("ValidationException", "An AppSync target requires a mutation operation.", 400);
|
||||
}
|
||||
List<DenyField> denied = fieldAuthorizationPlanner.planDenyFields(plan, auth, permission);
|
||||
if (!denied.isEmpty()) {
|
||||
throw new AwsException("AccessDeniedException", "The target role may not access every selected field.", 403);
|
||||
}
|
||||
return executeQuery(apiId, preparedSdl, scalars, new ParsedRequest(query, variables, null), denied, plan, auth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the query on the sidecar, wiring the resolver callback when any field the query touches
|
||||
* actually has a resolver. Without one, the sidecar resolves every field over a null root value
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ public class AuthMiddleware {
|
||||
identity, authType, authenticationType, deniedFields, api, accessKeyId, info.region(), info.accountId());
|
||||
}
|
||||
|
||||
static Set<AuthenticationType> configuredModes(GraphqlApi api) {
|
||||
public static Set<AuthenticationType> configuredModes(GraphqlApi api) {
|
||||
Set<AuthenticationType> modes = new HashSet<>();
|
||||
if (api.getAuthenticationType() != null) {
|
||||
modes.add(api.getAuthenticationType());
|
||||
|
||||
+1
-1
@@ -324,7 +324,7 @@ public class IamAuthValidator {
|
||||
return appsyncArn(region, accountId, "apis/" + apiId + "/*");
|
||||
}
|
||||
|
||||
static String fieldArn(String region, String accountId, String apiId, String typeName, String fieldName) {
|
||||
public static String fieldArn(String region, String accountId, String apiId, String typeName, String fieldName) {
|
||||
return appsyncArn(region, accountId, "apis/" + apiId + "/types/" + typeName + "/fields/" + fieldName);
|
||||
}
|
||||
|
||||
|
||||
+12
-10
@@ -12,6 +12,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Precomputes which {@code (typeName, fieldName)} coordinates a query must have redacted
|
||||
@@ -34,12 +35,20 @@ public class SidecarFieldAuthorizationPlanner {
|
||||
|
||||
/** Empty when nothing needs redacting (including when {@code auth} carries no API context, same as the live path). */
|
||||
public List<DenyField> planDenyFields(PlanResult plan, AppSyncAuthContext auth) {
|
||||
return planDenyFields(plan, auth, field -> !iamAuthValidator.isFieldDenied(auth.accessKeyId(),
|
||||
IamAuthValidator.fieldArn(auth.region(), auth.accountId(), auth.graphqlApi().getApiId(),
|
||||
field.typeName(), field.fieldName())));
|
||||
}
|
||||
|
||||
/** Service-role calls use the same directive checks with their own IAM principal evaluator. */
|
||||
public List<DenyField> planDenyFields(PlanResult plan, AppSyncAuthContext auth,
|
||||
Predicate<PlannedField> iamPermission) {
|
||||
if (auth == null || auth.graphqlApi() == null) {
|
||||
return List.of();
|
||||
}
|
||||
List<DenyField> denied = new ArrayList<>();
|
||||
for (PlannedField field : plan.fields()) {
|
||||
if (isDenied(field, auth)) {
|
||||
if (isDenied(field, auth, iamPermission)) {
|
||||
denied.add(new DenyField(field.typeName(), field.fieldName(),
|
||||
AppSyncAuth.FIELD_UNAUTHORIZED_TYPE,
|
||||
AppSyncAuth.fieldUnauthorizedMessage(field.fieldName(), field.typeName())));
|
||||
@@ -48,21 +57,14 @@ public class SidecarFieldAuthorizationPlanner {
|
||||
return denied;
|
||||
}
|
||||
|
||||
private boolean isDenied(PlannedField field, AppSyncAuthContext auth) {
|
||||
private boolean isDenied(PlannedField field, AppSyncAuthContext auth, Predicate<PlannedField> iamPermission) {
|
||||
if (isDeniedField(field, auth)) {
|
||||
return true;
|
||||
}
|
||||
if (!modeAllowed(field, auth)) {
|
||||
return true;
|
||||
}
|
||||
if (auth.authenticationType() == AuthenticationType.AWS_IAM) {
|
||||
String fieldArn = IamAuthValidator.fieldArn(
|
||||
auth.region(), auth.accountId(), auth.graphqlApi().getApiId(), field.typeName(), field.fieldName());
|
||||
if (iamAuthValidator.isFieldDenied(auth.accessKeyId(), fieldArn)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return auth.authenticationType() == AuthenticationType.AWS_IAM && !iamPermission.test(field);
|
||||
}
|
||||
|
||||
private boolean isDeniedField(PlannedField field, AppSyncAuthContext auth) {
|
||||
|
||||
+3
@@ -241,6 +241,9 @@ public class AppSyncCfnProvisioner implements CfnResourceProvisioner {
|
||||
r.setPhysicalId(api.getApiId());
|
||||
r.getAttributes().put("ApiId", api.getApiId());
|
||||
r.getAttributes().put("Arn", api.getArn());
|
||||
AwsArnUtils.Arn apiArn = AwsArnUtils.parse(api.getArn());
|
||||
r.getAttributes().put("GraphQLEndpointArn", new AwsArnUtils.Arn(apiArn.partition(), apiArn.service(),
|
||||
apiArn.region(), apiArn.accountId(), "endpoints/graphql-api/" + api.getApiId()).toString());
|
||||
Map<String, String> uris = api.getUris() == null ? Map.of() : api.getUris();
|
||||
String graphqlUrl = uris.get("GRAPHQL");
|
||||
String realtimeUrl = uris.get("REALTIME");
|
||||
|
||||
+5
-1
@@ -231,6 +231,10 @@ public class EventsCfnProvisioner implements CfnResourceProvisioner {
|
||||
target.setBatchParameters(batchParameters);
|
||||
}
|
||||
target.setRoleArn(resolved.path("RoleArn").asText(null));
|
||||
JsonNode appSyncParamsNode = resolved.path("AppSyncParameters");
|
||||
if (appSyncParamsNode.isObject()) {
|
||||
target.setAppSyncParameters(MAPPER.convertValue(appSyncParamsNode, Target.AppSyncParameters.class));
|
||||
}
|
||||
JsonNode ecsParamsNode = resolved.path("EcsParameters");
|
||||
if (ecsParamsNode.isObject()) {
|
||||
target.setEcsParameters(MAPPER.convertValue(
|
||||
@@ -347,7 +351,7 @@ public class EventsCfnProvisioner implements CfnResourceProvisioner {
|
||||
eventBridgeService.removeTargets(ruleName, busName, added, region);
|
||||
}
|
||||
if (!restored.isEmpty()) {
|
||||
eventBridgeService.putTargets(ruleName, busName, restored, region);
|
||||
eventBridgeService.restoreAcceptedTargets(ruleName, busName, restored, region);
|
||||
}
|
||||
resource.getAttributes().remove(CfnRollback.RULE_TARGETS_SNAPSHOT_ATTR);
|
||||
}
|
||||
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
package io.github.hectorvent.floci.services.eventbridge;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.RequestScopes;
|
||||
import io.github.hectorvent.floci.core.common.ServicePrincipals;
|
||||
import io.github.hectorvent.floci.core.common.ServiceRegistry;
|
||||
import io.github.hectorvent.floci.services.appsync.AppSyncService;
|
||||
import io.github.hectorvent.floci.services.appsync.graphql.AppSyncExecutionController;
|
||||
import io.github.hectorvent.floci.services.appsync.graphql.AppSyncTransportException;
|
||||
import io.github.hectorvent.floci.services.appsync.graphql.auth.AppSyncAuth;
|
||||
import io.github.hectorvent.floci.services.appsync.graphql.auth.AppSyncAuthContext;
|
||||
import io.github.hectorvent.floci.services.appsync.graphql.auth.AuthMiddleware;
|
||||
import io.github.hectorvent.floci.services.appsync.graphql.auth.IamAuthValidator;
|
||||
import io.github.hectorvent.floci.services.appsync.graphql.auth.IdentityBuilder;
|
||||
import io.github.hectorvent.floci.services.appsync.model.AuthenticationType;
|
||||
import io.github.hectorvent.floci.services.appsync.model.GraphqlApi;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Target;
|
||||
import io.github.hectorvent.floci.services.iam.ServiceRoleAuthorizer;
|
||||
import io.github.hectorvent.floci.services.iam.ServiceRoleAuthorizer.Permission;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/** Delivers to an AppSync API through its execution engine, never through a caller-supplied URL. */
|
||||
@ApplicationScoped
|
||||
public class AppSyncTargetInvoker {
|
||||
|
||||
private static final String EVENTS = ServicePrincipals.of("events");
|
||||
private final AppSyncService appSync;
|
||||
private final AppSyncExecutionController execution;
|
||||
private final ServiceRoleAuthorizer authorizer;
|
||||
private final ServiceRegistry registry;
|
||||
private final RegionResolver regionResolver;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
@Inject
|
||||
public AppSyncTargetInvoker(AppSyncService appSync, AppSyncExecutionController execution,
|
||||
ServiceRoleAuthorizer authorizer, ServiceRegistry registry,
|
||||
RegionResolver regionResolver, ObjectMapper mapper) {
|
||||
this.appSync = appSync;
|
||||
this.execution = execution;
|
||||
this.authorizer = authorizer;
|
||||
this.registry = registry;
|
||||
this.regionResolver = regionResolver;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public void invoke(Target target, String payload, String ruleArn, String accountId) {
|
||||
if (!registry.isServiceEnabled("appsync")) {
|
||||
throw new AwsException("ServiceNotAvailableException", "Service appsync is not enabled.", 400);
|
||||
}
|
||||
AwsArnUtils.Arn endpoint = endpoint(target.getArn());
|
||||
if (!endpoint.accountId().equals(accountId)) {
|
||||
throw new AwsException("AccessDeniedException", "Cross-account AppSync targets are not supported.", 403);
|
||||
}
|
||||
if (ruleArn != null) {
|
||||
if (!AwsArnUtils.isArn(ruleArn)) {
|
||||
throw new AwsException("AccessDeniedException", "Invalid AppSync target source rule.", 403);
|
||||
}
|
||||
AwsArnUtils.Arn source = AwsArnUtils.parse(ruleArn);
|
||||
if (!endpoint.partition().equals(source.partition()) || !accountId.equals(source.accountId())) {
|
||||
throw new AwsException("AccessDeniedException", "The AppSync target must share the rule's account and partition.", 403);
|
||||
}
|
||||
}
|
||||
Target.AppSyncParameters parameters = target.getAppSyncParameters();
|
||||
String operation = parameters == null ? null : parameters.graphQLOperation();
|
||||
if (operation == null || operation.isBlank() || operation.codePointCount(0, operation.length()) > 1048576) {
|
||||
throw new AwsException("ValidationException", "An AppSync target requires GraphQLOperation of length 1-1048576.", 400);
|
||||
}
|
||||
Map<String, Object> variables = variables(payload);
|
||||
RequestScopes.runAs(accountId, endpoint.region(), () -> {
|
||||
String apiId = endpoint.resource().substring("endpoints/graphql-api/".length());
|
||||
GraphqlApi api = appSync.getGraphqlApi(apiId);
|
||||
String expected = new AwsArnUtils.Arn(endpoint.partition(), "appsync", endpoint.region(), accountId,
|
||||
"apis/" + apiId).toString();
|
||||
if (!expected.equals(api.getArn())) {
|
||||
throw new AwsException("NotFoundException", "GraphQL API not found in the target region.", 404);
|
||||
}
|
||||
boolean iamConfigured = AuthMiddleware.configuredModes(api).contains(AuthenticationType.AWS_IAM);
|
||||
if (!iamConfigured || !"GLOBAL".equals(api.getVisibility())) {
|
||||
throw new AwsException("AccessDeniedException", "AppSync targets require a public API with AWS_IAM authorization.", 403);
|
||||
}
|
||||
authorizer.refusal(target.getRoleArn(), accountId, EVENTS, ruleArn, List.of()).ifPresent(reason -> {
|
||||
throw new AwsException("AccessDeniedException", reason, 403);
|
||||
});
|
||||
String roleName = target.getRoleArn() == null ? null
|
||||
: target.getRoleArn().substring(target.getRoleArn().lastIndexOf('/') + 1);
|
||||
String callerArn = roleName == null ? null : AwsArnUtils.Arn.global(endpoint.partition(), "sts", accountId,
|
||||
"assumed-role/" + roleName + "/EventBridge").toString();
|
||||
AppSyncAuthContext auth = new AppSyncAuthContext(
|
||||
IdentityBuilder.iam(accountId, null, roleName, callerArn, List.of()),
|
||||
AppSyncAuth.AUTH_TYPE_IAM, AuthenticationType.AWS_IAM, Set.of(), api, null, endpoint.region(), accountId);
|
||||
try {
|
||||
Map<String, Object> result = execution.executeServiceMutation(apiId, operation, variables, auth,
|
||||
field -> authorizer.refusal(
|
||||
target.getRoleArn(), accountId, EVENTS, ruleArn, List.of(new Permission("appsync:GraphQL",
|
||||
IamAuthValidator.fieldArn(endpoint.region(), accountId, apiId,
|
||||
field.typeName(), field.fieldName())))).isEmpty());
|
||||
// GraphQL request errors omit data; execution results include it even when null
|
||||
// (spec section 7.1.3). Never retry a returned execution result after partial mutations.
|
||||
if (!result.containsKey("data")) {
|
||||
if (result.get("errors") instanceof List<?> errors && !errors.isEmpty()) {
|
||||
throw new AwsException("ValidationException", "AppSync rejected the mutation before execution.", 400);
|
||||
}
|
||||
throw new AwsException("InternalFailure", "Invalid AppSync execution response.", 502);
|
||||
}
|
||||
} catch (AppSyncTransportException e) {
|
||||
throw new AwsException(e.getErrorType(), e.getMessage(), e.getHttpStatus());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private AwsArnUtils.Arn endpoint(String value) {
|
||||
if (!AwsArnUtils.isArn(value)) {
|
||||
throw new AwsException("ValidationException", "Invalid AppSync GraphQL endpoint ARN.", 400);
|
||||
}
|
||||
AwsArnUtils.Arn arn = AwsArnUtils.parse(value);
|
||||
if (!"appsync".equals(arn.service()) || !arn.accountId().matches("[0-9]{12}")
|
||||
|| !RegionResolver.isKnownRegion(arn.region()) || !regionResolver.partitionForRegion(arn.region()).equals(arn.partition())
|
||||
|| !arn.resource().matches("endpoints/graphql-api/[A-Za-z0-9_-]+")) {
|
||||
throw new AwsException("ValidationException", "Invalid AppSync GraphQL endpoint ARN.", 400);
|
||||
}
|
||||
return arn;
|
||||
}
|
||||
|
||||
private Map<String, Object> variables(String payload) {
|
||||
try {
|
||||
JsonNode node = mapper.readTree(payload);
|
||||
if (node == null || !node.isObject()) {
|
||||
throw new AwsException("ValidationException", "AppSync target input must be a JSON object of variables.", 400);
|
||||
}
|
||||
return mapper.convertValue(node, new TypeReference<Map<String, Object>>() { });
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("ValidationException", "AppSync target input must be valid JSON.", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package io.github.hectorvent.floci.services.eventbridge;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.appsync.GraphqlSidecarClient;
|
||||
import io.github.hectorvent.floci.services.appsync.graphql.AppSyncTransportException;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Target;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/** Checks an endpoint target's document before any targets in the request are stored. */
|
||||
@ApplicationScoped
|
||||
public class AppSyncTargetValidator {
|
||||
|
||||
// Planning parses the document without executing it. A placeholder schema deliberately
|
||||
// avoids requiring an existing API or checking its fields during PutTargets.
|
||||
private static final String SDL = "type Query { _eventBridge: Boolean } type Mutation { _eventBridge: Boolean }";
|
||||
private final GraphqlSidecarClient sidecar;
|
||||
|
||||
@Inject
|
||||
public AppSyncTargetValidator(GraphqlSidecarClient sidecar) {
|
||||
this.sidecar = sidecar;
|
||||
}
|
||||
|
||||
public void validate(Target target) {
|
||||
if (!AwsArnUtils.isArnFor(target.getArn(), "appsync")
|
||||
|| !AwsArnUtils.parse(target.getArn()).resource().startsWith("endpoints/graphql-api/")) {
|
||||
return;
|
||||
}
|
||||
String operation = target.getAppSyncParameters() == null
|
||||
? null : target.getAppSyncParameters().graphQLOperation();
|
||||
if (operation == null) {
|
||||
throw invalidOperation();
|
||||
}
|
||||
try {
|
||||
// No operationName: the sidecar rejects documents with multiple operations.
|
||||
if (!"MUTATION".equals(sidecar.plan(SDL, Map.of(), operation, null).operationType())) {
|
||||
throw invalidOperation();
|
||||
}
|
||||
} catch (AppSyncTransportException e) {
|
||||
if (e.getHttpStatus() == 400) {
|
||||
throw invalidOperation();
|
||||
}
|
||||
throw new AwsException("InternalFailure", "Unable to validate the AppSync target operation.", 500);
|
||||
}
|
||||
}
|
||||
|
||||
private static AwsException invalidOperation() {
|
||||
return new AwsException("ValidationException",
|
||||
"AppSyncParameters.GraphQLOperation must contain exactly one mutation operation.", 400);
|
||||
}
|
||||
}
|
||||
@@ -302,6 +302,10 @@ public class EventBridgeHandler {
|
||||
if (!httpParamsNode.isMissingNode() && httpParamsNode.isObject()) {
|
||||
target.setHttpParameters(objectMapper.convertValue(httpParamsNode, HttpParameters.class));
|
||||
}
|
||||
JsonNode appSyncParamsNode = t.path("AppSyncParameters");
|
||||
if (appSyncParamsNode.isObject()) {
|
||||
target.setAppSyncParameters(objectMapper.convertValue(appSyncParamsNode, Target.AppSyncParameters.class));
|
||||
}
|
||||
targets.add(target);
|
||||
}
|
||||
}
|
||||
@@ -380,6 +384,9 @@ public class EventBridgeHandler {
|
||||
if (t.getHttpParameters() != null) {
|
||||
node.set("HttpParameters", objectMapper.valueToTree(t.getHttpParameters()));
|
||||
}
|
||||
if (t.getAppSyncParameters() != null) {
|
||||
node.set("AppSyncParameters", objectMapper.valueToTree(t.getAppSyncParameters()));
|
||||
}
|
||||
targetsArray.add(node);
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
|
||||
+33
-2
@@ -89,6 +89,7 @@ public class EventBridgeInvoker {
|
||||
private final RedshiftDataService redshiftDataService;
|
||||
private final RedshiftTargetAuthorizer redshiftTargetAuthorizer;
|
||||
private final RedshiftDataTargetSubmitter redshiftSubmitter;
|
||||
private final AppSyncTargetInvoker appSyncTargetInvoker;
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
private final RegionResolver regionResolver;
|
||||
private final ObjectMapper objectMapper;
|
||||
@@ -97,6 +98,19 @@ public class EventBridgeInvoker {
|
||||
private final Map<String, RateWindow> rateWindows = new ConcurrentHashMap<>();
|
||||
|
||||
@Inject
|
||||
public EventBridgeInvoker(LambdaService lambdaService, SqsService sqsService, SnsService snsService,
|
||||
BatchService batchService, FirehoseService firehoseService,
|
||||
EventBridgeService eventBridgeService, EcsService ecsService,
|
||||
EcsJsonHandler ecsJsonHandler, StepFunctionsService stepFunctionsService,
|
||||
RedshiftDataService redshiftDataService, RedshiftTargetAuthorizer redshiftTargetAuthorizer,
|
||||
ServiceRegistry serviceRegistry, RegionResolver regionResolver, ObjectMapper objectMapper,
|
||||
EmulatorConfig config, AppSyncTargetInvoker appSyncTargetInvoker) {
|
||||
this(lambdaService, sqsService, snsService, batchService, firehoseService, eventBridgeService,
|
||||
ecsService, ecsJsonHandler, stepFunctionsService, redshiftDataService, redshiftTargetAuthorizer,
|
||||
serviceRegistry, regionResolver, objectMapper, config,
|
||||
HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build(), appSyncTargetInvoker);
|
||||
}
|
||||
|
||||
public EventBridgeInvoker(LambdaService lambdaService,
|
||||
SqsService sqsService,
|
||||
SnsService snsService,
|
||||
@@ -114,8 +128,7 @@ public class EventBridgeInvoker {
|
||||
EmulatorConfig config) {
|
||||
this(lambdaService, sqsService, snsService, batchService, firehoseService, eventBridgeService,
|
||||
ecsService, ecsJsonHandler, stepFunctionsService, redshiftDataService, redshiftTargetAuthorizer,
|
||||
serviceRegistry, regionResolver, objectMapper, config,
|
||||
HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build());
|
||||
serviceRegistry, regionResolver, objectMapper, config, (AppSyncTargetInvoker) null);
|
||||
}
|
||||
|
||||
EventBridgeInvoker(LambdaService lambdaService,
|
||||
@@ -134,6 +147,18 @@ public class EventBridgeInvoker {
|
||||
ObjectMapper objectMapper,
|
||||
EmulatorConfig config,
|
||||
HttpClient httpClient) {
|
||||
this(lambdaService, sqsService, snsService, batchService, firehoseService, eventBridgeService,
|
||||
ecsService, ecsJsonHandler, stepFunctionsService, redshiftDataService, redshiftTargetAuthorizer,
|
||||
serviceRegistry, regionResolver, objectMapper, config, httpClient, null);
|
||||
}
|
||||
|
||||
private EventBridgeInvoker(LambdaService lambdaService, SqsService sqsService, SnsService snsService,
|
||||
BatchService batchService, FirehoseService firehoseService,
|
||||
EventBridgeService eventBridgeService, EcsService ecsService,
|
||||
EcsJsonHandler ecsJsonHandler, StepFunctionsService stepFunctionsService,
|
||||
RedshiftDataService redshiftDataService, RedshiftTargetAuthorizer redshiftTargetAuthorizer,
|
||||
ServiceRegistry serviceRegistry, RegionResolver regionResolver, ObjectMapper objectMapper,
|
||||
EmulatorConfig config, HttpClient httpClient, AppSyncTargetInvoker appSyncTargetInvoker) {
|
||||
this.lambdaService = lambdaService;
|
||||
this.sqsService = sqsService;
|
||||
this.snsService = snsService;
|
||||
@@ -146,6 +171,7 @@ public class EventBridgeInvoker {
|
||||
this.redshiftDataService = redshiftDataService;
|
||||
this.redshiftTargetAuthorizer = redshiftTargetAuthorizer;
|
||||
this.redshiftSubmitter = new RedshiftDataTargetSubmitter(redshiftDataService, objectMapper);
|
||||
this.appSyncTargetInvoker = appSyncTargetInvoker;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.regionResolver = regionResolver;
|
||||
this.objectMapper = objectMapper;
|
||||
@@ -344,6 +370,11 @@ public class EventBridgeInvoker {
|
||||
}
|
||||
} else if (arn.contains(":events:") && arn.contains(":api-destination/")) {
|
||||
deliverToApiDestination(target, payload, region);
|
||||
} else if (arn.contains(":appsync:")) {
|
||||
if (appSyncTargetInvoker == null) {
|
||||
throw new AwsException("ServiceNotAvailableException", "AppSync delivery is not available.", 400);
|
||||
}
|
||||
appSyncTargetInvoker.invoke(target, payload, ruleArn, regionResolver.getAccountId());
|
||||
} else {
|
||||
LOG.warnv("EventBridge: unsupported target ARN type: {0}", arn);
|
||||
}
|
||||
|
||||
+30
-3
@@ -84,6 +84,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
private final TargetDispatcher dispatcher;
|
||||
private final ResourceGroupsTaggingService resourceGroupsTaggingService;
|
||||
private final ReplayDispatcher replayDispatcher;
|
||||
private final AppSyncTargetValidator appSyncTargetValidator;
|
||||
|
||||
@Inject
|
||||
public EventBridgeService(StorageFactory storageFactory,
|
||||
@@ -93,7 +94,8 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
RuleScheduler ruleScheduler,
|
||||
TargetDispatcher dispatcher,
|
||||
ReplayDispatcher replayDispatcher,
|
||||
ResourceGroupsTaggingService resourceGroupsTaggingService) {
|
||||
ResourceGroupsTaggingService resourceGroupsTaggingService,
|
||||
AppSyncTargetValidator appSyncTargetValidator) {
|
||||
this(
|
||||
storageFactory.create("eventbridge", "eventbridge-buses.json",
|
||||
new TypeReference<Map<String, EventBus>>() {}),
|
||||
@@ -112,7 +114,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
storageFactory.create("eventbridge", "eventbridge-api-destinations.json",
|
||||
new TypeReference<Map<String, ApiDestination>>() {}),
|
||||
regionResolver, objectMapper, ruleScheduler, dispatcher, replayDispatcher,
|
||||
resourceGroupsTaggingService
|
||||
resourceGroupsTaggingService, appSyncTargetValidator
|
||||
);
|
||||
}
|
||||
|
||||
@@ -129,7 +131,8 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
RuleScheduler ruleScheduler,
|
||||
TargetDispatcher dispatcher,
|
||||
ReplayDispatcher replayDispatcher,
|
||||
ResourceGroupsTaggingService resourceGroupsTaggingService) {
|
||||
ResourceGroupsTaggingService resourceGroupsTaggingService,
|
||||
AppSyncTargetValidator appSyncTargetValidator) {
|
||||
this.busStore = busStore;
|
||||
this.ruleStore = ruleStore;
|
||||
this.targetStore = targetStore;
|
||||
@@ -144,6 +147,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
this.dispatcher = dispatcher;
|
||||
this.replayDispatcher = replayDispatcher;
|
||||
this.resourceGroupsTaggingService = resourceGroupsTaggingService;
|
||||
this.appSyncTargetValidator = appSyncTargetValidator;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
@@ -488,6 +492,20 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
|
||||
public int putTargets(String ruleName, String busName, List<Target> newTargets, String region) {
|
||||
validateTargetSettings(newTargets);
|
||||
newTargets.forEach(appSyncTargetValidator::validate);
|
||||
return upsertTargets(ruleName, busName, newTargets, region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal rollback path for previously accepted targets. Local shape checks still apply,
|
||||
* but restoring a snapshot must not depend on the GraphQL sidecar being available.
|
||||
*/
|
||||
public int restoreAcceptedTargets(String ruleName, String busName, List<Target> targets, String region) {
|
||||
validateTargetSettings(targets);
|
||||
return upsertTargets(ruleName, busName, targets, region);
|
||||
}
|
||||
|
||||
private int upsertTargets(String ruleName, String busName, List<Target> newTargets, String region) {
|
||||
String effectiveBus = resolvedBusName(busName);
|
||||
String key = ruleKey(region, effectiveBus, ruleName);
|
||||
Rule rule = ruleStore.get(key)
|
||||
@@ -527,6 +545,15 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
private static void validateTargetSettings(List<Target> targets) {
|
||||
for (int i = 0; i < targets.size(); i++) {
|
||||
Target target = targets.get(i);
|
||||
String operation = target.getAppSyncParameters() == null
|
||||
? null : target.getAppSyncParameters().graphQLOperation();
|
||||
if (operation != null) {
|
||||
String violation = SmithyValidationErrors.Violations.WITHOUT_VALUES.lengthOutOfRange(
|
||||
"targets." + (i + 1) + ".member.appSyncParameters.graphQLOperation", operation, 1, 1048576);
|
||||
if (violation != null) {
|
||||
throw SmithyValidationErrors.validationException(violation);
|
||||
}
|
||||
}
|
||||
Integer attempts = target.getRetryPolicy() != null ? target.getRetryPolicy().maximumRetryAttempts() : null;
|
||||
Integer age = target.getRetryPolicy() != null ? target.getRetryPolicy().maximumEventAgeInSeconds() : null;
|
||||
String arn = target.getDeadLetterConfig() != null ? target.getDeadLetterConfig().arn() : null;
|
||||
|
||||
@@ -22,6 +22,7 @@ public class Target {
|
||||
private RetryPolicy retryPolicy;
|
||||
private DeadLetterConfig deadLetterConfig;
|
||||
private HttpParameters httpParameters;
|
||||
private AppSyncParameters appSyncParameters;
|
||||
|
||||
public Target() {}
|
||||
|
||||
@@ -73,6 +74,14 @@ public class Target {
|
||||
public HttpParameters getHttpParameters() { return httpParameters; }
|
||||
public void setHttpParameters(HttpParameters httpParameters) { this.httpParameters = httpParameters; }
|
||||
|
||||
public AppSyncParameters getAppSyncParameters() { return appSyncParameters; }
|
||||
public void setAppSyncParameters(AppSyncParameters appSyncParameters) { this.appSyncParameters = appSyncParameters; }
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record AppSyncParameters(@JsonProperty("GraphQLOperation") String graphQLOperation) {}
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
|
||||
Reference in new issue
Block a user