Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(iam): check PutEvents on each entry's event bus (#6704)

Priamo Germosen0410a2b4eaed
diff --git a/.github/workflows/iam-data-drift.yml b/.github/workflows/iam-data-drift.yml
index 20130c6a20..4af040ba4f 100644
--- a/.github/workflows/iam-data-drift.yml
+++ b/.github/workflows/iam-data-drift.yml
@@ -14,7 +14,10 @@ name: IAM Data Drift
#
# - On a pull request that touches a vendored file or its generator, which is where a
# hand-typed or mistyped entry would enter the repository. A pull request that does not touch
-# them cannot introduce one, so it does not run and cannot be failed by an outage.
+# them cannot introduce one, so it does not run and cannot be failed by an outage. For the same
+# reason, one that does checks only the files it touches, each with its generator and the
+# modules that generator imports (the paths in the Makefile, above iam-data-verify): drift in a
+# file it leaves alone is not its doing, and the weekly run reports it.
# - Weekly, because the files also go stale without anyone touching them: AWS ships services
# and actions, and occasionally retires them. Tying the only upstream check to pull request
# activity would mean a quiet month is a month with no drift detection at all.
@@ -72,6 +75,10 @@ jobs:
timeout-minutes: 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ # A pull request's merge commit and its first parent, the base branch, so the step below
+ # can tell which files the pull request changes.
+ fetch-depth: 2
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
@@ -80,5 +87,15 @@ jobs:
# No dependency install: the generators are deliberately stdlib-only, and this job runs no
# tests. The pinned botocore the sibling workflow needs is for the partition generator.
- - name: Check every vendored IAM file still matches upstream
- run: make iam-data-verify
+ #
+ # A pull request checks the files it changes; the weekly and manual runs check every file. A
+ # diff that cannot be read leaves CHANGED empty, which checks every file too.
+ - name: Check the vendored IAM files still match upstream
+ env:
+ EVENT_NAME: ${{ github.event_name }}
+ run: |
+ if [ "$EVENT_NAME" = pull_request ]; then
+ make iam-data-verify CHANGED="$(git diff --name-only HEAD^1 HEAD | tr '\n' ' ')"
+ else
+ make iam-data-verify
+ fi
diff --git a/Makefile b/Makefile
index 24b4ee8efc..31ab382573 100644
--- a/Makefile
+++ b/Makefile
@@ -397,17 +397,55 @@ iam-action-resources-verify: ## CI gate (online): every vendored IAM action reso
exit 1; \
fi
-iam-data-verify: ## CI gate (online): every vendored IAM file must still match AWS
- @# Both halves run even when the first fails, so one file's drift cannot hide the other's
+# The paths each upstream check covers: its vendored file, its tests, its generator and every
+# module that generator imports. Given CHANGED, the paths a pull request changes, iam-data-verify
+# runs only the checks covering one of them, so a pull request is not failed by drift in a file it
+# leaves alone; without it, as on the weekly run, it runs every check.
+IAM_PASSED_ROLES_GENERATOR := tools/aws/regen_iam_passed_roles.py tools/aws/regen_iam_authorized_actions.py \
+ tools/aws/regen_partitions.py tools/aws/regen_query_services.py
+IAM_NAMESPACES_PATHS := src/main/resources/aws/iam-service-namespaces.json \
+ tools/aws/regen_service_namespaces.py tools/aws/test_regen_service_namespaces.py
+IAM_ACTION_RESOURCES_PATHS := src/main/resources/aws/iam-action-resources.json \
+ tools/aws/regen_iam_action_resources.py tools/aws/test_regen_iam_action_resources.py
+IAM_AUTHORIZED_ACTIONS_PATHS := src/main/resources/aws/iam-authorized-actions.json \
+ tools/aws/regen_iam_authorized_actions.py tools/aws/test_regen_iam_authorized_actions.py
+IAM_PASSED_ROLES_PATHS := src/main/resources/aws/iam-passed-roles.json $(IAM_PASSED_ROLES_GENERATOR) \
+ tools/aws/test_regen_iam_passed_roles.py
+IAM_TAG_ON_CREATE_PATHS := src/main/resources/aws/iam-tag-on-create.json tools/aws/regen_iam_tag_on_create.py \
+ $(IAM_PASSED_ROLES_GENERATOR) tools/aws/test_regen_iam_tag_on_create.py
+IAM_REQUEST_RESOURCES_PATHS := src/main/resources/aws/iam-request-resources.json \
+ tools/aws/regen_iam_request_resources.py $(IAM_PASSED_ROLES_GENERATOR) \
+ tools/aws/test_regen_iam_request_resources.py
+
+iam-data-verify: ## CI gate (online): every vendored IAM file must still match AWS; CHANGED="<paths>" checks only the ones they cover
+ @# Every check runs even when an earlier one fails, so one file's drift cannot hide another's
@# state. Sequential steps in CI stop at the first failure, which once left the action
@# resource gate unexercised while the namespace list was stale.
@namespaces=0; actions=0; authorized=0; passed=0; tagged=0; requested=0; \
- $(MAKE) --no-print-directory iam-namespaces-verify || namespaces=$$?; \
- $(MAKE) --no-print-directory iam-action-resources-verify || actions=$$?; \
- $(MAKE) --no-print-directory iam-authorized-actions-verify || authorized=$$?; \
- $(MAKE) --no-print-directory iam-passed-roles-verify || passed=$$?; \
- $(MAKE) --no-print-directory iam-tag-on-create-verify || tagged=$$?; \
- $(MAKE) --no-print-directory iam-request-resources-verify || requested=$$?; \
+ covers() { \
+ [ -z "$(strip $(CHANGED))" ] && return 0; \
+ for path in $(CHANGED); do case " $$1 " in *" $$path "*) return 0;; esac; done; \
+ echo "not checked, as the change touches none of its files: $$2"; \
+ return 1; \
+ }; \
+ if covers "$(IAM_NAMESPACES_PATHS)" "the service namespace list"; then \
+ $(MAKE) --no-print-directory iam-namespaces-verify || namespaces=$$?; \
+ fi; \
+ if covers "$(IAM_ACTION_RESOURCES_PATHS)" "the action resource map"; then \
+ $(MAKE) --no-print-directory iam-action-resources-verify || actions=$$?; \
+ fi; \
+ if covers "$(IAM_AUTHORIZED_ACTIONS_PATHS)" "the map of operations to their IAM actions"; then \
+ $(MAKE) --no-print-directory iam-authorized-actions-verify || authorized=$$?; \
+ fi; \
+ if covers "$(IAM_PASSED_ROLES_PATHS)" "the table of the roles operations pass"; then \
+ $(MAKE) --no-print-directory iam-passed-roles-verify || passed=$$?; \
+ fi; \
+ if covers "$(IAM_TAG_ON_CREATE_PATHS)" "the table of the tagging actions creates need"; then \
+ $(MAKE) --no-print-directory iam-tag-on-create-verify || tagged=$$?; \
+ fi; \
+ if covers "$(IAM_REQUEST_RESOURCES_PATHS)" "the table of the resources requests name"; then \
+ $(MAKE) --no-print-directory iam-request-resources-verify || requested=$$?; \
+ fi; \
if [ $$namespaces -ne 0 ] || [ $$actions -ne 0 ] || [ $$authorized -ne 0 ] || [ $$passed -ne 0 ] \
|| [ $$tagged -ne 0 ] || [ $$requested -ne 0 ]; then \
echo ""; \
diff --git a/docs/services/iam.md b/docs/services/iam.md
index fe06cfd7f6..86b30de879 100644
--- a/docs/services/iam.md
+++ b/docs/services/iam.md
@@ -1490,7 +1490,10 @@ its request's `EventBusName` names, by name or by ARN, and on the default bus wh
or gives a null, whose rules are `rule/<name>`, with no bus; a bus ARN of another account, the
default bus's included, names that account's rule, checked as given and as the caller's own, which
Floci acts on, and one leaving its account and Region empty names the caller's. `DescribeEventBus`
-naming no bus is checked on `event-bus/default`. A connection or an API destination, whose ARN
+naming no bus is checked on `event-bus/default`. `PutEvents` is checked on the bus of every entry,
+the one its `EventBusName` names, by name or by ARN, or the default bus for an entry naming none,
+so one entry for a bus the caller may not publish to refuses the whole request, as the EventBridge
+User Guide gives it for every entry. A connection or an API destination, whose ARN
EventBridge follows with an id it mints after the name, `connection/<name>/<id>`, is checked on
the ARN it is stored under when the request names it, and on `connection/<name>/*` when there is
none yet, as for its create. EventBridge V2's API, which Floci does not serve, is not read. A
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/RequestResourceMembers.java b/src/main/java/io/github/hectorvent/floci/core/common/RequestResourceMembers.java
index 46422a0f1f..0f03321381 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/RequestResourceMembers.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/RequestResourceMembers.java
@@ -34,6 +34,8 @@ final class RequestResourceMembers {
private static final Pattern MEMBER = Pattern.compile("[A-Za-z][A-Za-z0-9_]*(\\[])?");
/** A member holding an ARN may also be one level inside a structure or each of a list's structures. */
private static final Pattern ARN_MEMBER = Pattern.compile("[A-Za-z][A-Za-z0-9_]*(\\[])?(\\.[A-Za-z][A-Za-z0-9_]*(\\[])?)?");
+ /** A member filling a variable may also be a field of each of a list's structures, one value for each. */
+ private static final Pattern FILL_MEMBER = Pattern.compile("[A-Za-z][A-Za-z0-9_]*(\\[]|\\[]\\.[A-Za-z][A-Za-z0-9_]*)?");
/** An ARN format's leading resource type word, and the rest of its resource. */
private static final Pattern RESOURCE_PART = Pattern.compile(
"^arn:\\$\\{Partition}:[^:]*:[^:]*:[^:]*:([A-Za-z][A-Za-z0-9-]*)(.*)$");
@@ -51,6 +53,16 @@ final class RequestResourceMembers {
Member(String name, boolean list) {
this(name, list, null);
}
+
+ /** As the file writes it: {@code Name}, {@code Name[]}, {@code Name.Field} or {@code Name[].Field}. */
+ String path() {
+ return name + (list ? "[]" : "") + (field == null ? "" : "." + field.path());
+ }
+
+ /** Whether it is a field of each of a list's structures, which gives one value for each of them. */
+ boolean eachElement() {
+ return list && field != null && !field.list();
+ }
}
/**
@@ -98,8 +110,12 @@ final class RequestResourceMembers {
* the request's. A member {@code absent} from the request, or given a JSON null, is read as the value given for
* it (an EventBridge request naming no event bus names {@code default}), and one in {@code arnOf} may give an
* ARN of the type named for it instead of its name, read as that type's one variable, the resource then in the
- * ARN's account and Region, or the caller's and the request's where the ARN leaves them empty. An ARN
- * member's value is read up to the character {@code before}, when there is one, as its handler drops the rest.
+ * ARN's account and Region, or the caller's and the request's where the ARN leaves them empty. A member filling
+ * a variable may be a field of each of a list's structures ({@code Entries[].EventBusName}), which names one
+ * resource for each structure, read as {@code absent} gives for one that lacks it and in the account and Region
+ * of the ARN that structure gives, if any. Such a member is in {@code absent} or {@code arnOf} only when it
+ * fills a variable. An ARN member's value is read up to the character {@code before}, when there is one, as its
+ * handler drops the rest.
*/
record Resource(List<String> types, Member arn, Map<String, Member> fill, Map<String, List<String>> when,
Map<String, List<String>> unless, Map<String, String> absent, Map<String, String> arnOf,
@@ -233,7 +249,7 @@ final class RequestResourceMembers {
throw new IllegalStateException(RESOURCE_NAME + " fills " + variable.getKey() + " for " + operation
+ ", no variable of " + type + "'s format");
}
- fill.put(variable.getKey(), member(operation, variable.getValue().asText("")));
+ fill.put(variable.getKey(), fillMember(operation, variable.getValue().asText("")));
});
if (fill.values().stream().filter(Member::list).count() > 1) {
throw new IllegalStateException(RESOURCE_NAME + " fills " + type + " for " + operation
@@ -241,9 +257,10 @@ final class RequestResourceMembers {
}
Map<String, List<String>> when = values(operation, type, resource.path("when"));
Map<String, List<String>> unless = values(operation, type, resource.path("unless"));
+ Set<String> filled = Set.copyOf(fill.values().stream().map(Member::path).toList());
Map<String, String> absent = new LinkedHashMap<>();
resource.path("absent").properties().forEach(member -> {
- if (member(operation, member.getKey()).list() || !member.getValue().isTextual()
+ if (!readAsOne(operation, member.getKey(), filled) || !member.getValue().isTextual()
|| member.getValue().asText().isEmpty()) {
throw new IllegalStateException(RESOURCE_NAME + " reads " + member.getKey() + " for " + operation
+ " when absent as no value");
@@ -253,7 +270,7 @@ final class RequestResourceMembers {
Map<String, String> arnOf = new LinkedHashMap<>();
resource.path("arnOf").properties().forEach(member -> {
ArnFormat named = formats.get(member.getValue().asText(""));
- if (member(operation, member.getKey()).list() || named == null
+ if (!readAsOne(operation, member.getKey(), filled) || named == null
|| !ONE_VARIABLE.matcher(named.format().split(":", 6)[5]).matches()) {
throw new IllegalStateException(RESOURCE_NAME + " reads " + member.getKey() + " for " + operation
+ " as an ARN of " + member.getValue() + ", no type named by one variable");
@@ -306,6 +323,26 @@ final class RequestResourceMembers {
return path.endsWith("[]") ? new Member(path.substring(0, path.length() - 2), true) : new Member(path, false);
}
+ /**
+ * A member filling a variable: {@code Name}, {@code Name[]}, or a field of each of a list's structures,
+ * {@code Name[].Field}.
+ */
+ private static Member fillMember(String operation, String path) {
+ if (!FILL_MEMBER.matcher(path).matches()) {
+ throw new IllegalStateException(RESOURCE_NAME + " reads " + operation + " at " + path + ", which is no member");
+ }
+ return arnMember(operation, path);
+ }
+
+ /**
+ * Whether a member gives one value as it is read: a top-level one that is no list, or a field of each of a
+ * list's structures that fills a variable, one value for each structure.
+ */
+ private static boolean readAsOne(String operation, String path, Set<String> filled) {
+ return FILL_MEMBER.matcher(path).matches() && path.contains("[].") ? filled.contains(path)
+ : !member(operation, path).list();
+ }
+
/** A member holding an ARN: {@code Name}, {@code Name[]}, or a field of it, {@code Name.Field} or {@code Name[].Field}. */
private static Member arnMember(String operation, String path) {
if (!ARN_MEMBER.matcher(path).matches()) {
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/RequestResources.java b/src/main/java/io/github/hectorvent/floci/core/common/RequestResources.java
index 595f3ef8b0..a3cf056e26 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/RequestResources.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/RequestResources.java
@@ -5,6 +5,7 @@ import jakarta.ws.rs.container.ContainerRequestContext;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -34,6 +35,16 @@ public final class RequestResources {
private static final Pattern VARIABLE = Pattern.compile("\\$\\{(\\w+)}");
private static final Pattern ACCOUNT_ID = Pattern.compile("\\d{12}");
+ /** Values for a type's variables, and the ARN whose account and Region the resource they name is in, if any. */
+ private record Filling(Map<String, String> variables, AwsArnUtils.Arn from) {
+
+ Filling with(String variable, String value, AwsArnUtils.Arn arn) {
+ Map<String, String> more = new HashMap<>(variables);
+ more.put(variable, value);
+ return new Filling(more, from == null ? arn : from);
+ }
+ }
+
private RequestResources() {
}
@@ -151,23 +162,34 @@ public final class RequestResources {
}
/**
- * The values a request gives a member as the resource reads them: the one it reads for the member absent or
- * given a JSON null, as a handler reading it with {@code asText(null)} does (EventBridge's {@code EventBusName}),
- * and, for a member that may give an ARN of a type instead of its name, that type's one variable of such an ARN.
+ * The values a request gives a member as the resource reads them, as {@link #read} gives them, and, for a member
+ * that may give an ARN of a type instead of its name, that type's one variable of such an ARN.
*/
private static List<String> given(RequestResourceMembers.Resource resource, Map<String, String> form,
JsonNode body, RequestResourceMembers.Member member,
Map<String, RequestResourceMembers.ArnFormat> formats) {
- String absent = resource.absent().get(member.name());
- List<String> values = absent != null && isNull(body, member) ? List.of() : values(form, body, member);
- if (values.isEmpty() && absent != null) {
- return List.of(absent);
- }
- RequestResourceMembers.ArnFormat named = arnOf(resource, member.name(), formats);
+ RequestResourceMembers.ArnFormat named = arnOf(resource, member.path(), formats);
+ List<String> values = read(resource, form, body, member);
return named == null ? values : values.stream()
.map(value -> named.pattern().matcher(value).matches() ? named.variable(value) : value).toList();
}
+ /**
+ * The values a request gives a member: the one the resource reads for the member absent or given a JSON null,
+ * as a handler reading it with {@code asText(null)} does (EventBridge's {@code EventBusName}), and, for a field
+ * of each of a list's structures, one for each structure, that one for a structure lacking it (a
+ * {@code PutEvents} entry naming no event bus is published to the default one), none for no structures.
+ */
+ private static List<String> read(RequestResourceMembers.Resource resource, Map<String, String> form,
+ JsonNode body, RequestResourceMembers.Member member) {
+ String absent = resource.absent().get(member.path());
+ if (absent != null && member.eachElement()) {
+ return eachElement(form, body, member, absent);
+ }
+ List<String> values = absent != null && isNull(body, member) ? List.of() : values(form, body, member);
+ return values.isEmpty() && absent != null ? List.of(absent) : values;
+ }
+
/** The format of the type whose ARN a member of the resource may give instead of its name; null for none. */
private static RequestResourceMembers.ArnFormat arnOf(RequestResourceMembers.Resource resource, String member,
Map<String, RequestResourceMembers.ArnFormat> formats) {
@@ -176,12 +198,19 @@ public final class RequestResources {
}
/**
- * The ARN a request gives for a name in a member of the resource that may give one, which puts the resource in
- * that ARN's account and Region (a rule on the event bus it names, the default one included); null for none.
+ * The ARN a request gives for a name in a member of the resource that may give one and fills none of its
+ * variables, which puts the resource in that ARN's account and Region (a rule on the default event bus of the
+ * account the bus's ARN names); null for none. A member filling a variable puts each resource it names in the
+ * account and Region of the ARN it gives for it, as {@link #fill} reads it.
*/
private static AwsArnUtils.Arn arnGiven(RequestResourceMembers.Resource resource, Map<String, String> form,
JsonNode body, Map<String, RequestResourceMembers.ArnFormat> formats) {
+ Set<String> filled = new HashSet<>();
+ resource.fill().values().forEach(member -> filled.add(member.path()));
for (String member : resource.arnOf().keySet()) {
+ if (filled.contains(member)) {
+ continue;
+ }
RequestResourceMembers.ArnFormat named = arnOf(resource, member, formats);
for (String value : values(form, body, new RequestResourceMembers.Member(member, false))) {
if (named.pattern().matcher(value).matches()) {
@@ -204,7 +233,9 @@ public final class RequestResources {
* the account the resource's account member gives, which its handler acts in, and none when that member holds
* no account id; in the request's without one, or with a JSON null for it. An ARN given for a name puts the
* resource in that ARN's account and Region, the caller's and the request's where it leaves them empty, as its
- * handler then acts on the caller's resource of that name, and it is named as an ARN the request gives is. A type
+ * handler then acts on the caller's resource of that name, and it is named as an ARN the request gives is; for
+ * a member naming one resource for each of a list's structures, each in the account and Region of the ARN its
+ * structure gives, the request's for a name (a {@code PutEvents} entry, on the bus it names). A type
* whose service mints an id after its name is the caller's resource {@code stored} finds under that name, or
* else has that id open.
*/
@@ -221,44 +252,52 @@ public final class RequestResources {
}
account = given.isEmpty() ? accountId : given.getFirst();
}
- AwsArnUtils.Arn from = arnGiven(resource, form, body, formats);
- List<Map<String, String>> fillings = new ArrayList<>(List.of(Map.of()));
+ AwsArnUtils.Arn fromRequest = arnGiven(resource, form, body, formats);
+ List<Filling> fillings = new ArrayList<>(List.of(new Filling(Map.of(), fromRequest)));
for (Map.Entry<String, RequestResourceMembers.Member> variable : resource.fill().entrySet()) {
- List<String> values = given(resource, form, body, variable.getValue(), formats);
+ List<String> values = read(resource, form, body, variable.getValue());
if (values.isEmpty()) {
continue;
}
- if (resource.fill().size() == 1 && from == null
- && values.stream().allMatch(value -> format.pattern().matcher(value).matches())) {
+ RequestResourceMembers.ArnFormat named = arnOf(resource, variable.getValue().path(), formats);
+ if (resource.fill().size() == 1 && fromRequest == null && values.stream().allMatch(value ->
+ !isArnOf(named, value) && format.pattern().matcher(value).matches())) {
values.forEach(value -> addNamed(arns, format.checked(value), partition, region, accountId));
return;
}
- List<Map<String, String>> next = new ArrayList<>();
- for (Map<String, String> filling : fillings) {
+ List<Filling> next = new ArrayList<>();
+ for (Filling filling : fillings) {
for (String value : values) {
- Map<String, String> more = new HashMap<>(filling);
- more.put(variable.getKey(), value);
- next.add(more);
+ next.add(isArnOf(named, value)
+ ? filling.with(variable.getKey(), named.variable(value), AwsArnUtils.parse(value))
+ : filling.with(variable.getKey(), value, null));
}
}
fillings = next;
}
- if (!resource.fill().isEmpty() && fillings.getFirst().isEmpty()) {
+ if (!resource.fill().isEmpty() && fillings.getFirst().variables().isEmpty()) {
return;
}
- for (Map<String, String> filling : fillings) {
+ for (Filling filling : fillings) {
+ AwsArnUtils.Arn from = filling.from();
if (from == null) {
- arns.add(withId(render(format.format(), filling, partition, region, account), format,
- resource.types().getFirst(), filling, account.equals(accountId) ? stored : null, region));
+ arns.add(withId(render(format.format(), filling.variables(), partition, region, account), format,
+ resource.types().getFirst(), filling.variables(), account.equals(accountId) ? stored : null,
+ region));
} else {
- addNamed(arns, withId(render(format.format(), filling, from.partition(),
+ addNamed(arns, withId(render(format.format(), filling.variables(), from.partition(),
from.region().isEmpty() ? region : from.region(),
from.accountId().isEmpty() ? accountId : from.accountId()), format,
- resource.types().getFirst(), filling, null, region), partition, region, accountId);
+ resource.types().getFirst(), filling.variables(), null, region), partition, region, accountId);
}
}
}
+ /** Whether a member that may give an ARN of a type instead of its name gives one. */
+ private static boolean isArnOf(RequestResourceMembers.ArnFormat named, String value) {
+ return named != null && named.pattern().matcher(value).matches();
+ }
+
/**
* The ARN of a resource of a type whose service follows its name with an id it mints: the one {@code stored}
* finds the caller's resource of that name under in the Region, or else the ARN with that id open; any other
@@ -339,6 +378,39 @@ public final class RequestResources {
return values;
}
+ /**
+ * The value of a field of each of a list's structures, {@code absent} for one that gives none or a JSON null, as
+ * a handler reading it with {@code asText(null)} does: a body's list, or a form's list numbered from 1 to the
+ * first structure it gives nothing of; none for no list.
+ */
+ private static List<String> eachElement(Map<String, String> form, JsonNode body,
+ RequestResourceMembers.Member member, String absent) {
+ List<String> values = new ArrayList<>();
+ if (!form.isEmpty()) {
+ String key = member.name() + ".member.";
+ for (int i = 1; hasElement(form, key + i + "."); i++) {
+ List<String> found = new ArrayList<>();
+ add(found, form.get(key + i + "." + member.field().name()));
+ values.add(found.isEmpty() ? absent : found.getFirst());
+ }
+ } else if (body != null && body.isObject() && body.path(member.name()).isArray()) {
+ for (JsonNode element : body.path(member.name())) {
+ List<String> found = new ArrayList<>();
+ JsonNode value = element.path(member.field().name());
+ if (!value.isNull()) {
+ addValue(found, value);
+ }
+ values.add(found.isEmpty() ? absent : found.getFirst());
+ }
+ }
+ return values;
+ }
+
+ /** Whether a form gives anything of a list's structure under {@code prefix}. */
+ private static boolean hasElement(Map<String, String> form, String prefix) {
+ return form.keySet().stream().anyMatch(key -> key.startsWith(prefix));
+ }
+
/**
* A form's values of a member under {@code prefix}: each element of a list from 1 to the first that does not
* give the member, or its field, as a handler loops over them.
diff --git a/src/main/resources/aws/iam-request-resources.json b/src/main/resources/aws/iam-request-resources.json
index 56b99329f8..e909a9e949 100644
--- a/src/main/resources/aws/iam-request-resources.json
+++ b/src/main/resources/aws/iam-request-resources.json
@@ -1,5 +1,5 @@
{
- "_source": {"generator": "tools/aws/regen_iam_request_resources.py", "reference": "https://servicereference.us-east-1.amazonaws.com/", "botocore": "botocore 1.43.113 (installed package)", "retrieved": "2026-10-25", "note": "make iam-request-resources-check re-derives every operation's resources from botocore; make iam-request-resources-verify checks every action, type and format against AWS."},
+ "_source": {"generator": "tools/aws/regen_iam_request_resources.py", "reference": "https://servicereference.us-east-1.amazonaws.com/", "botocore": "botocore 1.43.113 (installed package)", "retrieved": "2026-10-26", "note": "make iam-request-resources-check re-derives every operation's resources from botocore; make iam-request-resources-verify checks every action, type and format against AWS."},
"namespaces": {"cognito-idp": ["cognito-idp"], "ecr": ["ecr"], "elasticloadbalancing": ["elb", "elbv2"], "events": ["events"], "states": ["stepfunctions"]},
"clientsNotRead": {"eventbridgev2": "EventBridge V2, the AWSEventsV2 target over Smithy RPC v2 CBOR on the eventsv2 endpoint, which Floci does not serve; its operations share EventBridge's names and name their resources by other members"},
"handBuilt": ["dsql", "dynamodb", "eks", "iam", "kinesis", "kms", "lambda", "logs", "pipes", "resource-groups", "s3", "scheduler", "secretsmanager", "sns", "sqs", "ssm", "sts"],
@@ -320,7 +320,7 @@
"events:ListSubscribers": {"action": "events:ListSubscribers", "types": [], "resources": []},
"events:ListTagsForResource": {"action": "events:ListTagsForResource", "types": ["event-bus", "event-busv2", "event-sourcev2", "rule-on-custom-event-bus", "rule-on-default-event-bus", "subscriber"], "resources": [{"types": ["event-bus", "event-busv2", "event-sourcev2", "rule-on-custom-event-bus", "rule-on-default-event-bus", "subscriber"], "arn": "ResourceARN"}]},
"events:ListTargetsByRule": {"action": "events:ListTargetsByRule", "types": ["rule-on-custom-event-bus", "rule-on-default-event-bus"], "resources": [{"type": "rule-on-default-event-bus", "fill": {"RuleName": "Rule"}, "when": {"EventBusName": ["default"]}, "absent": {"EventBusName": "default"}, "arnOf": {"EventBusName": "event-bus"}}, {"type": "rule-on-custom-event-bus", "fill": {"EventBusName": "EventBusName", "RuleName": "Rule"}, "unless": {"EventBusName": ["default"]}, "absent": {"EventBusName": "default"}, "arnOf": {"EventBusName": "event-bus"}}]},
- "events:PutEvents": {"action": "events:PutEvents", "types": ["event-bus", "event-busv2"], "resources": []},
+ "events:PutEvents": {"action": "events:PutEvents", "types": ["event-bus", "event-busv2"], "resources": [{"type": "event-bus", "fill": {"EventBusName": "Entries[].EventBusName"}, "absent": {"Entries[].EventBusName": "default"}, "arnOf": {"Entries[].EventBusName": "event-bus"}}]},
"events:PutPartnerEvents": {"action": "events:PutPartnerEvents", "types": [], "resources": []},
"events:PutPermission": {"action": "events:PutPermission", "types": [], "resources": []},
"events:PutRawEvents": {"action": "events:PutRawEvents", "types": ["event-busv2"], "resources": []},
diff --git a/src/test/java/io/github/hectorvent/floci/core/common/RequestResourceMembersTest.java b/src/test/java/io/github/hectorvent/floci/core/common/RequestResourceMembersTest.java
index 9d694e369d..159a462951 100644
--- a/src/test/java/io/github/hectorvent/floci/core/common/RequestResourceMembersTest.java
+++ b/src/test/java/io/github/hectorvent/floci/core/common/RequestResourceMembersTest.java
@@ -100,10 +100,25 @@ class RequestResourceMembersTest {
+ "{\"resources\":[],\"creates\":[{\"type\":\"part\",\"parent\":\"thing\",\"arn\":\"ThingArn\"}]}}}"),
part);
}
- // A member past one structure, or a structure's member filling a variable.
+ // A member past one structure, or filling a variable from a lone structure's member or a list in a list.
assertThrows(IllegalStateException.class, () -> parse(document(formats, "{\"types\":[\"thing\"],\"arn\":\"A[].B.ThingArn\"}")));
- assertThrows(IllegalStateException.class, () -> parse(document(formats,
- "{\"type\":\"thing\",\"fill\":{\"ThingName\":\"A[].Name\"}}")));
+ for (String bad : List.of("A.Name", "A[].Names[]", "A[].B.Name")) {
+ assertThrows(IllegalStateException.class, () -> parse(document(formats,
+ "{\"type\":\"thing\",\"fill\":{\"ThingName\":\"" + bad + "\"}}")), bad);
+ }
+ // A field of each of a list's structures fills a variable, read as given when absent or as an ARN, which
+ // only a member filling a variable is.
+ Member each = new Member("A", true, new Member("Name", false));
+ assertEquals(List.of(new Resource(List.of("thing"), null, Map.of("ThingName", each), Map.of(), Map.of(),
+ Map.of("A[].Name", "default"), Map.of("A[].Name", "thing"), null, null)),
+ parseUnchecked(document(formats, "{\"type\":\"thing\",\"fill\":{\"ThingName\":\"A[].Name\"},"
+ + "\"absent\":{\"A[].Name\":\"default\"},\"arnOf\":{\"A[].Name\":\"thing\"}}"))
+ .operations().get("a:Op"));
+ assertEquals("A[].Name", each.path());
+ for (String bad : List.of("\"absent\":{\"A[].Name\":\"default\"}", "\"arnOf\":{\"A[].Name\":\"thing\"}")) {
+ assertThrows(IllegalStateException.class, () -> parse(document(formats,
+ "{\"type\":\"thing\",\"fill\":{\"ThingName\":\"Name\"}," + bad + "}")), bad);
+ }
assertEquals(List.of(new Resource(List.of("thing"), new Member("A", true, new Member("ThingArns", true)), Map.of(),
Map.of(), Map.of(), Map.of(), Map.of(), null, null)), parseUnchecked(document(formats, "{\"types\":[\"thing\"],\"arn\":\"A[].ThingArns[]\"}"))
.operations().get("a:Op"));
diff --git a/src/test/java/io/github/hectorvent/floci/core/common/RequestResourcesTest.java b/src/test/java/io/github/hectorvent/floci/core/common/RequestResourcesTest.java
index d93e27d8a9..b6199ee8da 100644
--- a/src/test/java/io/github/hectorvent/floci/core/common/RequestResourcesTest.java
+++ b/src/test/java/io/github/hectorvent/floci/core/common/RequestResourcesTest.java
@@ -292,6 +292,38 @@ class RequestResourcesTest {
assertEquals(List.of(events + "event-bus/default"), of("events:DescribeEventBus", json("{\"Name\":null}")));
}
+ /**
+ * Each {@code PutEvents} entry is published to the event bus it names, by name or ARN, in the account and Region
+ * that ARN gives, or to the default one when it names none, gives a null or a blank; a request publishing nothing
+ * names no bus.
+ */
+ @Test
+ void eachEntryIsOnTheEventBusItNames() {
+ String events = "arn:aws:events:us-east-1:000000000000:";
+ assertEquals(List.of(events + "event-bus/orders", events + "event-bus/default", events + "event-bus/audit"),
+ of("events:PutEvents", json("{\"Entries\":[{\"EventBusName\":\"orders\"},{\"Source\":\"s\"},"
+ + "{\"EventBusName\":\"audit\"},{\"EventBusName\":\"orders\"}]}")));
+ assertEquals(List.of(events + "event-bus/default"), of("events:PutEvents",
+ json("{\"Entries\":[{\"EventBusName\":null},{\"EventBusName\":\"\"},{\"EventBusName\":\" \"}]}")));
+ // Each ARN puts its entry's bus in its own account and Region, checked as the caller's too.
+ assertEquals(List.of("arn:aws:events:eu-west-1:111122223333:event-bus/orders",
+ "arn:aws:events:us-east-1:111122223333:event-bus/orders",
+ "arn:aws:events:eu-west-1:000000000000:event-bus/orders", events + "event-bus/orders",
+ events + "event-bus/audit", "arn:aws:events:us-east-1:444455556666:event-bus/billing",
+ events + "event-bus/billing"), of("events:PutEvents", json("{\"Entries\":["
+ + "{\"EventBusName\":\"arn:aws:events:eu-west-1:111122223333:event-bus/orders\"},"
+ + "{\"EventBusName\":\"audit\"},"
+ + "{\"EventBusName\":\"arn:aws:events:us-east-1:444455556666:event-bus/billing\"}]}")));
+ assertEquals(List.of(events + "event-bus/orders"), of("events:PutEvents",
+ json("{\"Entries\":[{\"EventBusName\":\"arn:aws:events:::event-bus/orders\"}]}")));
+ assertEquals(List.of(), of("events:PutEvents", json("{\"Entries\":[]}")));
+ assertEquals(List.of(), of("events:PutEvents", json("{}")));
+ // A form's entries run from 1 to the first it gives nothing of.
+ assertEquals(List.of(events + "event-bus/orders", events + "event-bus/default"), of("events:PutEvents",
+ form("Action=PutEvents&Entries.member.1.EventBusName=orders&Entries.member.2.Source=s"
+ + "&Entries.member.4.EventBusName=late")));
+ }
+
/**
* A connection or an API destination, whose ARN EventBridge follows with an id it mints after the name, is the
* one stored under the name the request gives, and has that id open when none is or nothing looks it up.
diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/IamRequestResourceEnforcementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/IamRequestResourceEnforcementIntegrationTest.java
index 2efd9a6e67..a752555824 100644
--- a/src/test/java/io/github/hectorvent/floci/services/iam/IamRequestResourceEnforcementIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/iam/IamRequestResourceEnforcementIntegrationTest.java
@@ -23,6 +23,7 @@ import java.util.Map;
import static io.github.hectorvent.floci.testing.EnforcementFixtures.auth;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -374,6 +375,36 @@ class IamRequestResourceEnforcementIntegrationTest {
.then(), "events:DescribeEventBus");
}
+ /**
+ * Publishing is authorized on the bus of every entry, the one it names by name or ARN or the default one when
+ * it names none, so a grant on one bus refuses a batch with an entry for another, and a deny on one bus holds
+ * however many entries go elsewhere.
+ */
+ @Test
+ void eachEventIsCheckedOnTheBusItsEntryNames() {
+ String bus = "res-bus-" + suffix();
+ admin("events").header("X-Amz-Target", "AWSEvents.CreateEventBus").contentType("application/x-amz-json-1.1")
+ .body("{\"Name\":\"" + bus + "\"}").post("/").then().statusCode(200);
+ cleanup.register(() -> admin("events").header("X-Amz-Target", "AWSEvents.DeleteEventBus")
+ .contentType("application/x-amz-json-1.1").body("{\"Name\":\"" + bus + "\"}").post("/"));
+ String byName = ",\"EventBusName\":\"" + bus + "\"";
+ String byArn = ",\"EventBusName\":\"" + EVENTS + "event-bus/" + bus + "\"";
+
+ User user = user("res-put-events");
+ user.policy(allowOn("events:PutEvents", EVENTS + "event-bus/" + bus));
+ putEvents(user, byName, byArn).statusCode(200).body("FailedEntryCount", equalTo(0));
+ refusedJson(putEvents(user, byName, ""), "events:PutEvents");
+ refusedJson(putEvents(user, ""), "events:PutEvents");
+ user.policy(allowOn("events:PutEvents", EVENTS + "event-bus/" + bus) + ","
+ + allowOn("events:PutEvents", EVENTS + "event-bus/default"));
+ putEvents(user, byName, "").statusCode(200).body("FailedEntryCount", equalTo(0));
+
+ user.policy(allowOn("events:PutEvents", "*") + ",{\"Effect\":\"Deny\",\"Action\":\"events:PutEvents\","
+ + "\"Resource\":\"" + EVENTS + "event-bus/" + bus + "\"}");
+ refusedJson(putEvents(user, "", "", byArn), "events:PutEvents");
+ putEvents(user, "", ",\"EventBusName\":null").statusCode(200).body("FailedEntryCount", equalTo(0));
+ }
+
@Test
void aUserPoolIsCheckedOnTheArnItsIdNames() {
String id = admin("cognito-idp").header("X-Amz-Target", "AWSCognitoIdentityProviderService.CreateUserPool")
@@ -522,6 +553,17 @@ class IamRequestResourceEnforcementIntegrationTest {
.post("/").then();
}
+ /** Publishes an event for each of {@code buses}, the bus of its entry as a JSON member or none. */
+ private static ValidatableResponse putEvents(User user, String... buses) {
+ StringBuilder entries = new StringBuilder();
+ for (String bus : buses) {
+ entries.append(entries.isEmpty() ? "" : ",")
+ .append("{\"Source\":\"res.test\",\"DetailType\":\"t\",\"Detail\":\"{}\"").append(bus).append('}');
+ }
+ return user.json("events", "AWSEvents.PutEvents", "1.1").body("{\"Entries\":[" + entries + "]}")
+ .post("/").then();
+ }
+
private static String publishVersion(String arn) {
return admin("states").header("X-Amz-Target", "AWSStepFunctions.PublishStateMachineVersion")
.contentType("application/x-amz-json-1.0").body("{\"stateMachineArn\":\"" + arn + "\"}")
diff --git a/tools/aws/regen_iam_request_resources.py b/tools/aws/regen_iam_request_resources.py
index 40e5a7a7f0..db2d7e397e 100644
--- a/tools/aws/regen_iam_request_resources.py
+++ b/tools/aws/regen_iam_request_resources.py
@@ -42,7 +42,9 @@ A member whose botocore shape is an account id (a string of pattern `[0-9]{12}`)
the types the request names by their variables: ECR's `registryId` selects the registry its handler
acts in, so `repository/<name>` is that account's. A member whose shape's pattern takes an ARN before
the name (`(arn:...:event-bus/)?<name>`) may give the ARN of the type of that name instead, whose one
-variable it is then read as, in the ARN's account and Region: EventBridge's `EventBusName`.
+variable it is then read as, in the ARN's account and Region: EventBridge's `EventBusName`. So may a
+field of each element of a list of structures, each element's resource in the account and Region of
+the ARN it gives: `PutEvents`' `Entries[].EventBusName`.
An operation that creates a type its action does not act on names the new resource from the ARN of the
parent it acts on, when the child's ARN format is the parent's with its resource type word replaced and
@@ -61,7 +63,9 @@ or not. `HAND_BUILT` are the namespaces `ResourceArnBuilder` builds resources fo
`CORRECTIONS` gives an operation's resources where the rule gets them wrong, each with its reason; a
resource there may apply only `when` a member has one of some values (`Type` picks the load balancer
v2 `CreateLoadBalancer` creates), or `unless` it has, read as a value when it is `absent` (an
-EventBridge request naming no event bus names the default one), and an ARN member's value may be read
+EventBridge request naming no event bus names the default one), a variable may be filled from a field
+of each element of a list of structures, one resource for each element and the `absent` value for an
+element lacking it (`PutEvents` publishes each entry to its bus), and an ARN member's value may be read
only up to a character `before` which its handler drops the rest (`StartExecution`'s
`<stateMachineArn>#<test case>`). `CLIENTS_NOT_READ` are SDK clients the reference lists for a
namespace's operations whose requests Floci does not serve, each with its reason.
@@ -250,6 +254,12 @@ CORRECTIONS: dict[str, tuple[list[dict], str]] = {
"events:DescribeEventBus": ([{"type": "event-bus", "fill": {"EventBusName": "Name"}, "absent": {"Name": "default"}}],
"a request naming no event bus describes the default one ('If you omit this, the "
"default event bus is displayed')"),
+ "events:PutEvents": ([{"type": "event-bus", "fill": {"EventBusName": "Entries[].EventBusName"},
+ "absent": {"Entries[].EventBusName": "default"}}],
+ "each entry goes to the event bus its EventBusName names, the default one when it names "
+ "none ('If you omit this, the default event bus is used'), and publishing is authorized "
+ "against the bus for every entry in the request; the rule reads no member of a list's "
+ "structures"),
**{f"states:{operation}": ([{"types": ["statemachine"], "arn": "stateMachineArn", "before": "#"}],
"Floci takes Step Functions Local's <stateMachineArn>#<test case> and runs the machine "
"the part before the # names, so that part is the one checked")
@@ -413,20 +423,35 @@ NAME_OR_ARN_RE = re.compile(r"^\(arn:[^)]*:([A-Za-z][A-Za-z0-9-]*)\\?/\)\?")
def name_or_arn_members(models: dict[str, dict], operation: str) -> dict[str, str]:
"""The top-level members of the operation's request whose shape's pattern takes an ARN before a name, by name,
- each with the resource type word of that ARN."""
+ and the fields of each element of a list of structures whose shape's does, as `Name[].Field`, each with the
+ resource type word of that ARN."""
found: dict[str, str] = {}
for model in models.values():
spec = model["operations"].get(operation)
if spec is None or "input" not in spec or not READ_PROTOCOLS & _protocols(model):
continue
for name, member in model["shapes"][spec["input"]["shape"]].get("members", {}).items():
+ if member.get("location") not in BODY_LOCATIONS:
+ continue
shape = model["shapes"][member["shape"]]
- match = NAME_OR_ARN_RE.match(shape.get("pattern") or "") if shape["type"] == "string" else None
- if member.get("location") in BODY_LOCATIONS and match:
- found.setdefault(name, match.group(1))
+ word = _name_or_arn(shape)
+ if word:
+ found.setdefault(name, word)
+ element = model["shapes"][shape["member"]["shape"]] if shape["type"] == "list" else {}
+ if element.get("type") == "structure":
+ for field, nested in element.get("members", {}).items():
+ word = _name_or_arn(model["shapes"][nested["shape"]])
+ if word:
+ found.setdefault(f"{name}[].{field}", word)
return found
+def _name_or_arn(shape: dict) -> str | None:
+ """The resource type word of the ARN a string shape's pattern takes before a name; None for another shape."""
+ match = NAME_OR_ARN_RE.match(shape.get("pattern") or "") if shape["type"] == "string" else None
+ return match.group(1) if match else None
+
+
def named_by(word: str, formats: dict[str, str]) -> str | None:
"""The type whose ARN format's resource is the word and one variable (`event-bus/${EventBusName}`)."""
found = [kind for kind, arn in formats.items()
@@ -704,6 +729,8 @@ def render(document: dict) -> str:
# Gates
# --------------------------------------------------------------------------- #
PATH_RE = re.compile(r"^[A-Za-z][A-Za-z0-9_]*(\[])?$")
+# A member filling a variable may also be a field of each element of a list of structures, one value for each.
+FILL_PATH_RE = re.compile(r"^[A-Za-z][A-Za-z0-9_]*(\[]|\[]\.[A-Za-z][A-Za-z0-9_]*)?$")
# An ARN member's path may go one level into a structure or a list's structures.
ARN_PATH_RE = re.compile(r"^[A-Za-z][A-Za-z0-9_]*(\[])?(\.[A-Za-z][A-Za-z0-9_]*(\[])?)?$")
# A format's resource that is a literal and one variable, at its end.
@@ -784,9 +811,9 @@ def _resource_problems(operation: str, resource: object, types: set[str], format
fill = resource["fill"]
variables = set(VARIABLE_RE.findall(formats[kinds[0]])) - KNOWN_VARIABLES
if not isinstance(fill, dict) or set(fill) - variables or not all(
- isinstance(path, str) and PATH_RE.match(path) for path in fill.values()):
+ isinstance(path, str) and FILL_PATH_RE.match(path) for path in fill.values()):
return [f"{operation} fills {fill!r}, which are no variables of {kinds[0]}'s ARN by members"]
- if sum(path.endswith("[]") for path in fill.values()) > 1:
+ if sum("[]" in path for path in fill.values()) > 1:
return [f"{operation} fills {kinds[0]} from more than one list"]
for key in ("when", "unless"):
when = resource.get(key, {})
@@ -795,12 +822,12 @@ def _resource_problems(operation: str, resource: object, types: set[str], format
and values and all(value is None or isinstance(value, str) for value in values) for path, values in when.items()):
return [f"{operation} names {kinds[0]} {key} {when!r}, which is no member's values"]
absent = resource.get("absent", {})
- if not isinstance(absent, dict) or not all(isinstance(path, str) and PATH_RE.match(path) and not path.endswith("[]")
- and isinstance(value, str) and value for path, value in absent.items()):
+ if not isinstance(absent, dict) or not all(_read_as_one(path, fill) and isinstance(value, str) and value
+ for path, value in absent.items()):
return [f"{operation} reads {absent!r} for absent members, which is no member's value"]
arn_of = resource.get("arnOf", {})
if not isinstance(arn_of, dict) or not all(
- isinstance(path, str) and PATH_RE.match(path) and not path.endswith("[]") and isinstance(kind, str)
+ _read_as_one(path, fill) and isinstance(kind, str)
and len(set(VARIABLE_RE.findall(formats.get(kind, ""))) - KNOWN_VARIABLES) == 1
and formats[kind].endswith("}") for path, kind in arn_of.items()):
return [f"{operation} reads {arn_of!r} as ARNs of types, which are no members or types of one variable"]
@@ -811,6 +838,16 @@ def _resource_problems(operation: str, resource: object, types: set[str], format
return []
+def _read_as_one(path: object, fill: dict) -> bool:
+ """Whether a member gives one value as it is read: a top-level one that is no list, or a field of each element
+ of a list of structures that fills a variable, one value for each element."""
+ if not isinstance(path, str):
+ return False
+ if "[]." in path:
+ return bool(FILL_PATH_RE.match(path)) and path in fill.values()
+ return bool(PATH_RE.match(path)) and not path.endswith("[]")
+
+
def _created_problems(operation: str, created: object, types: set[str], formats: dict[str, str]) -> list[str]:
if not isinstance(created, dict) or set(created) != {"type", "parent", "arn"} or not isinstance(created["arn"], str) \
or not PATH_RE.match(created["arn"]):
diff --git a/tools/aws/test_regen_iam_request_resources.py b/tools/aws/test_regen_iam_request_resources.py
index d51512b6e2..54599ff367 100644
--- a/tools/aws/test_regen_iam_request_resources.py
+++ b/tools/aws/test_regen_iam_request_resources.py
@@ -275,6 +275,22 @@ def test_a_member_taking_an_arn_before_a_name_is_read_as_the_variable_of_that_ty
dict(rules[0], arnOf={"BusName": "bus"}), dict(rules[1], arnOf={"BusName": "bus"}), rules[2]]
+def test_a_field_of_each_of_a_lists_structures_taking_an_arn_before_a_name_is_read_by_its_path():
+ shapes = {"String": {"type": "string"},
+ "BusNameOrArn": {"type": "string", "pattern": "(arn:aws[\\w-]*:svc:[a-z]+-[a-z]+-[\\w-]+:[0-9]{12}:bus\\/)?[\\.\\-_A-Za-z0-9]+"},
+ "Entry": {"type": "structure", "members": {"Source": {"shape": "String"}, "BusName": {"shape": "BusNameOrArn"}}},
+ "Entries": {"type": "list", "member": {"shape": "Entry"}},
+ "Config": {"type": "structure", "members": {"BusName": {"shape": "BusNameOrArn"}}},
+ "In": {"type": "structure", "members": {"Entries": {"shape": "Entries"}, "Config": {"shape": "Config"}}}}
+ models = {"svc": {"metadata": {"protocol": "json"}, "operations": {"PutEvents": {"input": {"shape": "In"}}}, "shapes": shapes}}
+ # Only a list's structures give one value for each, so a lone structure's field is not read.
+ assert r.name_or_arn_members(models, "PutEvents") == {"Entries[].BusName": "bus"}
+ formats = {"bus": "arn:${Partition}:svc:${Region}:${Account}:bus/${BusName}"}
+ buses = [{"type": "bus", "fill": {"BusName": "Entries[].BusName"}, "absent": {"Entries[].BusName": "default"}}]
+ assert r.with_arn_of(buses, formats, r.name_or_arn_members(models, "PutEvents")) == [
+ dict(buses[0], arnOf={"Entries[].BusName": "bus"})]
+
+
def test_a_correction_for_an_operation_the_file_does_not_read_fails(corrections, tmp_path):
corrections.setattr(r, "CORRECTIONS", {"svc:Gone": ([], "no longer there")})
with pytest.raises(ValueError, match="svc:Gone"):
@@ -303,6 +319,11 @@ def test_a_well_formed_document_validates():
document["operations"]["svc:A"]["resources"][0]["before"] = "#"
assert r.validate(document) == []
assert r.validate(with_a_create()) == []
+ # A field of each of a list's structures fills a variable, read as given when absent, or as an ARN.
+ document = good_document()
+ document["operations"]["svc:B"]["resources"][0].update(
+ fill={"GroupName": "Groups[].Name"}, absent={"Groups[].Name": "default"}, arnOf={"Groups[].Name": "thing"})
+ assert r.validate(document) == []
def with_a_create() -> dict:
@@ -316,7 +337,11 @@ def with_a_create() -> dict:
(lambda d: d["operations"]["svc:A"]["resources"][0].update(types=["pool"]), "not resource types"),
(lambda d: d["operations"]["svc:A"]["resources"][0].update(arn="a.b.c"), "no member"),
(lambda d: d["operations"]["svc:A"]["resources"][0].update(arn="a[][]"), "no member"),
- (lambda d: d["operations"]["svc:B"]["resources"][0]["fill"].update(GroupName="Groups[].Name"), "no variables"),
+ (lambda d: d["operations"]["svc:B"]["resources"][0]["fill"].update(GroupName="Group.Name"), "no variables"),
+ (lambda d: d["operations"]["svc:B"]["resources"][0]["fill"].update(GroupName="Groups[].Names[]"), "no variables"),
+ (lambda d: d["operations"]["svc:B"]["resources"][0]["fill"].update(GroupId="Groups[].Id"), "more than one list"),
+ (lambda d: d["operations"]["svc:B"]["resources"][0].update(absent={"Groups[].Name": "default"}), "absent members"),
+ (lambda d: d["operations"]["svc:B"]["resources"][0].update(arnOf={"Groups[].Name": "thing"}), "types of one variable"),
(lambda d: d["operations"]["svc:B"]["resources"][0]["fill"].update(Other="Name"), "no variables"),
(lambda d: d["operations"]["svc:B"]["resources"][0]["fill"].update(GroupId="Ids[]"), "more than one list"),
(lambda d: d["operations"]["svc:A"].update(action="other:A"), "no action of its namespace"),
@@ -428,6 +453,10 @@ def test_the_vendored_file_is_well_formed():
"unless": {"EventBusName": ["default"]}, "absent": {"EventBusName": "default"}, "arnOf": {"EventBusName": "event-bus"}}]
assert operations["events:DescribeEventBus"]["resources"] == [
{"type": "event-bus", "fill": {"EventBusName": "Name"}, "absent": {"Name": "default"}, "arnOf": {"Name": "event-bus"}}]
+ # Each PutEvents entry is on the bus it names, by name or ARN, or the default one when it names none.
+ assert operations["events:PutEvents"]["resources"] == [
+ {"type": "event-bus", "fill": {"EventBusName": "Entries[].EventBusName"},
+ "absent": {"Entries[].EventBusName": "default"}, "arnOf": {"Entries[].EventBusName": "event-bus"}}]
assert document["namespaces"]["events"] == ["events"] and "eventbridgev2" in document["clientsNotRead"]
# A state machine's version or alias is checked on the state machine.
assert document["unqualified"] == {"states": ["statemachine"]}