mirror of
https://github.com/floci-io/floci.git
synced 2026-12-04 18:48:00 -05:00
test(core): guard that core-bound classes import no AWS service code (#10026)
Adds CoreBoundImportGuardTest, a source-scanning test that keeps the infrastructure classes bound for floci-core (storage, Docker, DNS, TLS, lifecycle, service registry, request plumbing, XML), listed in core-boundary/core-bound.txt, free of AWS service code. Ignoring comments, it fails on an io.floci.aws.services reference in code or in a string literal, a service-specific ServicesConfig accessor read from EmulatorConfig, or one of their config types. allowlist.tsv records the 88 references that predate the guard, and a stale line fails too, so the list only shrinks until ALLOWLIST_MUST_BE_EMPTY makes it the rule.
This commit is contained in:
1 parent
83209f39f6
commit
cb90a9f16d
3 files changed
+734
No files matched your search
@@ -0,0 +1,580 @@
|
||||
package io.floci.aws.tools;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
/**
|
||||
* Keeps the classes bound for floci-core free of AWS service code.
|
||||
*
|
||||
* <p>The floci-core ADR moves the Tier 1 and Tier 2 infrastructure classes (storage, Docker, DNS,
|
||||
* TLS, lifecycle, service registry, request plumbing, XML) into a shared library, and requires that
|
||||
* they first stop depending on AWS services while they still live here. Those classes are listed in
|
||||
* {@code src/test/resources/core-boundary/core-bound.txt}. Their sources must contain none of:
|
||||
*
|
||||
* <ul>
|
||||
* <li>a reference to {@code io.floci.aws.services.*} in code: a regular or static import, or a
|
||||
* fully qualified name anywhere in the body;</li>
|
||||
* <li>the same package named in a string literal (a reflection or native-image registration is
|
||||
* as much a dependency as an import);</li>
|
||||
* <li>a service-specific accessor on {@code ServicesConfig}, such as
|
||||
* {@code config.services().lambda()}. The accessors are read from {@code EmulatorConfig}'s
|
||||
* {@code ServicesConfig}; the shared {@code dockerNetwork()} is not service-specific and is
|
||||
* allowed;</li>
|
||||
* <li>a service config type returned by those accessors, such as
|
||||
* {@code EmulatorConfig.EcsServiceConfig} or {@code DuckConfig}, including through an
|
||||
* import of one of its nested types.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>Comments are ignored. The references that predate this guard are recorded in
|
||||
* {@code src/test/resources/core-boundary/allowlist.tsv}, one {@code class<TAB>reference} per line.
|
||||
* A reference that is not in the allowlist fails, and so does an allowlist line that no longer
|
||||
* matches anything, so the list can only shrink.
|
||||
*
|
||||
* <p>Classes that the ADR names but that live under {@code services/} are not scanned: Lambda's
|
||||
* {@code ImageCacheService} and ACM's {@code CertificateGenerator} are the AWS copies that core
|
||||
* replaces with its own, reached through seams.
|
||||
*
|
||||
* <p><b>Flipping to the end state.</b> Today the guard runs in report mode: the allowlist is the
|
||||
* report of what is left to untangle. Each untangling change removes its lines (the stale-entry
|
||||
* check forces it). Once the allowlist is empty, set {@link #ALLOWLIST_MUST_BE_EMPTY} to
|
||||
* {@code true}, which turns any line added back to the allowlist into a failure. To check how far
|
||||
* off that is before flipping, run with {@code -Dfloci.core-boundary.strict=true}.
|
||||
*/
|
||||
class CoreBoundImportGuardTest {
|
||||
|
||||
/** The end-state switch; see the class documentation. */
|
||||
static final boolean ALLOWLIST_MUST_BE_EMPTY = false;
|
||||
|
||||
private static final Path SOURCES = Path.of("src/main/java");
|
||||
private static final Path CORE_BOUND = Path.of("src/test/resources/core-boundary/core-bound.txt");
|
||||
private static final Path ALLOWLIST = Path.of("src/test/resources/core-boundary/allowlist.tsv");
|
||||
private static final Path EMULATOR_CONFIG = SOURCES.resolve("io/floci/aws/config/EmulatorConfig.java");
|
||||
|
||||
@Test
|
||||
void everyCoreBoundEntryNamesAnExistingSource() {
|
||||
List<String> problems = new ArrayList<>();
|
||||
List<String> lines = read(CORE_BOUND);
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String entry = lines.get(i).strip();
|
||||
if (entry.isEmpty() || entry.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
String name = entry.startsWith("!") ? entry.substring(1) : entry;
|
||||
boolean exists = name.endsWith(".*")
|
||||
? !javaFilesIn(packageDir(name)).isEmpty()
|
||||
: Files.isRegularFile(SOURCES.resolve(sourceOf(name)));
|
||||
if (!exists) {
|
||||
problems.add(CORE_BOUND + ":" + (i + 1) + ": " + entry);
|
||||
}
|
||||
}
|
||||
assertTrue(problems.isEmpty(), "core-bound entries that name no source (renamed, moved or "
|
||||
+ "deleted? update core-bound.txt to follow it):\n " + String.join("\n ", problems));
|
||||
}
|
||||
|
||||
@Test
|
||||
void coreBoundClassesReferenceNoAwsServiceCodeBeyondTheAllowlist() {
|
||||
Set<String> allowed = allowlist().keySet();
|
||||
List<String> violations = new ArrayList<>();
|
||||
for (Map.Entry<String, List<SourceScanner.Finding>> entry : scanCoreBound().entrySet()) {
|
||||
for (SourceScanner.Finding finding : entry.getValue()) {
|
||||
if (!allowed.contains(entry.getKey() + "\t" + finding.reference())) {
|
||||
violations.add(SOURCES.resolve(sourceOf(entry.getKey())) + ":" + finding.line()
|
||||
+ ": " + finding.reference() + " (" + finding.rule() + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!violations.isEmpty()) {
|
||||
fail("Classes bound for floci-core reference AWS service code:\n "
|
||||
+ String.join("\n ", violations) + "\n"
|
||||
+ "Move the dependency behind an interface the AWS service implements (an SPI, a "
|
||||
+ "hook, a neutral config key), or take the class off core-bound.txt if it does "
|
||||
+ "not belong in floci-core. " + ALLOWLIST + " only records references that "
|
||||
+ "predate this guard and must not grow.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void everyAllowlistEntryStillOccurs() {
|
||||
Map<String, Set<String>> found = new LinkedHashMap<>();
|
||||
scanCoreBound().forEach((className, findings) -> found.put(className,
|
||||
findings.stream().map(SourceScanner.Finding::reference).collect(Collectors.toSet())));
|
||||
List<String> stale = new ArrayList<>();
|
||||
allowlist().forEach((key, line) -> {
|
||||
String[] parts = key.split("\t", 2);
|
||||
if (!found.getOrDefault(parts[0], Set.of()).contains(parts[1])) {
|
||||
stale.add(ALLOWLIST + ":" + line + ": " + parts[0] + " -> " + parts[1]);
|
||||
}
|
||||
});
|
||||
assertTrue(stale.isEmpty(), "Stale allowlist entries: the reference no longer occurs in a "
|
||||
+ "core-bound class. Remove them:\n " + String.join("\n ", stale));
|
||||
}
|
||||
|
||||
@Test
|
||||
void allowlistIsEmptyOnceTheBoundaryIsEnforced() {
|
||||
assumeTrue(ALLOWLIST_MUST_BE_EMPTY || Boolean.getBoolean("floci.core-boundary.strict"),
|
||||
"report mode: the allowlist still lists references to untangle");
|
||||
Map<String, Integer> entries = allowlist();
|
||||
assertTrue(entries.isEmpty(), "The core boundary is enforced, so " + ALLOWLIST
|
||||
+ " must be empty, but it lists " + entries.size() + " references:\n "
|
||||
+ entries.entrySet().stream()
|
||||
.map(entry -> ALLOWLIST + ":" + entry.getValue() + ": " + entry.getKey().replace("\t", " -> "))
|
||||
.collect(Collectors.joining("\n ")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void serviceConfigAccessorsAreReadFromEmulatorConfig() {
|
||||
SourceScanner scanner = SourceScanner.fromEmulatorConfig(readString(EMULATOR_CONFIG));
|
||||
assertTrue(scanner.accessors().containsAll(Set.of("lambda", "ecs", "iam", "duck")),
|
||||
"accessors: " + scanner.accessors());
|
||||
assertFalse(scanner.accessors().contains("dockerNetwork"));
|
||||
assertTrue(scanner.types().containsAll(Set.of("LambdaServiceConfig", "EcsServiceConfig", "DuckConfig")),
|
||||
"types: " + scanner.types());
|
||||
assertFalse(scanner.types().contains("Optional"));
|
||||
}
|
||||
|
||||
// Scanner edge cases. The fixtures use a tiny accessor and type set.
|
||||
|
||||
private static final SourceScanner FIXTURE = new SourceScanner(
|
||||
Set.of("lambda", "iot"), Set.of("LambdaServiceConfig", "DuckConfig"));
|
||||
|
||||
@Test
|
||||
void scan_importsStaticImportsAndWildcards_areFound() {
|
||||
List<SourceScanner.Finding> findings = FIXTURE.scan("""
|
||||
package io.floci.aws.core.common;
|
||||
|
||||
import io.floci.aws.services.acm.CertificateGenerator;
|
||||
import static io.floci.aws.services.iam.Policies.ALLOW;
|
||||
import io.floci.aws.services.lambda.model.*;
|
||||
""");
|
||||
assertEquals(List.of(
|
||||
new SourceScanner.Finding(3, "io.floci.aws.services.acm.CertificateGenerator", SourceScanner.SERVICES_RULE),
|
||||
new SourceScanner.Finding(4, "io.floci.aws.services.iam.Policies.ALLOW", SourceScanner.SERVICES_RULE),
|
||||
new SourceScanner.Finding(5, "io.floci.aws.services.lambda.model.*", SourceScanner.SERVICES_RULE)),
|
||||
findings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void scan_fullyQualifiedNameInCode_isFound() {
|
||||
List<SourceScanner.Finding> findings = FIXTURE.scan("""
|
||||
class A {
|
||||
Object o = new io.floci.aws.services.sqs.SqsService();
|
||||
}
|
||||
""");
|
||||
assertEquals(List.of(new SourceScanner.Finding(2, "io.floci.aws.services.sqs.SqsService",
|
||||
SourceScanner.SERVICES_RULE)), findings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void scan_comments_areIgnored() {
|
||||
List<SourceScanner.Finding> findings = FIXTURE.scan("""
|
||||
// import io.floci.aws.services.acm.CertificateGenerator;
|
||||
/* config.services().lambda() and LambdaServiceConfig */
|
||||
/**
|
||||
* {@link io.floci.aws.services.sqs.SqsService} "not a string
|
||||
*/
|
||||
class A { // "also not a string
|
||||
int x; /* io.floci.aws.services.x.Y */ int y;
|
||||
}
|
||||
""");
|
||||
assertEquals(List.of(), findings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void scan_servicePackageInStringLiteral_isFoundButConfigNamesInStringsAreNot() {
|
||||
List<SourceScanner.Finding> findings = FIXTURE.scan("""
|
||||
class A {
|
||||
String log = "set config.services().lambda() or LambdaServiceConfig";
|
||||
String reflect = "io.floci.aws.services.ec2.net.VpcNetworkManager$Gateway";
|
||||
}
|
||||
""");
|
||||
assertEquals(List.of(new SourceScanner.Finding(3,
|
||||
"io.floci.aws.services.ec2.net.VpcNetworkManager$Gateway", SourceScanner.STRING_RULE)), findings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void scan_commentMarkersInsideStringsAndCharLiterals_doNotHideCode() {
|
||||
List<SourceScanner.Finding> findings = FIXTURE.scan("""
|
||||
class A {
|
||||
String a = "/* not a comment \\" still a string";
|
||||
char q = '"';
|
||||
char s = '\\'';
|
||||
String b = "// nor this";
|
||||
Object c = config.services().lambda();
|
||||
}
|
||||
""");
|
||||
assertEquals(List.of(new SourceScanner.Finding(6, "services().lambda()", SourceScanner.ACCESSOR_RULE)),
|
||||
findings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void scan_textBlocks_areStrings() {
|
||||
String source = "class A {\n"
|
||||
+ " String t = \"\"\"\n"
|
||||
+ " config.services().lambda() \\\"\"\" // still inside\n"
|
||||
+ " \"\"\";\n"
|
||||
+ " Object c = config.services().iot();\n"
|
||||
+ "}\n";
|
||||
assertEquals(List.of(new SourceScanner.Finding(5, "services().iot()", SourceScanner.ACCESSOR_RULE)),
|
||||
FIXTURE.scan(source));
|
||||
}
|
||||
|
||||
@Test
|
||||
void scan_accessorChainAcrossLines_isFoundOnItsAccessorLine() {
|
||||
List<SourceScanner.Finding> findings = FIXTURE.scan("""
|
||||
class A {
|
||||
Object c = config.services()
|
||||
.lambda()
|
||||
.dockerHostOverride();
|
||||
}
|
||||
""");
|
||||
assertEquals(List.of(new SourceScanner.Finding(3, "services().lambda()", SourceScanner.ACCESSOR_RULE)),
|
||||
findings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void scan_sharedDockerNetworkAndUnrelatedNames_areAllowed() {
|
||||
List<SourceScanner.Finding> findings = FIXTURE.scan("""
|
||||
class A {
|
||||
Object n = config.services().dockerNetwork();
|
||||
Object m = lambdaServices().lambda();
|
||||
ServiceConfigAccess access;
|
||||
MyLambdaServiceConfigHolder holder;
|
||||
}
|
||||
""");
|
||||
assertEquals(List.of(), findings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void scan_serviceConfigTypes_areFoundQualifiedOrImported() {
|
||||
List<SourceScanner.Finding> findings = FIXTURE.scan("""
|
||||
import io.floci.aws.config.EmulatorConfig.LambdaServiceConfig.Mode;
|
||||
class A {
|
||||
EmulatorConfig.DuckConfig duck;
|
||||
}
|
||||
""");
|
||||
assertEquals(List.of(
|
||||
new SourceScanner.Finding(1, "LambdaServiceConfig", SourceScanner.TYPE_RULE),
|
||||
new SourceScanner.Finding(3, "DuckConfig", SourceScanner.TYPE_RULE)), findings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void scan_sameReferenceTwiceOnOneLine_isReportedOnce() {
|
||||
List<SourceScanner.Finding> findings = FIXTURE.scan(
|
||||
"class A { Object a = config.services().lambda(), b = config.services().lambda(); }\n");
|
||||
assertEquals(1, findings.size(), findings.toString());
|
||||
}
|
||||
|
||||
/** Core-bound class name to what the scanner found in its source, in class-name order. */
|
||||
private static Map<String, List<SourceScanner.Finding>> scanCoreBound() {
|
||||
SourceScanner scanner = SourceScanner.fromEmulatorConfig(readString(EMULATOR_CONFIG));
|
||||
Map<String, List<SourceScanner.Finding>> result = new LinkedHashMap<>();
|
||||
for (String className : coreBoundClasses()) {
|
||||
List<SourceScanner.Finding> findings = scanner.scan(readString(SOURCES.resolve(sourceOf(className))));
|
||||
if (!findings.isEmpty()) {
|
||||
result.put(className, findings);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Set<String> coreBoundClasses() {
|
||||
Set<String> classes = new TreeSet<>();
|
||||
Set<String> excluded = new LinkedHashSet<>();
|
||||
for (String raw : read(CORE_BOUND)) {
|
||||
String entry = raw.strip();
|
||||
if (entry.isEmpty() || entry.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
if (entry.startsWith("!")) {
|
||||
excluded.add(entry.substring(1));
|
||||
} else if (entry.endsWith(".*")) {
|
||||
String pkg = entry.substring(0, entry.length() - 2);
|
||||
for (Path file : javaFilesIn(packageDir(entry))) {
|
||||
String simple = file.getFileName().toString();
|
||||
classes.add(pkg + "." + simple.substring(0, simple.length() - ".java".length()));
|
||||
}
|
||||
} else {
|
||||
classes.add(entry);
|
||||
}
|
||||
}
|
||||
classes.removeAll(excluded);
|
||||
return classes;
|
||||
}
|
||||
|
||||
/** {@code class<TAB>reference} to its line number in the allowlist file. */
|
||||
private static Map<String, Integer> allowlist() {
|
||||
Map<String, Integer> entries = new LinkedHashMap<>();
|
||||
List<String> lines = read(ALLOWLIST);
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String line = lines.get(i);
|
||||
if (line.isBlank() || line.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
String[] parts = line.split("\t");
|
||||
if (parts.length != 2 || parts[0].isBlank() || parts[1].isBlank()) {
|
||||
fail(ALLOWLIST + ":" + (i + 1) + ": expected class<TAB>reference, got: " + line);
|
||||
}
|
||||
if (entries.put(line, i + 1) != null) {
|
||||
fail(ALLOWLIST + ":" + (i + 1) + ": duplicate entry: " + line);
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
private static Path sourceOf(String className) {
|
||||
return Path.of(className.replace('.', '/') + ".java");
|
||||
}
|
||||
|
||||
private static Path packageDir(String packageEntry) {
|
||||
String pkg = packageEntry.substring(0, packageEntry.length() - 2);
|
||||
return SOURCES.resolve(pkg.replace('.', '/'));
|
||||
}
|
||||
|
||||
private static List<Path> javaFilesIn(Path dir) {
|
||||
if (!Files.isDirectory(dir)) {
|
||||
return List.of();
|
||||
}
|
||||
try (Stream<Path> files = Files.list(dir)) {
|
||||
return files.filter(Files::isRegularFile)
|
||||
.filter(file -> file.getFileName().toString().endsWith(".java"))
|
||||
.filter(file -> !file.getFileName().toString().equals("package-info.java"))
|
||||
.sorted()
|
||||
.toList();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Could not list " + dir, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> read(Path file) {
|
||||
try {
|
||||
return Files.readAllLines(file, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Could not read " + file, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String readString(Path file) {
|
||||
try {
|
||||
return Files.readString(file, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Could not read " + file, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds AWS service references in one Java source.
|
||||
*
|
||||
* <p>It splits the source into a code view (comments and literals blanked) and a literal view
|
||||
* (only string, text block and char literal contents kept), both the length of the source with
|
||||
* its line breaks in place, so a match offset maps straight to a line number.
|
||||
*/
|
||||
static final class SourceScanner {
|
||||
|
||||
static final String SERVICES_RULE = "AWS service package";
|
||||
static final String STRING_RULE = "AWS service package in a string literal";
|
||||
static final String ACCESSOR_RULE = "service-specific config accessor";
|
||||
static final String TYPE_RULE = "service config type";
|
||||
|
||||
private static final Pattern SERVICES_PACKAGE = Pattern.compile(
|
||||
"(?<![\\w$.])io\\s*\\.\\s*floci\\s*\\.\\s*aws\\s*\\.\\s*services(?:\\s*\\.\\s*[\\w$]+)+(?:\\s*\\.\\s*\\*)?");
|
||||
private static final Pattern SERVICES_CONFIG_BLOCK = Pattern.compile("\\binterface\\s+ServicesConfig\\s*\\{");
|
||||
private static final Pattern ACCESSOR_DECLARATION = Pattern.compile("^\\s*([\\w.<>]+)\\s+(\\w+)\\s*\\(\\s*\\)\\s*;");
|
||||
private static final Set<String> NON_SERVICE_TYPES = Set.of("Optional", "String", "boolean", "int", "long");
|
||||
|
||||
record Finding(int line, String reference, String rule) {
|
||||
}
|
||||
|
||||
private final Set<String> accessors;
|
||||
private final Set<String> types;
|
||||
private final Pattern accessorPattern;
|
||||
private final Pattern typePattern;
|
||||
|
||||
SourceScanner(Set<String> accessors, Set<String> types) {
|
||||
this.accessors = Set.copyOf(accessors);
|
||||
this.types = Set.copyOf(types);
|
||||
this.accessorPattern = Pattern.compile("\\.\\s*services\\s*\\(\\s*\\)\\s*\\.\\s*("
|
||||
+ String.join("|", new TreeSet<>(accessors)) + ")\\s*\\(");
|
||||
this.typePattern = Pattern.compile("(?<![\\w$])(" + String.join("|", new TreeSet<>(types)) + ")(?![\\w$])");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the service-specific accessors and their return types from the
|
||||
* {@code ServicesConfig} interface in {@code EmulatorConfig}'s source. An accessor that
|
||||
* returns a plain value ({@code Optional<String> dockerNetwork()}) is shared, not
|
||||
* service-specific.
|
||||
*/
|
||||
static SourceScanner fromEmulatorConfig(String emulatorConfigSource) {
|
||||
String code = new String(views(emulatorConfigSource)[0]);
|
||||
Matcher start = SERVICES_CONFIG_BLOCK.matcher(code);
|
||||
if (!start.find()) {
|
||||
fail("EmulatorConfig has no ServicesConfig interface; the guard cannot tell which "
|
||||
+ "config accessors are service-specific");
|
||||
}
|
||||
int depth = 1;
|
||||
int bodyStart = start.end();
|
||||
int end = bodyStart;
|
||||
StringBuilder topLevel = new StringBuilder();
|
||||
while (depth > 0 && end < code.length()) {
|
||||
char c = code.charAt(end);
|
||||
if (c == '{') {
|
||||
depth++;
|
||||
} else if (c == '}') {
|
||||
depth--;
|
||||
} else if (depth == 1) {
|
||||
topLevel.append(c);
|
||||
}
|
||||
end++;
|
||||
}
|
||||
Set<String> accessors = new TreeSet<>();
|
||||
Set<String> types = new TreeSet<>();
|
||||
for (String line : topLevel.toString().split("\n")) {
|
||||
Matcher declaration = ACCESSOR_DECLARATION.matcher(line);
|
||||
if (declaration.find()) {
|
||||
String type = declaration.group(1).replaceAll("<.*", "");
|
||||
if (!NON_SERVICE_TYPES.contains(type)) {
|
||||
accessors.add(declaration.group(2));
|
||||
types.add(type.substring(type.lastIndexOf('.') + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (accessors.isEmpty()) {
|
||||
fail("Found no service config accessors in EmulatorConfig.ServicesConfig");
|
||||
}
|
||||
return new SourceScanner(accessors, types);
|
||||
}
|
||||
|
||||
Set<String> accessors() {
|
||||
return accessors;
|
||||
}
|
||||
|
||||
Set<String> types() {
|
||||
return types;
|
||||
}
|
||||
|
||||
List<Finding> scan(String source) {
|
||||
char[][] views = views(source);
|
||||
String code = new String(views[0]);
|
||||
String literals = new String(views[1]);
|
||||
int[] lineStarts = lineStarts(source);
|
||||
Set<Finding> findings = new LinkedHashSet<>();
|
||||
collect(findings, SERVICES_PACKAGE.matcher(code), lineStarts, SERVICES_RULE, 0);
|
||||
collect(findings, SERVICES_PACKAGE.matcher(literals), lineStarts, STRING_RULE, 0);
|
||||
Matcher accessor = accessorPattern.matcher(code);
|
||||
while (accessor.find()) {
|
||||
findings.add(new Finding(lineOf(lineStarts, accessor.start(1)),
|
||||
"services()." + accessor.group(1) + "()", ACCESSOR_RULE));
|
||||
}
|
||||
collect(findings, typePattern.matcher(code), lineStarts, TYPE_RULE, 1);
|
||||
List<Finding> sorted = new ArrayList<>(findings);
|
||||
sorted.sort((a, b) -> a.line() != b.line() ? Integer.compare(a.line(), b.line())
|
||||
: a.reference().compareTo(b.reference()));
|
||||
return sorted;
|
||||
}
|
||||
|
||||
private static void collect(Set<Finding> findings, Matcher matcher, int[] lineStarts, String rule, int group) {
|
||||
while (matcher.find()) {
|
||||
findings.add(new Finding(lineOf(lineStarts, matcher.start(group)),
|
||||
matcher.group(group).replaceAll("\\s+", ""), rule));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {code view, literal view}. Handles line and block comments, string literals with
|
||||
* escapes, text blocks and char literals; comment markers inside a literal and quotes
|
||||
* inside a comment are inert.
|
||||
*/
|
||||
static char[][] views(String source) {
|
||||
int n = source.length();
|
||||
char[] code = source.toCharArray();
|
||||
char[] literals = new char[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
literals[i] = source.charAt(i) == '\n' ? '\n' : ' ';
|
||||
}
|
||||
int i = 0;
|
||||
while (i < n) {
|
||||
char c = source.charAt(i);
|
||||
char next = i + 1 < n ? source.charAt(i + 1) : '\0';
|
||||
if (c == '/' && next == '/') {
|
||||
int end = source.indexOf('\n', i);
|
||||
i = blank(code, i, end < 0 ? n : end);
|
||||
} else if (c == '/' && next == '*') {
|
||||
int end = source.indexOf("*/", i + 2);
|
||||
i = blank(code, i, end < 0 ? n : end + 2);
|
||||
} else if (source.startsWith("\"\"\"", i)) {
|
||||
int contentStart = i + 3;
|
||||
int j = contentStart;
|
||||
while (j < n && !source.startsWith("\"\"\"", j)) {
|
||||
j += source.charAt(j) == '\\' ? 2 : 1;
|
||||
}
|
||||
int contentEnd = Math.min(j, n);
|
||||
copy(source, literals, contentStart, contentEnd);
|
||||
i = blank(code, i, Math.min(contentEnd + 3, n));
|
||||
} else if (c == '"' || c == '\'') {
|
||||
int j = i + 1;
|
||||
while (j < n && source.charAt(j) != c && source.charAt(j) != '\n') {
|
||||
j += source.charAt(j) == '\\' ? 2 : 1;
|
||||
}
|
||||
int contentEnd = Math.min(j, n);
|
||||
copy(source, literals, i + 1, contentEnd);
|
||||
i = blank(code, i, Math.min(contentEnd + 1, n));
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return new char[][] {code, literals};
|
||||
}
|
||||
|
||||
private static int blank(char[] chars, int from, int to) {
|
||||
for (int k = from; k < to; k++) {
|
||||
if (chars[k] != '\n') {
|
||||
chars[k] = ' ';
|
||||
}
|
||||
}
|
||||
return to;
|
||||
}
|
||||
|
||||
private static void copy(String source, char[] target, int from, int to) {
|
||||
for (int k = from; k < to; k++) {
|
||||
target[k] = source.charAt(k);
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] lineStarts(String source) {
|
||||
List<Integer> starts = new ArrayList<>(List.of(0));
|
||||
for (int k = 0; k < source.length(); k++) {
|
||||
if (source.charAt(k) == '\n') {
|
||||
starts.add(k + 1);
|
||||
}
|
||||
}
|
||||
return starts.stream().mapToInt(Integer::intValue).toArray();
|
||||
}
|
||||
|
||||
private static int lineOf(int[] lineStarts, int offset) {
|
||||
int index = Arrays.binarySearch(lineStarts, offset);
|
||||
return (index >= 0 ? index : -index - 2) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
# class reference
|
||||
io.floci.aws.config.FlociCertificateAuthority io.floci.aws.services.acm.CertificateGenerator
|
||||
io.floci.aws.config.FlociCertificateAuthority io.floci.aws.services.acm.model.KeyAlgorithm
|
||||
io.floci.aws.config.ServerCertificateRenewal io.floci.aws.services.acm.CertificateGenerator
|
||||
io.floci.aws.config.ServerCertificateRenewal io.floci.aws.services.acm.model.KeyAlgorithm
|
||||
io.floci.aws.config.TlsCertificateManager io.floci.aws.services.acm.CertificateGenerator
|
||||
io.floci.aws.config.TlsCertificateManager io.floci.aws.services.acm.model.KeyAlgorithm
|
||||
io.floci.aws.config.TlsConfigSource io.floci.aws.services.acm.CertificateGenerator
|
||||
io.floci.aws.config.TlsConfigSource io.floci.aws.services.acm.model.KeyAlgorithm
|
||||
io.floci.aws.config.TlsProxyServer services().iot()
|
||||
io.floci.aws.config.TlsProxyServer services().lambda()
|
||||
io.floci.aws.core.common.docker.ContainerBuilder io.floci.aws.services.lambda.launcher.ImageCacheService
|
||||
io.floci.aws.core.common.docker.ContainerLifecycleManager EcsServiceConfig
|
||||
io.floci.aws.core.common.docker.ContainerLifecycleManager io.floci.aws.services.lambda.launcher.ImageCacheService
|
||||
io.floci.aws.core.common.docker.ContainerLifecycleManager io.floci.aws.services.lambda.launcher.ImageCacheService.LaunchImage
|
||||
io.floci.aws.core.common.docker.ContainerLogStreamer io.floci.aws.services.cloudwatch.logs.CloudWatchLogsService
|
||||
io.floci.aws.core.common.docker.DockerHostResolver services().lambda()
|
||||
io.floci.aws.core.common.docker.LaunchedContainerAwsEnv io.floci.aws.services.iam.model.SessionCreds
|
||||
io.floci.aws.core.common.port.PortAllocator services().lambda()
|
||||
io.floci.aws.lifecycle.EmulatorInfoController io.floci.aws.services.dynamodb.backend.DynamoDbBackendSelector
|
||||
io.floci.aws.lifecycle.EmulatorInfoController services().ui()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle Ec2ServiceConfig
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle EksServiceConfig
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle EmrServiceConfig
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.amazonmq.AmazonMqService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.amazonmq.container.RabbitMqManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.appsync.graphql.SchemaCreationWorker
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.cloudwatch.metrics.CloudWatchMetricsService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.codeartifact.CodeArtifactService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.docdb.DocDbService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.docdb.container.DocDbContainerManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.dynamodb.DynamoDbRuntime
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.ec2.Ec2MetadataServer
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.ecr.registry.EcrRegistryManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.ecs.EcsService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.ecs.container.EcsTaskRoleCredentialsServer
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.eks.EksService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.elasticache.ElastiCacheMemcachedService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.elasticache.ElastiCacheService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.elasticache.container.ElastiCacheContainerManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.elasticache.container.ElastiCacheMemcachedContainerManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.elasticache.proxy.ElastiCacheProxyManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.elb.ElbClassicService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.elbv2.ElbV2Service
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.floci.ui.FlociUiManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.iam.IamService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.kinesisanalytics.KinesisAnalyticsV2Service
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.kinesisanalytics.container.FlinkContainerManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.lambda.DynamoDbStreamsEventSourcePoller
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.lambda.KinesisEventSourcePoller
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.lambda.SqsEventSourcePoller
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.lambda.durable.DurableExecutionService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.memorydb.MemoryDbService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.memorydb.container.MemoryDbContainerManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.memorydb.proxy.MemoryDbProxyManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.mwaa.MwaaService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.neptune.NeptuneService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.neptune.container.NeptuneContainerManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.neptune.proxy.NeptuneProxyManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.opensearch.OpenSearchService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.pipes.PipesService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.rds.RdsService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.rds.container.RdsContainerManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.rds.integration.RdsIntegrationLoader
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.rds.integration.RdsIntegrationReplicator
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.rds.proxy.RdsProxyManager
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.redshift.RedshiftDynamoDbZeroEtlConsumer
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.sagemaker.SageMakerService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.stepfunctions.StepFunctionsService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle io.floci.aws.services.timestreaminfluxdb.TimestreamInfluxDbService
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().amazonmq()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().codeartifact()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().docdb()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().ec2()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().ecs()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().eks()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().elasticache()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().elb()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().elbv2()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().emr()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().iam()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().kinesisAnalytics()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().lambda()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().memorydb()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().mwaa()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().neptune()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().opensearch()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().sagemaker()
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle services().timestreamInfluxdb()
|
||||
|
@@ -0,0 +1,65 @@
|
||||
# Classes bound for floci-core: the Tier 1 and Tier 2 lists of the floci-core ADR, mapped to their
|
||||
# floci-aws sources. CoreBoundImportGuardTest checks that none of them references AWS service code.
|
||||
#
|
||||
# One entry per line:
|
||||
# io.floci.aws.some.Class a class
|
||||
# io.floci.aws.some.pkg.* every class directly in that package (not its subpackages)
|
||||
# !io.floci.aws.some.Class a class excluded from a package entry above
|
||||
# Every named class and package must exist, so a rename or move fails until this file follows it.
|
||||
|
||||
# Storage (Tier 1 InMemoryStorage, PersistentPathValidator; Tier 2 storage; scoped storage)
|
||||
io.floci.aws.core.storage.*
|
||||
|
||||
# Docker (Tier 1 ContainerDetector, DockerHostResolver, CurrentContainerNetworkResolver, DockerRetry,
|
||||
# RetryingTarCopier, ContainerExec, ContainerReachableEndpoint, the io.floci.* label constants in
|
||||
# ContainerStorageHelper; Tier 2 ContainerBuilder, ContainerSpec, ContainerLifecycleManager,
|
||||
# ContainerStorageHelper, DockerClientProducer, PortAllocator, ContainerLogStreamer)
|
||||
io.floci.aws.core.common.docker.*
|
||||
# Replaced by the floci-core deployment module's native registration rather than moved.
|
||||
!io.floci.aws.core.common.docker.DockerJavaNativeSupport
|
||||
io.floci.aws.core.common.ContainerTeardown
|
||||
io.floci.aws.core.common.ContainerTeardowns
|
||||
io.floci.aws.core.common.port.PortAllocator
|
||||
|
||||
# DNS (Tier 1 DnsRecord, DnsAnswer, DnsRecordSource; Tier 2 EmbeddedDnsServer)
|
||||
io.floci.aws.core.common.dns.*
|
||||
|
||||
# TLS (Tier 1 CertificateMetadata; Tier 2)
|
||||
io.floci.aws.config.CertificateMetadata
|
||||
io.floci.aws.config.TlsProxyServer
|
||||
io.floci.aws.config.TlsConfigSource
|
||||
io.floci.aws.config.FlociCertificateAuthority
|
||||
io.floci.aws.config.TlsCertificateManager
|
||||
io.floci.aws.config.ServerCertificateRenewal
|
||||
io.floci.aws.config.ContainerCaBundle
|
||||
io.floci.aws.core.common.tls.*
|
||||
|
||||
# HTTP and runtime (Tier 1)
|
||||
io.floci.aws.config.ClockProducer
|
||||
io.floci.aws.config.HttpOptionsCustomizer
|
||||
io.floci.aws.core.common.GlobalCorsFilter
|
||||
io.floci.aws.core.common.JacksonConfig
|
||||
io.floci.aws.core.common.Resettable
|
||||
|
||||
# Lifecycle (Tier 1 InitLifecycleState; Tier 2 lifecycle and control plane)
|
||||
io.floci.aws.lifecycle.InitLifecycleState
|
||||
io.floci.aws.lifecycle.EmulatorLifecycle
|
||||
io.floci.aws.lifecycle.HealthController
|
||||
io.floci.aws.lifecycle.EmulatorInfoController
|
||||
io.floci.aws.lifecycle.ControlPlaneNotFoundFilter
|
||||
io.floci.aws.lifecycle.inithook.*
|
||||
|
||||
# Service registry SPI (Tier 2)
|
||||
io.floci.aws.core.common.ServiceRegistry
|
||||
io.floci.aws.core.common.ServiceDescriptor
|
||||
io.floci.aws.core.common.ServiceEnabledFilter
|
||||
io.floci.aws.core.common.ServiceConfigAccess
|
||||
|
||||
# Request plumbing (Tier 2)
|
||||
io.floci.aws.core.common.RequestContext
|
||||
io.floci.aws.core.common.RequestScopes
|
||||
io.floci.aws.core.common.ServiceProtocol
|
||||
|
||||
# XML (Tier 2)
|
||||
io.floci.aws.core.common.XmlBuilder
|
||||
io.floci.aws.core.common.XmlParser
|
||||
Reference in new issue
Block a user