mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 14:30:28 -05:00
feat(ses): implement v1 receipt rules with locally validated action targets (#3119)
* feat(ses): implement v1 receipt rules with locally validated action targets Adds the five v1 receipt-rule actions (CreateReceiptRule, DescribeReceiptRule, UpdateReceiptRule, DeleteReceiptRule, SetReceiptRulePosition) on top of the stored-but-inert receipt-rule-set domain. Rules route no mail, but ordering semantics follow real AWS as probed: a rule created without After is inserted at the front, SetReceiptRulePosition without After moves a rule to the front, update replaces the whole rule in place, and rule delete is idempotent while rule-set delete cascades. Action targets are validated against the local emulator the way real SES validates them against the account: any TopicArn must be an existing SNS topic, an S3 BucketName an existing bucket, a Lambda FunctionArn an existing function, and a BounceAction Sender a verified identity, using the probed error codes (InvalidSnsTopic, InvalidS3Configuration, InvalidLambdaFunction, InvalidParameterValue). Smithy-layer validation reproduces the probed member paths and combined violation messages; only the members real SES enforces are required (S3 BucketName, SNS TopicArn, and Stop Scope may be absent). Covered by unit tests with mocked resource services, Query-protocol integration tests, an AWS SDK compatibility test, and Terraform/OpenTofu compat coverage for aws_ses_receipt_rule. * fix(ses): match probed AWS semantics for action-list gaps and present-struct required members Probing triggered by the upstream review corrected two earlier conclusions. A gap in the action list (an empty struct serializes to no Query keys) is not compacted by AWS: the gap is padded into an empty action slot and rejected with InvalidParameterValue "Exactly one action type must be specified for each ReceiptAction", with Smithy paths keeping the wire index. member.0 is rejected outright with MalformedInput "0 is not a valid index". The earlier "optional" verdict for S3Action.BucketName, SNSAction.TopicArn, and StopAction.Scope was an artifact of empty structs never reaching the wire: once an action carries any member, the type's required members are enforced as Smithy violations. BounceAction violations are reported in the probed smtpReplyCode, sender, message order, and SNSAction reports a bad Encoding enum before the missing TopicArn. * fix(ses): honor original receipt-action index spellings and require stop actions last Probing the leading-zero report pinned AWS's index semantics exactly: index tokens are grouped by numeric value, ordered by length then lexicographically, and the i-th token must parse to i, or the padded empty slot is rejected with the exactly-one-action-type error. member.01 alone is therefore a valid slot 1 whose action must be parsed under its original spelling instead of a rebuilt canonical one, while mixed spellings such as member.01 plus member.2 are rejected because the one-digit token sorts first. The same probes surfaced an unrelated service-level rule now reproduced too: a stop action anywhere but the last position is rejected with "Stop action, if any, must be placed at the end of the actions list". * chore(ses): log best-effort compat-test cleanup failures with resource context The three cleanup catches in the receipt-rule compatibility suite swallowed failures silently. They now report the failed step and resource on stderr, the form the other suites in this module already use, so leaked test resources stay diagnosable. * chore(lambda): log functionExists resolution failures at debug level The catch converts a resolution failure into the predicate's negative answer; the debug line keeps a surprising false diagnosable (which reference was rejected, and why) without turning ordinary existence misses on a query path into log noise. * fix(ses): restrict receipt-action index tokens to ASCII digits Character.isDigit also accepts non-ASCII Unicode digits, so a key such as Rule.Actions.member.<fullwidth 1> parsed as a real index. No AWS Query index grammar recognizes those spellings; the key is now skipped like any other unmodeled parameter, pinned by an integration test. --------- Co-authored-by: Priamo <pgermosen@gmail.com>
This commit is contained in:
1 parent
4570bf62c5
commit
fd665a08cc
22 files changed
+2040
-37
No files matched your search
@@ -576,7 +576,9 @@ public class AwsQueryController {
|
||||
"UpdateConfigurationSetReputationMetricsEnabled",
|
||||
"PutConfigurationSetDeliveryOptions",
|
||||
"CreateReceiptRuleSet", "DescribeReceiptRuleSet", "ListReceiptRuleSets",
|
||||
"DeleteReceiptRuleSet", "SetActiveReceiptRuleSet", "DescribeActiveReceiptRuleSet"
|
||||
"DeleteReceiptRuleSet", "SetActiveReceiptRuleSet", "DescribeActiveReceiptRuleSet",
|
||||
"CreateReceiptRule", "DescribeReceiptRule", "UpdateReceiptRule",
|
||||
"DeleteReceiptRule", "SetReceiptRulePosition"
|
||||
);
|
||||
|
||||
private static final Set<String> COGNITO_ACTIONS = Set.of(
|
||||
|
||||
@@ -482,6 +482,22 @@ public class LambdaService implements ResourceProvider {
|
||||
"Function not found: " + functionName, 404));
|
||||
}
|
||||
|
||||
public boolean functionExists(String region, String functionName) {
|
||||
try {
|
||||
// The qualifier-aware read resolves an embedded alias/version and enforces the ARN's
|
||||
// region, so a qualified reference to a nonexistent version does not pass just
|
||||
// because the base function exists.
|
||||
getFunction(region, functionName, null);
|
||||
return true;
|
||||
} catch (AwsException e) {
|
||||
// Covers both a plain miss and a name/ARN the resolver rejects: the exception is
|
||||
// this predicate's negative answer, logged at debug so a surprising false stays
|
||||
// diagnosable without turning ordinary existence misses into log noise.
|
||||
LOG.debugv("functionExists({0}, {1}) is false: {2}", region, functionName, e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a function, honouring a {@code Qualifier} that selects a published version or an alias.
|
||||
*
|
||||
|
||||
@@ -3552,6 +3552,10 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean bucketExists(String bucketName) {
|
||||
return resolveBucket(bucketName).isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a bucket for existence/access. With {@code globalBucketNamespace} enabled, the
|
||||
* lookup spans every account's partition (AWS bucket names are globally unique and reachable
|
||||
|
||||
@@ -16,6 +16,8 @@ import io.github.hectorvent.floci.services.ses.model.EventDestination;
|
||||
import io.github.hectorvent.floci.services.ses.model.Identity;
|
||||
import io.github.hectorvent.floci.services.ses.model.KinesisFirehoseDestination;
|
||||
import io.github.hectorvent.floci.services.ses.model.MessageTag;
|
||||
import io.github.hectorvent.floci.services.ses.model.ReceiptAction;
|
||||
import io.github.hectorvent.floci.services.ses.model.ReceiptRule;
|
||||
import io.github.hectorvent.floci.services.ses.model.ReceiptRuleSet;
|
||||
import io.github.hectorvent.floci.services.ses.model.SnsDestination;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
@@ -27,6 +29,7 @@ import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -129,6 +132,11 @@ public class SesQueryHandler {
|
||||
case "DeleteReceiptRuleSet" -> handleDeleteReceiptRuleSet(params, region);
|
||||
case "SetActiveReceiptRuleSet" -> handleSetActiveReceiptRuleSet(params, region);
|
||||
case "DescribeActiveReceiptRuleSet" -> handleDescribeActiveReceiptRuleSet(region);
|
||||
case "CreateReceiptRule" -> handleCreateReceiptRule(params, region);
|
||||
case "DescribeReceiptRule" -> handleDescribeReceiptRule(params, region);
|
||||
case "UpdateReceiptRule" -> handleUpdateReceiptRule(params, region);
|
||||
case "DeleteReceiptRule" -> handleDeleteReceiptRule(params, region);
|
||||
case "SetReceiptRulePosition" -> handleSetReceiptRulePosition(params, region);
|
||||
default -> AwsQueryResponse.error("UnsupportedOperation",
|
||||
"Operation " + action + " is not supported by SES.", AwsNamespaces.SES, 400);
|
||||
};
|
||||
@@ -978,7 +986,7 @@ public class SesQueryHandler {
|
||||
ReceiptRuleSet ruleSet = sesService.describeReceiptRuleSet(getParam(params, "RuleSetName"), region);
|
||||
XmlBuilder xml = new XmlBuilder();
|
||||
writeReceiptRuleSetMetadata(xml, ruleSet);
|
||||
xml.start("Rules").end("Rules");
|
||||
writeReceiptRules(xml, ruleSet.getRules());
|
||||
return Response.ok(AwsQueryResponse.envelope(
|
||||
"DescribeReceiptRuleSet", AwsNamespaces.SES, xml.build())).build();
|
||||
}
|
||||
@@ -1014,12 +1022,188 @@ public class SesQueryHandler {
|
||||
// When no rule set is active AWS returns an empty result (no Metadata element).
|
||||
if (active != null) {
|
||||
writeReceiptRuleSetMetadata(xml, active);
|
||||
xml.start("Rules").end("Rules");
|
||||
writeReceiptRules(xml, active.getRules());
|
||||
}
|
||||
return Response.ok(AwsQueryResponse.envelope(
|
||||
"DescribeActiveReceiptRuleSet", AwsNamespaces.SES, xml.build())).build();
|
||||
}
|
||||
|
||||
private Response handleCreateReceiptRule(MultivaluedMap<String, String> params, String region) {
|
||||
sesService.createReceiptRule(getParam(params, "RuleSetName"), parseReceiptRule(params),
|
||||
getParam(params, "After"), region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
|
||||
"CreateReceiptRule", AwsNamespaces.SES)).build();
|
||||
}
|
||||
|
||||
private Response handleDescribeReceiptRule(MultivaluedMap<String, String> params, String region) {
|
||||
ReceiptRule rule = sesService.describeReceiptRule(getParam(params, "RuleSetName"),
|
||||
getParam(params, "RuleName"), region);
|
||||
XmlBuilder xml = new XmlBuilder();
|
||||
writeReceiptRule(xml, rule, "Rule");
|
||||
return Response.ok(AwsQueryResponse.envelope(
|
||||
"DescribeReceiptRule", AwsNamespaces.SES, xml.build())).build();
|
||||
}
|
||||
|
||||
private Response handleUpdateReceiptRule(MultivaluedMap<String, String> params, String region) {
|
||||
sesService.updateReceiptRule(getParam(params, "RuleSetName"), parseReceiptRule(params), region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
|
||||
"UpdateReceiptRule", AwsNamespaces.SES)).build();
|
||||
}
|
||||
|
||||
private Response handleDeleteReceiptRule(MultivaluedMap<String, String> params, String region) {
|
||||
sesService.deleteReceiptRule(getParam(params, "RuleSetName"),
|
||||
getParam(params, "RuleName"), region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
|
||||
"DeleteReceiptRule", AwsNamespaces.SES)).build();
|
||||
}
|
||||
|
||||
private Response handleSetReceiptRulePosition(MultivaluedMap<String, String> params, String region) {
|
||||
sesService.setReceiptRulePosition(getParam(params, "RuleSetName"),
|
||||
getParam(params, "RuleName"), getParam(params, "After"), region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
|
||||
"SetReceiptRulePosition", AwsNamespaces.SES)).build();
|
||||
}
|
||||
|
||||
private ReceiptRule parseReceiptRule(MultivaluedMap<String, String> params) {
|
||||
ReceiptRule rule = new ReceiptRule();
|
||||
rule.setName(getParam(params, "Rule.Name"));
|
||||
// Absent booleans stay false, matching the AWS defaults a minimal create gets.
|
||||
rule.setEnabled(parseXsdBoolean(params, "Rule.Enabled"));
|
||||
rule.setScanEnabled(parseXsdBoolean(params, "Rule.ScanEnabled"));
|
||||
rule.setTlsPolicy(getParam(params, "Rule.TlsPolicy"));
|
||||
rule.setRecipients(extractMembers(params, "Rule.Recipients"));
|
||||
// Index tokens are collected from the submitted keys rather than counted up sequentially:
|
||||
// an action serialized as an empty structure contributes no keys at all, so the list can
|
||||
// arrive with gaps (e.g. member.2 only). Probing pinned AWS's exact semantics: tokens are
|
||||
// grouped by numeric value, ordered by (length, then lexicographically), and the i-th
|
||||
// token must parse to i, or the padded empty slot is rejected because it carries no
|
||||
// action type. A leading-zero token such as member.01 is therefore VALID on its own, and
|
||||
// must be parsed under its original spelling rather than a rebuilt canonical one.
|
||||
List<ReceiptAction> actions = new ArrayList<>();
|
||||
int position = 1;
|
||||
for (String token : receiptActionIndexTokens(params)) {
|
||||
if (Integer.parseInt(token) != position) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Exactly one action type must be specified for each ReceiptAction", 400);
|
||||
}
|
||||
ReceiptAction action = parseReceiptAction(params, "Rule.Actions.member." + token + ".");
|
||||
if (action != null) {
|
||||
actions.add(action);
|
||||
position++;
|
||||
}
|
||||
}
|
||||
rule.setActions(actions);
|
||||
return rule;
|
||||
}
|
||||
|
||||
private List<String> receiptActionIndexTokens(MultivaluedMap<String, String> params) {
|
||||
String prefix = "Rule.Actions.member.";
|
||||
Map<Integer, String> byValue = new java.util.HashMap<>();
|
||||
for (String key : params.keySet()) {
|
||||
if (!key.startsWith(prefix)) {
|
||||
continue;
|
||||
}
|
||||
int dot = key.indexOf('.', prefix.length());
|
||||
if (dot < 0) {
|
||||
continue;
|
||||
}
|
||||
String token = key.substring(prefix.length(), dot);
|
||||
// ASCII digits only: Character.isDigit also accepts non-ASCII Unicode digits, which
|
||||
// no AWS Query index grammar does; such a key is skipped like any unmodeled param.
|
||||
if (token.isEmpty() || !token.chars().allMatch(c -> c >= '0' && c <= '9')) {
|
||||
continue;
|
||||
}
|
||||
// A digit run that overflows int implies an index far beyond any contiguous list,
|
||||
// which AWS's gap padding turns into the empty-slot rejection.
|
||||
if (token.length() > 9) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Exactly one action type must be specified for each ReceiptAction", 400);
|
||||
}
|
||||
int value = Integer.parseInt(token);
|
||||
if (value == 0) {
|
||||
// Probed: AWS rejects member.0 outright.
|
||||
throw new AwsException("MalformedInput", "0 is not a valid index", 400);
|
||||
}
|
||||
// Two spellings of the same numeric index keep one struct on AWS too; the probe
|
||||
// showed the padded spelling winning, so prefer the longer token deterministically.
|
||||
String existing = byValue.get(value);
|
||||
if (existing == null || token.length() > existing.length()
|
||||
|| (token.length() == existing.length() && token.compareTo(existing) > 0)) {
|
||||
byValue.put(value, token);
|
||||
}
|
||||
}
|
||||
List<String> tokens = new ArrayList<>(byValue.values());
|
||||
tokens.sort(Comparator.comparingInt(String::length).thenComparing(Comparator.naturalOrder()));
|
||||
return tokens;
|
||||
}
|
||||
|
||||
private ReceiptAction parseReceiptAction(MultivaluedMap<String, String> params, String prefix) {
|
||||
ReceiptAction parsed = null;
|
||||
for (Map.Entry<String, List<String>> type : ReceiptAction.ACTION_FIELDS.entrySet()) {
|
||||
ReceiptAction action = null;
|
||||
for (String field : type.getValue()) {
|
||||
String value = getParam(params, prefix + type.getKey() + "." + field);
|
||||
if (value != null) {
|
||||
if (action == null) {
|
||||
action = new ReceiptAction(type.getKey());
|
||||
}
|
||||
action.getProperties().put(field, value);
|
||||
}
|
||||
}
|
||||
if (action != null) {
|
||||
if (parsed != null) {
|
||||
// Probed: a member carrying two action types is rejected, not truncated.
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Exactly one action type must be specified for each ReceiptAction", 400);
|
||||
}
|
||||
parsed = action;
|
||||
}
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
private void writeReceiptRules(XmlBuilder xml, List<ReceiptRule> rules) {
|
||||
xml.start("Rules");
|
||||
for (ReceiptRule rule : rules) {
|
||||
writeReceiptRule(xml, rule, "member");
|
||||
}
|
||||
xml.end("Rules");
|
||||
}
|
||||
|
||||
private void writeReceiptRule(XmlBuilder xml, ReceiptRule rule, String tag) {
|
||||
xml.start(tag);
|
||||
xml.elem("Name", rule.getName());
|
||||
xml.elem("Enabled", String.valueOf(rule.isEnabled()));
|
||||
xml.elem("TlsPolicy", rule.getTlsPolicy());
|
||||
// AWS omits Recipients entirely when empty but always renders Actions, even as an empty
|
||||
// list; recipients come back sorted regardless of the order they were sent in (probed).
|
||||
if (!rule.getRecipients().isEmpty()) {
|
||||
xml.start("Recipients");
|
||||
rule.getRecipients().stream().sorted().forEach(r -> xml.elem("member", r));
|
||||
xml.end("Recipients");
|
||||
}
|
||||
xml.start("Actions");
|
||||
for (ReceiptAction action : rule.getActions()) {
|
||||
xml.start("member");
|
||||
List<String> fields = action.getType() == null
|
||||
? null : ReceiptAction.ACTION_FIELDS.get(action.getType());
|
||||
if (fields != null) {
|
||||
xml.start(action.getType());
|
||||
for (String field : fields) {
|
||||
String value = action.property(field);
|
||||
if (value != null) {
|
||||
xml.elem(field, value);
|
||||
}
|
||||
}
|
||||
xml.end(action.getType());
|
||||
}
|
||||
xml.end("member");
|
||||
}
|
||||
xml.end("Actions");
|
||||
xml.elem("ScanEnabled", String.valueOf(rule.isScanEnabled()));
|
||||
xml.end(tag);
|
||||
}
|
||||
|
||||
private void writeReceiptRuleSetMetadata(XmlBuilder xml, ReceiptRuleSet ruleSet) {
|
||||
xml.start("Metadata");
|
||||
writeReceiptRuleSetMetadataFields(xml, ruleSet);
|
||||
|
||||
@@ -4,7 +4,12 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaService;
|
||||
import io.github.hectorvent.floci.services.s3.S3Service;
|
||||
import io.github.hectorvent.floci.services.ses.model.ReceiptAction;
|
||||
import io.github.hectorvent.floci.services.ses.model.ReceiptRule;
|
||||
import io.github.hectorvent.floci.services.ses.model.ReceiptRuleSet;
|
||||
import io.github.hectorvent.floci.services.sns.SnsService;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
@@ -15,17 +20,20 @@ import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Owns the SES receipt-rule-set domain (the {@code receiptRuleSetStore}). Extracted from
|
||||
* {@link SesService} as the first step of the store-based domain split: a leaf
|
||||
* domain with no cross-service coupling, reached only through the {@code SesService} facade, which
|
||||
* now delegates its {@code *ReceiptRuleSet*} methods here.
|
||||
* Owns the SES receipt-rule domain (the {@code receiptRuleSetStore}: rule sets and the rules they
|
||||
* hold). Extracted from {@link SesService} in the store-based domain split and reached only through
|
||||
* that facade. Action-target validation couples this domain to {@link S3Service},
|
||||
* {@link SnsService}, and {@link LambdaService}, reproducing the checks real SES runs against the
|
||||
* account; the bounce-sender check arrives as a predicate the facade binds to
|
||||
* {@code SesIdentityService}, keeping identity resolution out of this class's dependencies.
|
||||
*
|
||||
* <p>Floci has no inbound-mail endpoint, so receipt rule sets are stored inertly: a set never holds
|
||||
* any rules and routes no mail. They exist only so the management API round-trips (enough to unblock
|
||||
* tools such as Terraform that declare a rule set during bootstrap).
|
||||
* <p>Floci has no inbound-mail endpoint, so rule sets and rules are stored inertly: stored rules
|
||||
* route no mail and their actions never execute. The management API round-trips (enough to unblock
|
||||
* tools such as Terraform that declare inbound configuration during bootstrap).
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SesReceiptRuleService {
|
||||
@@ -39,22 +47,47 @@ public class SesReceiptRuleService {
|
||||
// start/end with an alphanumeric is a service-level "Not a valid ruleSetName" InvalidParameterValue.
|
||||
// Re-verify against live SES (not the model, which can't confirm it) if these ever need to change.
|
||||
private static final Pattern RULE_SET_NAME_CHARS = Pattern.compile("^[a-zA-Z0-9_.-]+$");
|
||||
private static final int MAX_RULES_PER_SET = 200;
|
||||
private static final int MAX_ACTIONS_PER_RULE = 10;
|
||||
// Probed: a value that is not a well-formed topic/function ARN (a bare name, or an ARN with
|
||||
// missing segments) gets the "Invalid ..." message before any existence lookup. There is no
|
||||
// recipient-count limit (101 recipients are accepted).
|
||||
private static final Pattern SNS_TOPIC_ARN = Pattern.compile("^arn:aws[a-zA-Z-]*:sns:[a-z0-9-]+:\\d{12}:.+$");
|
||||
private static final Pattern LAMBDA_FUNCTION_ARN =
|
||||
Pattern.compile("^arn:aws[a-zA-Z-]*:lambda:[a-z0-9-]+:\\d{12}:function:.+$");
|
||||
// RFC 5322 ftext: printable US-ASCII excluding the colon. Real SES rejects anything else with
|
||||
// "Invalid header name: <name>" (probed 2026-09).
|
||||
private static final Pattern HEADER_NAME_CHARS = Pattern.compile("^[\\x21-\\x39\\x3B-\\x7E]+$");
|
||||
|
||||
private final StorageBackend<String, ReceiptRuleSet> receiptRuleSetStore;
|
||||
// Serializes receipt-rule-set create (check-then-put) and set-active (clear-then-set) so the
|
||||
// one-active-per-region invariant and duplicate-name rejection hold under concurrency.
|
||||
// one-active-per-region invariant and duplicate-name rejection hold under concurrency. Rule
|
||||
// mutations (create/update/delete/set-position, all read-modify-write on the set record) take
|
||||
// the same lock.
|
||||
private final Object receiptRuleSetLock = new Object();
|
||||
private final S3Service s3Service;
|
||||
private final SnsService snsService;
|
||||
private final LambdaService lambdaService;
|
||||
private final Clock clock;
|
||||
|
||||
@Inject
|
||||
public SesReceiptRuleService(StorageFactory storageFactory, Clock clock) {
|
||||
public SesReceiptRuleService(StorageFactory storageFactory, S3Service s3Service,
|
||||
SnsService snsService, LambdaService lambdaService, Clock clock) {
|
||||
this.receiptRuleSetStore = storageFactory.create("ses", "ses-receipt-rule-sets.json",
|
||||
new TypeReference<Map<String, ReceiptRuleSet>>() {});
|
||||
this.s3Service = s3Service;
|
||||
this.snsService = snsService;
|
||||
this.lambdaService = lambdaService;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
SesReceiptRuleService(StorageBackend<String, ReceiptRuleSet> receiptRuleSetStore, Clock clock) {
|
||||
SesReceiptRuleService(StorageBackend<String, ReceiptRuleSet> receiptRuleSetStore,
|
||||
S3Service s3Service, SnsService snsService, LambdaService lambdaService,
|
||||
Clock clock) {
|
||||
this.receiptRuleSetStore = receiptRuleSetStore;
|
||||
this.s3Service = s3Service;
|
||||
this.snsService = snsService;
|
||||
this.lambdaService = lambdaService;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@@ -139,6 +172,384 @@ public class SesReceiptRuleService {
|
||||
}
|
||||
}
|
||||
|
||||
public void createReceiptRule(String ruleSetName, ReceiptRule rule, String after, String region,
|
||||
Predicate<String> verifiedSender) {
|
||||
requireRuleSetName(ruleSetName);
|
||||
List<String> violations = new ArrayList<>();
|
||||
collectRuleNameParamViolations(after, "after", violations);
|
||||
collectRuleShapeViolations(rule, violations);
|
||||
throwViolations(violations);
|
||||
requireValidRuleName(rule.getName());
|
||||
synchronized (receiptRuleSetLock) {
|
||||
ReceiptRuleSet ruleSet = requireRuleSet(ruleSetName, region);
|
||||
List<ReceiptRule> rules = new ArrayList<>(ruleSet.getRules());
|
||||
if (rules.stream().anyMatch(r -> rule.getName().equals(r.getName()))) {
|
||||
throw new AwsException("AlreadyExists", "Rule already exists: " + rule.getName(), 400);
|
||||
}
|
||||
if (rules.size() >= MAX_RULES_PER_SET) {
|
||||
// Probed: the 201st rule in a set is rejected.
|
||||
throw new AwsException("LimitExceeded", "Too many rules", 400);
|
||||
}
|
||||
// AWS inserts at the FRONT when After is absent (probed); After places the rule
|
||||
// immediately behind the named one.
|
||||
int index = after == null ? 0 : indexOfRule(rules, after) + 1;
|
||||
validateActionTargets(rule, region, verifiedSender);
|
||||
applyRuleDefaults(rule);
|
||||
rules.add(index, rule);
|
||||
replaceRules(ruleSet, rules, ruleSetName, region);
|
||||
}
|
||||
LOG.infov("Created SES receipt rule {0} in rule set {1} ({2})", rule.getName(), ruleSetName, region);
|
||||
}
|
||||
|
||||
public ReceiptRule describeReceiptRule(String ruleSetName, String ruleName, String region) {
|
||||
requireRuleSetName(ruleSetName);
|
||||
requireRuleNameParam(ruleName, "ruleName");
|
||||
ReceiptRuleSet ruleSet = requireRuleSet(ruleSetName, region);
|
||||
List<ReceiptRule> rules = ruleSet.getRules();
|
||||
return rules.get(indexOfRule(rules, ruleName));
|
||||
}
|
||||
|
||||
public void updateReceiptRule(String ruleSetName, ReceiptRule rule, String region,
|
||||
Predicate<String> verifiedSender) {
|
||||
requireRuleSetName(ruleSetName);
|
||||
List<String> violations = new ArrayList<>();
|
||||
collectRuleShapeViolations(rule, violations);
|
||||
throwViolations(violations);
|
||||
requireValidRuleName(rule.getName());
|
||||
synchronized (receiptRuleSetLock) {
|
||||
ReceiptRuleSet ruleSet = requireRuleSet(ruleSetName, region);
|
||||
List<ReceiptRule> rules = new ArrayList<>(ruleSet.getRules());
|
||||
// AWS replaces the whole rule in place (omitted members reset to their defaults) and
|
||||
// keeps its position; an unknown name is an error, so update cannot rename.
|
||||
int index = indexOfRule(rules, rule.getName());
|
||||
validateActionTargets(rule, region, verifiedSender);
|
||||
applyRuleDefaults(rule);
|
||||
rules.set(index, rule);
|
||||
replaceRules(ruleSet, rules, ruleSetName, region);
|
||||
}
|
||||
LOG.infov("Updated SES receipt rule {0} in rule set {1} ({2})", rule.getName(), ruleSetName, region);
|
||||
}
|
||||
|
||||
public void deleteReceiptRule(String ruleSetName, String ruleName, String region) {
|
||||
requireRuleSetName(ruleSetName);
|
||||
requireRuleNameParam(ruleName, "ruleName");
|
||||
synchronized (receiptRuleSetLock) {
|
||||
// The rule set must exist, but deleting an absent rule is idempotent (probed).
|
||||
ReceiptRuleSet ruleSet = requireRuleSet(ruleSetName, region);
|
||||
List<ReceiptRule> rules = new ArrayList<>(ruleSet.getRules());
|
||||
if (rules.removeIf(r -> ruleName.equals(r.getName()))) {
|
||||
replaceRules(ruleSet, rules, ruleSetName, region);
|
||||
}
|
||||
}
|
||||
LOG.infov("Deleted SES receipt rule {0} from rule set {1} ({2})", ruleName, ruleSetName, region);
|
||||
}
|
||||
|
||||
public void setReceiptRulePosition(String ruleSetName, String ruleName, String after, String region) {
|
||||
requireRuleSetName(ruleSetName);
|
||||
requireRuleNamePresent(ruleName);
|
||||
List<String> violations = new ArrayList<>();
|
||||
collectRuleNameParamViolations(ruleName, "ruleName", violations);
|
||||
collectRuleNameParamViolations(after, "after", violations);
|
||||
throwViolations(violations);
|
||||
requireValidRuleName(ruleName);
|
||||
synchronized (receiptRuleSetLock) {
|
||||
ReceiptRuleSet ruleSet = requireRuleSet(ruleSetName, region);
|
||||
List<ReceiptRule> rules = new ArrayList<>(ruleSet.getRules());
|
||||
int index = indexOfRule(rules, ruleName);
|
||||
if (ruleName.equals(after)) {
|
||||
// AWS answers 200 for a rule positioned after itself (probed); nothing moves.
|
||||
return;
|
||||
}
|
||||
if (after != null) {
|
||||
indexOfRule(rules, after);
|
||||
}
|
||||
ReceiptRule moved = rules.remove(index);
|
||||
int target = after == null ? 0 : indexOfRule(rules, after) + 1;
|
||||
rules.add(target, moved);
|
||||
replaceRules(ruleSet, rules, ruleSetName, region);
|
||||
}
|
||||
LOG.infov("Positioned SES receipt rule {0} in rule set {1} ({2})", ruleName, ruleSetName, region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Swaps in a freshly built rules list and persists the set. Mutations never touch the list a
|
||||
* previously returned rule set holds: the storage backends hand out live object references, so
|
||||
* a describe caller may still be iterating the old list after the lock is released.
|
||||
*/
|
||||
private void replaceRules(ReceiptRuleSet ruleSet, List<ReceiptRule> rules,
|
||||
String ruleSetName, String region) {
|
||||
ruleSet.setRules(rules);
|
||||
receiptRuleSetStore.put(receiptRuleSetKey(region, ruleSetName), ruleSet);
|
||||
}
|
||||
|
||||
private ReceiptRuleSet requireRuleSet(String name, String region) {
|
||||
return receiptRuleSetStore.get(receiptRuleSetKey(region, name))
|
||||
.orElseThrow(() -> ruleSetDoesNotExist(name));
|
||||
}
|
||||
|
||||
private static int indexOfRule(List<ReceiptRule> rules, String name) {
|
||||
for (int i = 0; i < rules.size(); i++) {
|
||||
if (name.equals(rules.get(i).getName())) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
throw new AwsException("RuleDoesNotExist", "Rule does not exist: " + name, 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Smithy-model layer of rule validation, reproduced from probing real SES: violations
|
||||
* across the rule name, TlsPolicy, and every action member collect into one
|
||||
* {@code ValidationError} ("N validation errors detected: ...; ..."). A type's required
|
||||
* members are enforced whenever the action carries any member at all; an action struct with
|
||||
* no members never reaches this layer, because it serializes to no Query keys and AWS then
|
||||
* rejects the padded empty slot in the parser (probed).
|
||||
*/
|
||||
private static void collectRuleShapeViolations(ReceiptRule rule, List<String> violations) {
|
||||
String name = rule.getName();
|
||||
if (name == null || name.isEmpty()) {
|
||||
violations.add(lengthViolation("rule.name"));
|
||||
violations.add(patternViolation("rule.name"));
|
||||
} else if (!RULE_SET_NAME_CHARS.matcher(name).matches()) {
|
||||
violations.add(patternViolation("rule.name"));
|
||||
}
|
||||
if (rule.getTlsPolicy() != null && !"Optional".equals(rule.getTlsPolicy())
|
||||
&& !"Require".equals(rule.getTlsPolicy())) {
|
||||
violations.add(enumViolation("rule.tlsPolicy", "[Optional, Require]"));
|
||||
}
|
||||
int i = 1;
|
||||
for (ReceiptAction action : rule.getActions()) {
|
||||
String prefix = "rule.actions." + i + ".member.";
|
||||
if (action.is("AddHeaderAction")) {
|
||||
requireMember(violations, action, "HeaderName", prefix + "addHeaderAction.headerName");
|
||||
requireMember(violations, action, "HeaderValue", prefix + "addHeaderAction.headerValue");
|
||||
} else if (action.is("BounceAction")) {
|
||||
// Probed order: smtpReplyCode, then sender, then message.
|
||||
requireMember(violations, action, "SmtpReplyCode", prefix + "bounceAction.smtpReplyCode");
|
||||
requireMember(violations, action, "Sender", prefix + "bounceAction.sender");
|
||||
requireMember(violations, action, "Message", prefix + "bounceAction.message");
|
||||
} else if (action.is("ConnectAction")) {
|
||||
requireMember(violations, action, "InstanceARN", prefix + "connectAction.instanceARN");
|
||||
requireMember(violations, action, "IAMRoleARN", prefix + "connectAction.iAMRoleARN");
|
||||
} else if (action.is("WorkmailAction")) {
|
||||
requireMember(violations, action, "OrganizationArn", prefix + "workmailAction.organizationArn");
|
||||
} else if (action.is("LambdaAction")) {
|
||||
requireMember(violations, action, "FunctionArn", prefix + "lambdaAction.functionArn");
|
||||
if (invalidEnum(action, "InvocationType", "RequestResponse", "Event")) {
|
||||
violations.add(enumViolation(prefix + "lambdaAction.invocationType",
|
||||
"[RequestResponse, Event]"));
|
||||
}
|
||||
} else if (action.is("SNSAction")) {
|
||||
// Probed order: the encoding enum violation is reported before the missing topic.
|
||||
if (invalidEnum(action, "Encoding", "Base64", "UTF-8")) {
|
||||
violations.add(enumViolation(prefix + "sNSAction.encoding", "[Base64, UTF-8]"));
|
||||
}
|
||||
requireMember(violations, action, "TopicArn", prefix + "sNSAction.topicArn");
|
||||
} else if (action.is("S3Action")) {
|
||||
requireMember(violations, action, "BucketName", prefix + "s3Action.bucketName");
|
||||
} else if (action.is("StopAction")) {
|
||||
requireMember(violations, action, "Scope", prefix + "stopAction.scope");
|
||||
if (invalidEnum(action, "Scope", "RuleSet")) {
|
||||
violations.add(enumViolation(prefix + "stopAction.scope", "[RuleSet]"));
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private static void throwViolations(List<String> violations) {
|
||||
if (violations.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String label = violations.size() == 1 ? "1 validation error detected: "
|
||||
: violations.size() + " validation errors detected: ";
|
||||
throw new AwsException("ValidationError", label + String.join("; ", violations), 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Smithy-layer checks for the top-level RuleName and After parameters, which real SES
|
||||
* validates with the same length and pattern constraints as Rule.Name but under their own
|
||||
* wire member paths ('ruleName' / 'after', probed on describe, delete, set-position, and
|
||||
* the create After parameter). An absent parameter is left to the caller.
|
||||
*/
|
||||
private static void collectRuleNameParamViolations(String value, String path, List<String> violations) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
if (value.isEmpty()) {
|
||||
violations.add(lengthViolation(path));
|
||||
violations.add(patternViolation(path));
|
||||
} else if (!RULE_SET_NAME_CHARS.matcher(value).matches()) {
|
||||
violations.add(patternViolation(path));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Full validation of a required top-level RuleName parameter: presence, then the Smithy
|
||||
* layers, then the service-level "Not a valid ruleName" boundary check (probed on
|
||||
* describe and delete).
|
||||
*/
|
||||
private static void requireRuleNameParam(String ruleName, String path) {
|
||||
requireRuleNamePresent(ruleName);
|
||||
List<String> violations = new ArrayList<>();
|
||||
collectRuleNameParamViolations(ruleName, path, violations);
|
||||
throwViolations(violations);
|
||||
requireValidRuleName(ruleName);
|
||||
}
|
||||
|
||||
private static void requireMember(List<String> violations, ReceiptAction action,
|
||||
String member, String path) {
|
||||
if (action.property(member) == null) {
|
||||
violations.add("Value at '" + path + "' failed to satisfy constraint: "
|
||||
+ "Member must not be null");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean invalidEnum(ReceiptAction action, String member, String... allowed) {
|
||||
String value = action.property(member);
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
for (String candidate : allowed) {
|
||||
if (candidate.equals(value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String patternViolation(String path) {
|
||||
return "Value at '" + path + "' failed to satisfy constraint: "
|
||||
+ "Member must satisfy regular expression pattern: ^[a-zA-Z0-9_.-]+$";
|
||||
}
|
||||
|
||||
private static String lengthViolation(String path) {
|
||||
return "Value at '" + path + "' failed to satisfy constraint: "
|
||||
+ "Member must have length greater than or equal to 1";
|
||||
}
|
||||
|
||||
private static String enumViolation(String path, String valueSet) {
|
||||
return "Value at '" + path + "' failed to satisfy constraint: "
|
||||
+ "Member must satisfy enum value set: " + valueSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates every resource an action points at against the local emulator, reproducing the
|
||||
* checks real SES runs on create/update: any TopicArn must be a publishable SNS topic, an
|
||||
* S3 bucket must exist, a Lambda function must be invokable, and a bounce sender must be a
|
||||
* verified identity. Each check fires only when its member is present, matching AWS.
|
||||
*/
|
||||
private void validateActionTargets(ReceiptRule rule, String region, Predicate<String> verifiedSender) {
|
||||
if (rule.getActions().size() > MAX_ACTIONS_PER_RULE) {
|
||||
// Probed: the 11th action is rejected at the service layer, like the rules-per-set cap.
|
||||
throw new AwsException("LimitExceeded", "Too many actions", 400);
|
||||
}
|
||||
for (int i = 0; i < rule.getActions().size() - 1; i++) {
|
||||
// Probed: a stop action anywhere but the last position is rejected.
|
||||
if (rule.getActions().get(i).is("StopAction")) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Stop action, if any, must be placed at the end of the actions list", 400);
|
||||
}
|
||||
}
|
||||
for (ReceiptAction action : rule.getActions()) {
|
||||
String headerName = action.property("HeaderName");
|
||||
if (action.is("AddHeaderAction") && headerName != null
|
||||
&& !HEADER_NAME_CHARS.matcher(headerName).matches()) {
|
||||
throw new AwsException("InvalidParameterValue", "Invalid header name: " + headerName, 400);
|
||||
}
|
||||
// Empty members get their own service-level messages before the existence checks
|
||||
// (probed: they never reach the "no such resource" family).
|
||||
String topicArn = action.property("TopicArn");
|
||||
if (topicArn != null) {
|
||||
// The shape check covers the probed empty-string case too (same message).
|
||||
if (!SNS_TOPIC_ARN.matcher(topicArn).matches()) {
|
||||
throw new AwsException("InvalidSnsTopic", "Invalid SNS topic: " + topicArn, 400);
|
||||
}
|
||||
if (!snsService.topicExists(topicArn, region)) {
|
||||
throw new AwsException("InvalidSnsTopic",
|
||||
"Could not publish to SNS topic: " + topicArn, 400);
|
||||
}
|
||||
}
|
||||
String bucketName = action.property("BucketName");
|
||||
if (action.is("S3Action") && bucketName != null) {
|
||||
if (bucketName.isEmpty()) {
|
||||
throw new AwsException("InvalidParameterValue", "Bucket name must not be empty", 400);
|
||||
}
|
||||
if (!s3Service.bucketExists(bucketName)) {
|
||||
throw new AwsException("InvalidS3Configuration", "No such bucket: " + bucketName, 400);
|
||||
}
|
||||
}
|
||||
String functionArn = action.property("FunctionArn");
|
||||
if (action.is("LambdaAction") && functionArn != null) {
|
||||
if (functionArn.isEmpty()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Lambda function ARN must not be empty", 400);
|
||||
}
|
||||
// A bare function name or malformed ARN gets its own message before the
|
||||
// existence lookup (probed), so a same-named local function cannot make a
|
||||
// non-ARN value pass.
|
||||
if (!LAMBDA_FUNCTION_ARN.matcher(functionArn).matches()) {
|
||||
throw new AwsException("InvalidLambdaFunction",
|
||||
"Invalid Lambda function: " + functionArn, 400);
|
||||
}
|
||||
if (!lambdaService.functionExists(region, functionArn)) {
|
||||
throw new AwsException("InvalidLambdaFunction",
|
||||
"Could not invoke Lambda function: " + functionArn, 400);
|
||||
}
|
||||
}
|
||||
if (action.is("BounceAction")) {
|
||||
String smtpReplyCode = action.property("SmtpReplyCode");
|
||||
if (smtpReplyCode != null && smtpReplyCode.isEmpty()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid SMTP reply code: " + smtpReplyCode, 400);
|
||||
}
|
||||
String message = action.property("Message");
|
||||
if (message != null && message.isEmpty()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid SMTP response message: " + message, 400);
|
||||
}
|
||||
String sender = action.property("Sender");
|
||||
if (sender != null && !verifiedSender.test(sender)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Identity is not verified: " + sender, 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyRuleDefaults(ReceiptRule rule) {
|
||||
if (rule.getTlsPolicy() == null) {
|
||||
rule.setTlsPolicy("Optional");
|
||||
}
|
||||
for (ReceiptAction action : rule.getActions()) {
|
||||
// AWS fills in the SNS encoding default on the stored rule (probed: UTF-8 comes back
|
||||
// from Describe without ever being sent).
|
||||
if (action.is("SNSAction") && action.property("TopicArn") != null
|
||||
&& action.property("Encoding") == null) {
|
||||
action.getProperties().put("Encoding", "UTF-8");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireRuleNamePresent(String ruleName) {
|
||||
// Only an ABSENT parameter takes this error; a supplied empty or whitespace-only value
|
||||
// falls through to the Smithy length/pattern violations probed under the 'ruleName' path.
|
||||
if (ruleName == null) {
|
||||
throw new AwsException("InvalidParameterValue", "RuleName is required.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The service-level rule name check that runs after the Smithy pattern passes, mirroring
|
||||
* {@link #requireRuleSetName}: too long or not alphanumeric at both ends.
|
||||
*/
|
||||
private static void requireValidRuleName(String name) {
|
||||
if (name.length() > 64
|
||||
|| !Character.isLetterOrDigit(name.charAt(0))
|
||||
|| !Character.isLetterOrDigit(name.charAt(name.length() - 1))) {
|
||||
throw new AwsException("InvalidParameterValue", "Not a valid ruleName: " + name, 400);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearActiveReceiptRuleSet(String region) {
|
||||
String prefix = "receiptRuleSet::" + region + "::";
|
||||
for (ReceiptRuleSet rs : receiptRuleSetStore.scan(k -> k.startsWith(prefix))) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.github.hectorvent.floci.services.ses.model.Identity;
|
||||
import io.github.hectorvent.floci.services.ses.model.ListManagementOptions;
|
||||
import io.github.hectorvent.floci.services.ses.model.MessageHeader;
|
||||
import io.github.hectorvent.floci.services.ses.model.MessageTag;
|
||||
import io.github.hectorvent.floci.services.ses.model.ReceiptRule;
|
||||
import io.github.hectorvent.floci.services.ses.model.ReceiptRuleSet;
|
||||
import io.github.hectorvent.floci.services.ses.model.Topic;
|
||||
import io.github.hectorvent.floci.services.ses.model.TopicPreference;
|
||||
@@ -1282,6 +1283,31 @@ public class SesService {
|
||||
return receiptRuleService.describeActiveReceiptRuleSet(region);
|
||||
}
|
||||
|
||||
// The bounce-sender check needs identity state; the rule domain receives it as a predicate
|
||||
// bound here, keeping SesIdentityService out of its constructor surface.
|
||||
|
||||
public void createReceiptRule(String ruleSetName, ReceiptRule rule, String after, String region) {
|
||||
receiptRuleService.createReceiptRule(ruleSetName, rule, after, region,
|
||||
sender -> identityService.isVerifiedSender(sender, region));
|
||||
}
|
||||
|
||||
public ReceiptRule describeReceiptRule(String ruleSetName, String ruleName, String region) {
|
||||
return receiptRuleService.describeReceiptRule(ruleSetName, ruleName, region);
|
||||
}
|
||||
|
||||
public void updateReceiptRule(String ruleSetName, ReceiptRule rule, String region) {
|
||||
receiptRuleService.updateReceiptRule(ruleSetName, rule, region,
|
||||
sender -> identityService.isVerifiedSender(sender, region));
|
||||
}
|
||||
|
||||
public void deleteReceiptRule(String ruleSetName, String ruleName, String region) {
|
||||
receiptRuleService.deleteReceiptRule(ruleSetName, ruleName, region);
|
||||
}
|
||||
|
||||
public void setReceiptRulePosition(String ruleSetName, String ruleName, String after, String region) {
|
||||
receiptRuleService.setReceiptRulePosition(ruleSetName, ruleName, after, region);
|
||||
}
|
||||
|
||||
// ──────────────────────── Dedicated IP Pools ────────────────────────
|
||||
|
||||
// Storage lives in SesDedicatedIpService; the facade forwards.
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package io.github.hectorvent.floci.services.ses.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* One action inside a receipt rule, stored as its wire type name plus the members that were
|
||||
* actually provided. SES renders only the members a caller set (verified against real AWS:
|
||||
* an S3Action created with just BucketName and ObjectKeyPrefix describes back exactly those
|
||||
* two members), so a typed class per action would have to model absent-vs-set anyway; a
|
||||
* single ordered property map keeps parse, storage, and render symmetric.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class ReceiptAction {
|
||||
|
||||
/**
|
||||
* Wire member order per action type, used both to parse the Query request and to render
|
||||
* the Describe XML. A rule may also carry a completely empty action member with no type
|
||||
* at all; real SES accepts and stores it, so {@link #type} may be null.
|
||||
*
|
||||
* <p>WorkmailAction is kept for wire compatibility only: Amazon WorkMail reaches end of
|
||||
* support on 2027-03-31, so the action gets storage and round-trip (matching real SES, which
|
||||
* accepts even a fabricated organization ARN) but will never get resource validation or
|
||||
* execution behavior.
|
||||
*/
|
||||
public static final Map<String, List<String>> ACTION_FIELDS = Map.of(
|
||||
"AddHeaderAction", List.of("HeaderName", "HeaderValue"),
|
||||
"BounceAction", List.of("TopicArn", "SmtpReplyCode", "StatusCode", "Message", "Sender"),
|
||||
"ConnectAction", List.of("InstanceARN", "IAMRoleARN"),
|
||||
"LambdaAction", List.of("TopicArn", "FunctionArn", "InvocationType"),
|
||||
"S3Action", List.of("TopicArn", "BucketName", "ObjectKeyPrefix", "KmsKeyArn", "IamRoleArn"),
|
||||
"SNSAction", List.of("TopicArn", "Encoding"),
|
||||
"StopAction", List.of("Scope", "TopicArn"),
|
||||
"WorkmailAction", List.of("TopicArn", "OrganizationArn"));
|
||||
|
||||
@JsonProperty("Type")
|
||||
private String type;
|
||||
|
||||
@JsonProperty("Properties")
|
||||
private Map<String, String> properties = new LinkedHashMap<>();
|
||||
|
||||
public ReceiptAction() {
|
||||
}
|
||||
|
||||
public ReceiptAction(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
if (properties == null) {
|
||||
properties = new LinkedHashMap<>();
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(Map<String, String> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public String property(String name) {
|
||||
return getProperties().get(name);
|
||||
}
|
||||
|
||||
public boolean is(String actionType) {
|
||||
return actionType.equals(type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package io.github.hectorvent.floci.services.ses.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class ReceiptRule {
|
||||
|
||||
@JsonProperty("Name")
|
||||
private String name;
|
||||
|
||||
@JsonProperty("Enabled")
|
||||
private boolean enabled;
|
||||
|
||||
@JsonProperty("TlsPolicy")
|
||||
private String tlsPolicy;
|
||||
|
||||
@JsonProperty("Recipients")
|
||||
private List<String> recipients = new ArrayList<>();
|
||||
|
||||
@JsonProperty("ScanEnabled")
|
||||
private boolean scanEnabled;
|
||||
|
||||
@JsonProperty("Actions")
|
||||
private List<ReceiptAction> actions = new ArrayList<>();
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getTlsPolicy() {
|
||||
return tlsPolicy;
|
||||
}
|
||||
|
||||
public void setTlsPolicy(String tlsPolicy) {
|
||||
this.tlsPolicy = tlsPolicy;
|
||||
}
|
||||
|
||||
public List<String> getRecipients() {
|
||||
if (recipients == null) {
|
||||
recipients = new ArrayList<>();
|
||||
}
|
||||
return recipients;
|
||||
}
|
||||
|
||||
public void setRecipients(List<String> recipients) {
|
||||
this.recipients = recipients;
|
||||
}
|
||||
|
||||
public boolean isScanEnabled() {
|
||||
return scanEnabled;
|
||||
}
|
||||
|
||||
public void setScanEnabled(boolean scanEnabled) {
|
||||
this.scanEnabled = scanEnabled;
|
||||
}
|
||||
|
||||
public List<ReceiptAction> getActions() {
|
||||
if (actions == null) {
|
||||
actions = new ArrayList<>();
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
public void setActions(List<ReceiptAction> actions) {
|
||||
this.actions = actions;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,14 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A SES v1 receipt rule set. Floci stores it inertly: there is no inbound-mail endpoint, so a rule
|
||||
* set never holds any receipt rules and performs no mail routing. It exists only so the management
|
||||
* API (create / describe / list / delete and set/describe active) round-trips, which is enough to
|
||||
* unblock tools like Terraform that declare a rule set during bootstrap.
|
||||
* A SES v1 receipt rule set. Floci stores it inertly: there is no inbound-mail endpoint, so the
|
||||
* receipt rules a set holds route no mail. The management API (rule set and rule CRUD, rule
|
||||
* positioning, set/describe active) round-trips, which is enough to unblock tools like Terraform
|
||||
* that declare receipt rules during bootstrap.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@@ -27,6 +29,9 @@ public class ReceiptRuleSet {
|
||||
@JsonProperty("Active")
|
||||
private boolean active;
|
||||
|
||||
@JsonProperty("Rules")
|
||||
private List<ReceiptRule> rules = new ArrayList<>();
|
||||
|
||||
public ReceiptRuleSet() {
|
||||
}
|
||||
|
||||
@@ -58,4 +63,15 @@ public class ReceiptRuleSet {
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public List<ReceiptRule> getRules() {
|
||||
if (rules == null) {
|
||||
rules = new ArrayList<>();
|
||||
}
|
||||
return rules;
|
||||
}
|
||||
|
||||
public void setRules(List<ReceiptRule> rules) {
|
||||
this.rules = rules;
|
||||
}
|
||||
}
|
||||
@@ -223,6 +223,10 @@ public class SnsService implements Resettable, ResourceProvider {
|
||||
return topicStore.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
|
||||
public boolean topicExists(String topicArn, String region) {
|
||||
return topicStore.get(topicKey(region, topicArn)).isPresent();
|
||||
}
|
||||
|
||||
public Map<String, String> getTopicAttributes(String topicArn, String region) {
|
||||
String key = topicKey(region, topicArn);
|
||||
Topic topic = topicStore.get(key)
|
||||
|
||||
Reference in new issue
Block a user