refactor: 리펙토링 진행중 의존성 gradle은 얇게 유지, 각 모듈에서 처리하고 있는 부분에 대해서 리펙토링
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
plugins {
|
||||
id 'ca.spring-library'
|
||||
id 'ca.spring-config'
|
||||
}
|
||||
|
||||
// The Fileserver capability's cross-adapter assembly.
|
||||
//
|
||||
// It exists because one capability spans four leaves that must not see each other: the HTTP surface
|
||||
// in `adapter:inbound:web`, the storage and platform policy in `adapter:outbound:fileserver`, the
|
||||
// quota/recovery tables in `adapter:outbound:persistence-jpa`, and identifier generation. An
|
||||
// outbound adapter reaching an inbound one is the direction the architecture exists to forbid, so
|
||||
// something has to hold the assembly — and until now that something was the composition root, which
|
||||
// is why every application shipped Fileserver whether or not it wanted it.
|
||||
//
|
||||
// This module is not a composition root. It composes one capability; it does not run. What decides
|
||||
// whether an application ships Fileserver is one project dependency in `app-bootstrap/build.gradle`,
|
||||
// and its absence is enforced there by `dependencyPolicy`.
|
||||
//
|
||||
// It is deliberately thin: cross-adapter wiring only. A configuration that knows one leaf belongs to
|
||||
// that leaf — the fileserver platform's own settings, storage gateway, verification and security
|
||||
// wiring already moved into `adapter:outbound:fileserver` and must not come back here.
|
||||
dependencies {
|
||||
implementation project(':application-core')
|
||||
implementation project(':application-fileserver')
|
||||
implementation project(':shared-contract')
|
||||
implementation project(':adapter:inbound:web-fileserver')
|
||||
// The web platform itself as well, for `web.auth`: the admin plane composes the capability's
|
||||
// admin endpoints with the platform's authorization types. That edge is the reason this module
|
||||
// exists — an adapter reaching a sibling adapter is what it is here to take on.
|
||||
implementation project(':adapter:inbound:web')
|
||||
implementation project(':adapter:outbound:fileserver')
|
||||
implementation project(':adapter:outbound:persistence-fileserver')
|
||||
implementation project(':adapter:outbound:support')
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-autoconfigure'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||
implementation 'org.springframework:spring-jdbc'
|
||||
implementation 'org.springframework:spring-context'
|
||||
implementation 'org.slf4j:slf4j-api'
|
||||
// The cleanup worker logs structured key/value pairs. Same encoder the rest of the runtime uses.
|
||||
implementation libs.logstash.logback.encoder
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation 'org.springframework.boot:spring-boot-test'
|
||||
testImplementation 'ch.qos.logback:logback-classic'
|
||||
testImplementation libs.logstash.logback.encoder
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation libs.archunit.junit5
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
# This is a Gradle generated file for dependency locking.
|
||||
# Manual edits can break the build and are not advised.
|
||||
# This file is expected to be part of source control.
|
||||
biz.aQute.bnd:biz.aQute.bnd.annotation:7.1.0=compileClasspath,testCompileClasspath
|
||||
ch.qos.logback:logback-classic:1.5.38=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
ch.qos.logback:logback-core:1.5.38=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
com.fasterxml.jackson.core:jackson-annotations:2.21=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
com.fasterxml.jackson.core:jackson-core:2.21.5=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
com.fasterxml.jackson.core:jackson-databind:2.21.5=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.21.5=runtimeClasspath,testRuntimeClasspath
|
||||
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.21.5=runtimeClasspath,testRuntimeClasspath
|
||||
com.fasterxml.jackson:jackson-bom:2.21.5=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
com.fasterxml:classmate:1.7.3=runtimeClasspath,testRuntimeClasspath
|
||||
com.github.ben-manes.caffeine:caffeine:3.2.4=annotationProcessor,testAnnotationProcessor
|
||||
com.github.kevinstern:software-and-algorithms:1.0=annotationProcessor,testAnnotationProcessor
|
||||
com.github.spotbugs:spotbugs-annotations:4.10.2=spotbugs
|
||||
com.github.spotbugs:spotbugs:4.10.2=spotbugs
|
||||
com.github.stephenc.jcip:jcip-annotations:1.0-1=spotbugs
|
||||
com.google.auto.service:auto-service-annotations:1.0.1=annotationProcessor,testAnnotationProcessor
|
||||
com.google.auto.value:auto-value-annotations:1.9=annotationProcessor,testAnnotationProcessor
|
||||
com.google.auto:auto-common:1.2.2=annotationProcessor,testAnnotationProcessor
|
||||
com.google.code.findbugs:jsr305:3.0.2=checkstyle,spotbugs
|
||||
com.google.code.gson:gson:2.13.2=spotbugs
|
||||
com.google.errorprone:error_prone_annotation:2.49.0=annotationProcessor,testAnnotationProcessor
|
||||
com.google.errorprone:error_prone_annotations:2.38.0=compileClasspath,testCompileClasspath
|
||||
com.google.errorprone:error_prone_annotations:2.41.0=spotbugs
|
||||
com.google.errorprone:error_prone_annotations:2.47.0=checkstyle
|
||||
com.google.errorprone:error_prone_annotations:2.49.0=annotationProcessor,testAnnotationProcessor
|
||||
com.google.errorprone:error_prone_check_api:2.49.0=annotationProcessor,testAnnotationProcessor
|
||||
com.google.errorprone:error_prone_core:2.49.0=annotationProcessor,testAnnotationProcessor
|
||||
com.google.googlejavaformat:google-java-format:1.35.0=annotationProcessor,testAnnotationProcessor
|
||||
com.google.guava:failureaccess:1.0.3=annotationProcessor,checkstyle,testAnnotationProcessor
|
||||
com.google.guava:guava:33.5.0-jre=annotationProcessor,testAnnotationProcessor
|
||||
com.google.guava:guava:33.6.0-jre=checkstyle
|
||||
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=annotationProcessor,checkstyle,testAnnotationProcessor
|
||||
com.google.j2objc:j2objc-annotations:3.1=annotationProcessor,checkstyle,testAnnotationProcessor
|
||||
com.google.protobuf:protobuf-java:4.33.2=annotationProcessor,testAnnotationProcessor
|
||||
com.h3xstream.findsecbugs:findsecbugs-plugin:1.14.0=spotbugsPlugins
|
||||
com.jayway.jsonpath:json-path:2.10.0=testCompileClasspath,testRuntimeClasspath
|
||||
com.nimbusds:nimbus-jose-jwt:10.4=runtimeClasspath,testRuntimeClasspath
|
||||
com.puppycrawl.tools:checkstyle:13.5.0=checkstyle
|
||||
com.sun.istack:istack-commons-runtime:4.1.2=runtimeClasspath,testRuntimeClasspath
|
||||
com.tngtech.archunit:archunit-junit5-api:1.3.0=testCompileClasspath,testRuntimeClasspath
|
||||
com.tngtech.archunit:archunit-junit5-engine-api:1.3.0=testRuntimeClasspath
|
||||
com.tngtech.archunit:archunit-junit5-engine:1.3.0=testRuntimeClasspath
|
||||
com.tngtech.archunit:archunit-junit5:1.3.0=testCompileClasspath,testRuntimeClasspath
|
||||
com.tngtech.archunit:archunit:1.3.0=testCompileClasspath,testRuntimeClasspath
|
||||
com.vaadin.external.google:android-json:0.0.20131108.vaadin1=testCompileClasspath,testRuntimeClasspath
|
||||
com.zaxxer:HikariCP:7.0.2=runtimeClasspath,testRuntimeClasspath
|
||||
commons-beanutils:commons-beanutils:1.11.0=checkstyle
|
||||
commons-collections:commons-collections:3.2.2=checkstyle
|
||||
commons-io:commons-io:2.21.0=spotbugs
|
||||
commons-logging:commons-logging:1.3.6=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
info.picocli:picocli:4.7.7=checkstyle
|
||||
io.github.eisop:dataflow-errorprone:3.41.0-eisop1=annotationProcessor,testAnnotationProcessor
|
||||
io.github.java-diff-utils:java-diff-utils:4.12=annotationProcessor,testAnnotationProcessor
|
||||
io.micrometer:micrometer-commons:1.16.7=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
io.micrometer:micrometer-core:1.16.7=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
io.micrometer:micrometer-jakarta9:1.16.7=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
io.micrometer:micrometer-observation:1.16.7=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
io.projectreactor:reactor-core:3.8.7=runtimeClasspath,testRuntimeClasspath
|
||||
io.swagger.core.v3:swagger-annotations-jakarta:2.2.38=runtimeClasspath,testRuntimeClasspath
|
||||
io.swagger.core.v3:swagger-core-jakarta:2.2.38=runtimeClasspath,testRuntimeClasspath
|
||||
io.swagger.core.v3:swagger-models-jakarta:2.2.38=runtimeClasspath,testRuntimeClasspath
|
||||
jakarta.activation:jakarta.activation-api:2.1.4=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
jakarta.annotation:jakarta.annotation-api:3.0.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
jakarta.inject:jakarta.inject-api:2.0.1=runtimeClasspath,testRuntimeClasspath
|
||||
jakarta.persistence:jakarta.persistence-api:3.2.0=runtimeClasspath,testRuntimeClasspath
|
||||
jakarta.transaction:jakarta.transaction-api:2.0.1=runtimeClasspath,testRuntimeClasspath
|
||||
jakarta.validation:jakarta.validation-api:3.1.1=runtimeClasspath,testRuntimeClasspath
|
||||
jakarta.xml.bind:jakarta.xml.bind-api:4.0.5=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
javax.inject:javax.inject:1=annotationProcessor,testAnnotationProcessor
|
||||
jaxen:jaxen:2.0.6=spotbugs
|
||||
net.bytebuddy:byte-buddy-agent:1.17.8=testCompileClasspath,testRuntimeClasspath
|
||||
net.bytebuddy:byte-buddy:1.17.8=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
net.logstash.logback:logstash-logback-encoder:8.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
net.minidev:accessors-smart:2.6.0=testCompileClasspath,testRuntimeClasspath
|
||||
net.minidev:json-smart:2.6.0=testCompileClasspath,testRuntimeClasspath
|
||||
net.sf.saxon:Saxon-HE:12.9=checkstyle,spotbugs
|
||||
org.antlr:antlr4-runtime:4.13.2=checkstyle,runtimeClasspath,testRuntimeClasspath
|
||||
org.apache.bcel:bcel:6.12.0=spotbugs
|
||||
org.apache.commons:commons-lang3:3.20.0=checkstyle,runtimeClasspath,spotbugs,testRuntimeClasspath
|
||||
org.apache.commons:commons-text:1.15.0=spotbugs
|
||||
org.apache.commons:commons-text:1.3=checkstyle
|
||||
org.apache.httpcomponents:httpclient:4.5.13=checkstyle
|
||||
org.apache.httpcomponents:httpcore:4.4.16=checkstyle
|
||||
org.apache.logging.log4j:log4j-api:2.25.5=compileClasspath,runtimeClasspath,spotbugs,testCompileClasspath,testRuntimeClasspath
|
||||
org.apache.logging.log4j:log4j-core:2.25.5=spotbugs
|
||||
org.apache.logging.log4j:log4j-to-slf4j:2.25.5=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.apache.maven.doxia:doxia-core:1.12.0=checkstyle
|
||||
org.apache.maven.doxia:doxia-logging-api:1.12.0=checkstyle
|
||||
org.apache.maven.doxia:doxia-module-xdoc:1.12.0=checkstyle
|
||||
org.apache.maven.doxia:doxia-sink-api:1.12.0=checkstyle
|
||||
org.apache.tomcat.embed:tomcat-embed-core:11.0.24=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.apache.tomcat.embed:tomcat-embed-el:11.0.24=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.apache.tomcat.embed:tomcat-embed-websocket:11.0.24=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.apache.xbean:xbean-reflect:3.7=checkstyle
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath
|
||||
org.aspectj:aspectjweaver:1.9.25.1=runtimeClasspath,testRuntimeClasspath
|
||||
org.assertj:assertj-core:3.27.7=testCompileClasspath,testRuntimeClasspath
|
||||
org.awaitility:awaitility:4.3.0=testCompileClasspath,testRuntimeClasspath
|
||||
org.codehaus.plexus:plexus-classworlds:2.6.0=checkstyle
|
||||
org.codehaus.plexus:plexus-component-annotations:2.1.0=checkstyle
|
||||
org.codehaus.plexus:plexus-container-default:2.1.0=checkstyle
|
||||
org.codehaus.plexus:plexus-utils:3.3.0=checkstyle
|
||||
org.dom4j:dom4j:2.2.0=spotbugs
|
||||
org.eclipse.angus:angus-activation:2.0.3=runtimeClasspath,testRuntimeClasspath
|
||||
org.glassfish.jaxb:jaxb-core:4.0.9=runtimeClasspath,testRuntimeClasspath
|
||||
org.glassfish.jaxb:jaxb-runtime:4.0.9=runtimeClasspath,testRuntimeClasspath
|
||||
org.glassfish.jaxb:txw2:4.0.9=runtimeClasspath,testRuntimeClasspath
|
||||
org.hamcrest:hamcrest:3.0=testCompileClasspath,testRuntimeClasspath
|
||||
org.hdrhistogram:HdrHistogram:2.2.2=runtimeClasspath,testRuntimeClasspath
|
||||
org.hibernate.models:hibernate-models:1.0.1=runtimeClasspath,testRuntimeClasspath
|
||||
org.hibernate.orm:hibernate-core:7.2.24.Final=runtimeClasspath,testRuntimeClasspath
|
||||
org.hibernate.validator:hibernate-validator:9.0.1.Final=runtimeClasspath,testRuntimeClasspath
|
||||
org.javassist:javassist:3.28.0-GA=checkstyle
|
||||
org.jboss.logging:jboss-logging:3.6.3.Final=runtimeClasspath,testRuntimeClasspath
|
||||
org.jspecify:jspecify:1.0.1=annotationProcessor,checkstyle,compileClasspath,runtimeClasspath,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath
|
||||
org.junit.jupiter:junit-jupiter-api:6.0.3=testCompileClasspath,testRuntimeClasspath
|
||||
org.junit.jupiter:junit-jupiter-engine:6.0.3=testRuntimeClasspath
|
||||
org.junit.jupiter:junit-jupiter-params:6.0.3=testCompileClasspath,testRuntimeClasspath
|
||||
org.junit.jupiter:junit-jupiter:6.0.3=testCompileClasspath,testRuntimeClasspath
|
||||
org.junit.platform:junit-platform-commons:6.0.3=testCompileClasspath,testRuntimeClasspath
|
||||
org.junit.platform:junit-platform-engine:6.0.3=testRuntimeClasspath
|
||||
org.junit.platform:junit-platform-launcher:6.0.3=testRuntimeClasspath
|
||||
org.junit:junit-bom:6.0.3=testCompileClasspath,testRuntimeClasspath
|
||||
org.junit:junit-bom:6.1.0=spotbugs
|
||||
org.latencyutils:LatencyUtils:2.0.3=runtimeClasspath,testRuntimeClasspath
|
||||
org.mockito:mockito-core:5.20.0=mockitoAgent,testCompileClasspath,testRuntimeClasspath
|
||||
org.mockito:mockito-junit-jupiter:5.20.0=testCompileClasspath,testRuntimeClasspath
|
||||
org.objenesis:objenesis:3.3=testRuntimeClasspath
|
||||
org.openapitools:jackson-databind-nullable:0.2.6=runtimeClasspath,testRuntimeClasspath
|
||||
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testRuntimeClasspath
|
||||
org.osgi:org.osgi.annotation.bundle:2.0.0=compileClasspath,testCompileClasspath
|
||||
org.osgi:org.osgi.annotation.versioning:1.1.2=compileClasspath,testCompileClasspath
|
||||
org.osgi:org.osgi.resource:1.0.0=compileClasspath,testCompileClasspath
|
||||
org.osgi:org.osgi.service.serviceloader:1.0.0=compileClasspath,testCompileClasspath
|
||||
org.ow2.asm:asm-analysis:9.10.1=spotbugs
|
||||
org.ow2.asm:asm-commons:9.10.1=spotbugs
|
||||
org.ow2.asm:asm-tree:9.10.1=spotbugs
|
||||
org.ow2.asm:asm-util:9.10.1=spotbugs
|
||||
org.ow2.asm:asm:9.10.1=spotbugs
|
||||
org.ow2.asm:asm:9.7.1=testCompileClasspath,testRuntimeClasspath
|
||||
org.pcollections:pcollections:4.0.1=annotationProcessor,testAnnotationProcessor
|
||||
org.reactivestreams:reactive-streams:1.0.4=runtimeClasspath,testRuntimeClasspath
|
||||
org.reflections:reflections:0.10.2=checkstyle
|
||||
org.skyscreamer:jsonassert:1.5.3=testCompileClasspath,testRuntimeClasspath
|
||||
org.slf4j:jul-to-slf4j:2.0.18=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.slf4j:slf4j-api:2.0.18=compileClasspath,runtimeClasspath,spotbugs,spotbugsSlf4j,testCompileClasspath,testRuntimeClasspath
|
||||
org.slf4j:slf4j-simple:2.0.17=spotbugsSlf4j
|
||||
org.slf4j:slf4j-simple:2.0.18=checkstyle
|
||||
org.springdoc:springdoc-openapi-starter-common:3.0.0=runtimeClasspath,testRuntimeClasspath
|
||||
org.springdoc:springdoc-openapi-starter-webmvc-api:3.0.0=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-actuator-autoconfigure:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-actuator:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-autoconfigure:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-configuration-processor:4.0.8=annotationProcessor
|
||||
org.springframework.boot:spring-boot-data-commons:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-data-jpa:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-health:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-hibernate:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-http-converter:4.0.8=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-jackson:4.0.8=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-jdbc:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-jpa:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-micrometer-metrics:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-micrometer-observation:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-persistence:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-resttestclient:4.0.8=testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-security-oauth2-resource-server:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-security:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-servlet:4.0.8=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-sql:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-actuator:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-data-jpa:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-jackson-test:4.0.8=testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-jackson:4.0.8=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-jdbc:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-logging:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-micrometer-metrics:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-oauth2-resource-server:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-security:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-test:4.0.8=testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-tomcat-runtime:4.0.8=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-tomcat:4.0.8=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-validation:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-web:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-webmvc-test:4.0.8=testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter-webmvc:4.0.8=testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-starter:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-test-autoconfigure:4.0.8=testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-test:4.0.8=testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-tomcat:4.0.8=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-transaction:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-validation:4.0.8=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-web-server:4.0.8=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-webmvc-test:4.0.8=testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot-webmvc:4.0.8=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.boot:spring-boot:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework.data:spring-data-commons:4.0.7=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.data:spring-data-jpa:4.0.7=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.security:spring-security-config:7.0.7=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.security:spring-security-core:7.0.7=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.security:spring-security-crypto:7.0.7=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.security:spring-security-oauth2-core:7.0.7=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.security:spring-security-oauth2-jose:7.0.7=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.security:spring-security-oauth2-resource-server:7.0.7=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.security:spring-security-web:7.0.7=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework.session:spring-session-core:4.0.5=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework:spring-aop:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework:spring-aspects:7.0.9=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework:spring-beans:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework:spring-context:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework:spring-core:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework:spring-expression:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework:spring-jdbc:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework:spring-orm:7.0.9=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework:spring-test:7.0.9=testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework:spring-tx:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework:spring-web:7.0.9=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.springframework:spring-webflux:7.0.9=runtimeClasspath,testRuntimeClasspath
|
||||
org.springframework:spring-webmvc:7.0.9=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.xmlresolver:xmlresolver:5.3.3=checkstyle,spotbugs
|
||||
org.xmlunit:xmlunit-core:2.10.4=testCompileClasspath,testRuntimeClasspath
|
||||
org.yaml:snakeyaml:2.5=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
tools.jackson.core:jackson-core:3.1.5=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
tools.jackson.core:jackson-databind:3.1.5=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
tools.jackson:jackson-bom:3.1.5=runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
empty=
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.admin.FileserverAdminController;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* Serves the management plane from the management context, not the public one.
|
||||
*
|
||||
* <p>{@code /internal/fileserver/**} was a set of ordinary controller routes on the application
|
||||
* connector. A role check kept unauthorised callers out, but the surface was still reachable by
|
||||
* anything that could open a socket to the public port — which means every misconfigured ingress,
|
||||
* every port-forward, and every future route added to this controller without its own guard.
|
||||
*
|
||||
* <p>Registered as a management-context configuration instead, so when a deployment gives the
|
||||
* management server its own port the admin routes move with it and never appear on the public
|
||||
* listener at all. Boot falls back to the same context when the ports are equal, which is why the
|
||||
* role gate contributed by {@link FileserverAdminPlaneConfiguration} stays: the two guards cover
|
||||
* different deployments rather than duplicating each other.
|
||||
*
|
||||
* <p>The management context is a child of the application context, so the admin service, the policy
|
||||
* and the audit port are all inherited rather than rebuilt.
|
||||
*/
|
||||
@ManagementContextConfiguration(value = ManagementContextType.ANY, proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(
|
||||
prefix = "app.fileserver-platform",
|
||||
name = {"enabled", "admin.enabled"},
|
||||
havingValue = "true")
|
||||
@Import(FileserverAdminController.class)
|
||||
public class FileserverAdminManagementContextConfiguration {}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import dev.caskeleton.adapter.inbound.web.auth.RestrictedPathRule;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Puts the management plane behind the admin role at the transport, not only in application policy.
|
||||
*
|
||||
* <p>The base chain ends in {@code anyRequest().authenticated()}. Under it, {@code
|
||||
* /internal/fileserver/**} was reachable by every authenticated caller, and the only thing standing
|
||||
* between an ordinary user and a force-delete was an authorization check inside the service. That
|
||||
* check is real, but it runs after the request has been accepted, parsed and dispatched — and any
|
||||
* future admin endpoint that forgets to call it is open.
|
||||
*
|
||||
* <p>The roles come from the same setting the application policy uses, so the two cannot describe
|
||||
* different administrators.
|
||||
*
|
||||
* <p>This is the in-process half of the isolation. Serving the management plane on a separate port
|
||||
* or network remains an operational requirement — see the module README — because a shared port
|
||||
* still exposes the surface to anything that can reach the public listener.
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(
|
||||
prefix = "app.fileserver-platform.admin",
|
||||
name = "enabled",
|
||||
havingValue = "true")
|
||||
public class FileserverAdminPlaneConfiguration {
|
||||
|
||||
/** Every route the admin controller owns lives under this prefix. */
|
||||
static final String ADMIN_PATH_PATTERN = "/internal/fileserver/**";
|
||||
|
||||
@Bean
|
||||
RestrictedPathRule fileserverAdminPathRule(FileserverPlatformSettings settings) {
|
||||
return new RestrictedPathRule(ADMIN_PATH_PATTERN, settings.security().adminRoles());
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import dev.caskeleton.application.fileserver.cleanup.CleanupService;
|
||||
import java.time.Duration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
|
||||
/**
|
||||
* Runs reclamation in the background when a deployment opts in.
|
||||
*
|
||||
* <p>Separate from the cleanup service itself, which the admin plane also drives on demand. The
|
||||
* service decides what may be deleted; this decides only whether anything drives it unattended, and
|
||||
* that is a deployment's call — a node without the worker still queues cleanup items, and another
|
||||
* node or an operator reclaims them.
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableScheduling
|
||||
@ConditionalOnProperty(
|
||||
prefix = "app.fileserver-platform.cleanup",
|
||||
name = "enabled",
|
||||
havingValue = "true")
|
||||
public class FileserverCleanupConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
FileserverCleanupWorker fileserverCleanupWorker(
|
||||
CleanupService cleanupService, FileserverPlatformSettings settings) {
|
||||
return new FileserverCleanupWorker(
|
||||
cleanupService, settings.cleanup().maxItems(), settings.cleanup().maxBytes().toBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the batch schedule from the bound interval.
|
||||
*
|
||||
* <p>Programmatic rather than a {@code @Scheduled} placeholder on the worker: a placeholder
|
||||
* carries its own default, so the interval would have two owners with two defaults and no way to
|
||||
* tell from the outside which one a running node used.
|
||||
*
|
||||
* <p>Fixed <em>delay</em>, not fixed rate. A batch that runs long because storage is slow must
|
||||
* not have the next one queued behind it; under a fixed rate a degraded volume turns into an
|
||||
* accumulating backlog of invocations.
|
||||
*/
|
||||
@Bean
|
||||
SchedulingConfigurer fileserverCleanupSchedule(
|
||||
FileserverCleanupWorker worker, FileserverPlatformSettings settings) {
|
||||
Duration interval = settings.cleanup().interval();
|
||||
return registrar -> registrar.addFixedDelayTask(worker::runBatch, interval);
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import static net.logstash.logback.argument.StructuredArguments.kv;
|
||||
|
||||
import dev.caskeleton.application.fileserver.cleanup.CleanupBatchResult;
|
||||
import dev.caskeleton.application.fileserver.cleanup.CleanupService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Drives the bounded cleanup batch on a fixed delay.
|
||||
*
|
||||
* <p>Fixed <em>delay</em>, not fixed rate: a batch that runs long because storage is slow must not
|
||||
* have the next one queued behind it. Under fixed rate a degraded volume would accumulate pending
|
||||
* invocations and turn a slow filesystem into a thread-pool outage.
|
||||
*
|
||||
* <p>The batch bounds itself by item count and by bytes, so one invocation cannot monopolise the
|
||||
* scheduler however much work is queued. Whatever it does not reach stays queued for the next run.
|
||||
*
|
||||
* <p>A failing batch is logged and swallowed. An escaping exception cancels a scheduled task
|
||||
* permanently, which would silently stop all reclamation after one bad object — the failure mode
|
||||
* this worker exists to prevent.
|
||||
*
|
||||
* <p>The schedule itself is registered by {@link FileserverCleanupConfiguration} from the bound
|
||||
* interval rather than declared here with a property placeholder. Two declarations of the same
|
||||
* interval — one typed and validated, one a raw string with its own default — is one declaration
|
||||
* too many: they drift, and the one that wins is whichever the scheduler happened to read.
|
||||
*/
|
||||
public class FileserverCleanupWorker {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FileserverCleanupWorker.class);
|
||||
|
||||
private final CleanupService cleanupService;
|
||||
private final int maxItems;
|
||||
private final long maxBytes;
|
||||
|
||||
public FileserverCleanupWorker(CleanupService cleanupService, int maxItems, long maxBytes) {
|
||||
if (maxItems < 1 || maxBytes < 1) {
|
||||
throw new IllegalArgumentException("cleanup batch bounds must be positive");
|
||||
}
|
||||
this.cleanupService = cleanupService;
|
||||
this.maxItems = maxItems;
|
||||
this.maxBytes = maxBytes;
|
||||
}
|
||||
|
||||
public void runBatch() {
|
||||
try {
|
||||
CleanupBatchResult result = cleanupService.runBatch(maxItems, maxBytes);
|
||||
if (result.deleted() > 0 || result.failed() > 0) {
|
||||
LOG.info(
|
||||
"fileserver.cleanup deleted={} skippedActiveLease={} skippedStateChanged={} "
|
||||
+ "failed={} reclaimedBytes={}",
|
||||
result.deleted(),
|
||||
result.skippedActiveLease(),
|
||||
result.skippedStateChanged(),
|
||||
result.failed(),
|
||||
result.reclaimedBytes(),
|
||||
kv("capability", "fileserver"),
|
||||
kv("operation", "cleanup"),
|
||||
kv("cleanup.deleted", result.deleted()),
|
||||
kv("cleanup.skipped_active_lease", result.skippedActiveLease()),
|
||||
kv("cleanup.skipped_state_changed", result.skippedStateChanged()),
|
||||
kv("cleanup.failed", result.failed()),
|
||||
kv("cleanup.reclaimed_bytes", result.reclaimedBytes()));
|
||||
}
|
||||
} catch (RuntimeException failure) {
|
||||
LOG.warn(
|
||||
"fileserver.cleanup batch failed; the next run retries the same queue",
|
||||
kv("capability", "fileserver"),
|
||||
kv("operation", "cleanup"),
|
||||
kv("warning.kind", "scheduled-task-failed"),
|
||||
kv("retry.disposition", "next-run"),
|
||||
failure);
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.config.FileserverWebProperties;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.config.TransferExecutorProperties;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import dev.caskeleton.application.fileserver.api.StorageNamespace;
|
||||
import dev.caskeleton.application.fileserver.upload.UploadPolicy;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
class FileserverCorePolicyConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
FileserverWebProperties fileserverWebProperties(FileserverPlatformSettings properties) {
|
||||
return new FileserverWebProperties(
|
||||
StorageNamespace.of(properties.defaultNamespace()),
|
||||
properties.upload().ttl(),
|
||||
properties.upload().maxParts(),
|
||||
properties.upload().requireContentLength());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
TransferExecutorProperties fileserverTransferExecutorProperties(
|
||||
FileserverPlatformSettings properties) {
|
||||
return new TransferExecutorProperties(
|
||||
properties.transfer().coreSize(),
|
||||
properties.transfer().maxSize(),
|
||||
properties.transfer().queueCapacity(),
|
||||
properties.transfer().awaitSeconds());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
UploadPolicy fileserverUploadPolicy(FileserverPlatformSettings properties) {
|
||||
return new UploadPolicy(
|
||||
properties.upload().maxFileSize().toBytes(),
|
||||
properties.upload().initialReservation().toBytes(),
|
||||
properties.upload().reservationTtl(),
|
||||
properties.upload().leaseDuration());
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.http.DefaultHttpRangeResolver;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.http.HttpContentDispositionFactory;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.http.HttpDownloadPlanner;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.http.HttpDownloadPolicy;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.http.HttpRangePolicy;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.http.HttpRangeResolver;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.http.MvcConditionalRequestFactory;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.http.MvcDownloadResponseWriter;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.http.ZeroCopyEligibility;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/** HTTP-only download policy and rendering helpers. */
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
class FileserverHttpDownloadConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
MvcConditionalRequestFactory fileserverConditionalRequestFactory() {
|
||||
return new MvcConditionalRequestFactory();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
HttpRangeResolver fileserverHttpRangeResolver() {
|
||||
return new DefaultHttpRangeResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
HttpContentDispositionFactory fileserverHttpContentDispositionFactory() {
|
||||
return new HttpContentDispositionFactory();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
HttpDownloadPolicy fileserverHttpDownloadPolicy(FileserverPlatformSettings properties) {
|
||||
HttpRangePolicy rangePolicy =
|
||||
properties.download().maxRanges() <= 1
|
||||
? HttpRangePolicy.single(properties.download().maxRangeBytes().toBytes())
|
||||
: HttpRangePolicy.multi(
|
||||
properties.download().maxRanges(), properties.download().maxRangeBytes().toBytes());
|
||||
return new HttpDownloadPolicy(
|
||||
rangePolicy, properties.download().cacheControl(), properties.download().inlineAllowed());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
HttpDownloadPlanner fileserverHttpDownloadPlanner(
|
||||
HttpRangeResolver rangeResolver,
|
||||
HttpContentDispositionFactory dispositionFactory,
|
||||
HttpDownloadPolicy policy) {
|
||||
return new HttpDownloadPlanner(rangeResolver, dispositionFactory, policy);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
MvcDownloadResponseWriter fileserverDownloadResponseWriter() {
|
||||
return new MvcDownloadResponseWriter();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
ZeroCopyEligibility fileserverZeroCopyEligibility(FileserverPlatformSettings properties) {
|
||||
return new ZeroCopyEligibility(
|
||||
properties.download().zeroCopyEnabled(),
|
||||
properties.download().zeroCopyMinimumBytes().toBytes());
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.local.LocalBlockingContentStore;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.local.LocalStorageCapabilityProbe;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.local.LocalStorageProbeResult;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.local.LocalStorageProperties;
|
||||
import dev.caskeleton.adapter.outbound.persistence.fileserver.FileserverSchemaActivation;
|
||||
import dev.caskeleton.adapter.outbound.support.CapabilityStartupValidationException;
|
||||
import dev.caskeleton.application.fileserver.api.content.PublishMode;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
class FileserverLocalStorageCoreConfiguration {
|
||||
|
||||
/**
|
||||
* The three storage invariants are pinned, not configured.
|
||||
*
|
||||
* <p>Staging and content on one file store, a refusal to follow symbolic links, and a force
|
||||
* before publish are what make an atomic publish atomic and a namespace a boundary. A deployment
|
||||
* that could switch them off would be running a different capability under the same name and the
|
||||
* same tests, so they are constants here rather than settings.
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
LocalStorageProperties fileserverStorageProperties(FileserverPlatformSettings settings) {
|
||||
FileserverPlatformSettings.Storage storage = settings.storage();
|
||||
requireStorageRootIsIsolated(storage);
|
||||
return new LocalStorageProperties(
|
||||
storage.root(),
|
||||
publishMode(storage.publishMode()),
|
||||
true,
|
||||
true,
|
||||
(int) storage.bufferSize().toBytes(),
|
||||
settings.upload().maxFileSize().toBytes(),
|
||||
true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refuses to start until the Fileserver schema stream is applied and promoted.
|
||||
*
|
||||
* <p>Paired with the storage probe below: one proves the volume can hold the bytes, the other
|
||||
* proves the database sanctions the records. A capability that starts with either unproven fails
|
||||
* on a user's first upload instead of on the deployment that caused it.
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(JdbcOperations.class)
|
||||
FileserverSchemaActivation fileserverSchemaActivation(JdbcOperations jdbc) {
|
||||
FileserverSchemaActivation activation = new FileserverSchemaActivation(jdbc);
|
||||
activation.requireActive();
|
||||
return activation;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
LocalStorageProbeResult fileserverStorageProbeResult(LocalStorageProperties properties) {
|
||||
LocalStorageProbeResult result = new LocalStorageCapabilityProbe(properties).run();
|
||||
if (!result.mandatoryChecksPassed()) {
|
||||
throw new CapabilityStartupValidationException(
|
||||
"fileserver storage root failed a mandatory capability probe: "
|
||||
+ result.failures()
|
||||
+ "; the capability refuses to start rather than publish files it cannot place "
|
||||
+ "atomically");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
LocalBlockingContentStore fileserverContentStore(
|
||||
LocalStorageProperties properties, LocalStorageProbeResult probeResult) {
|
||||
return new LocalBlockingContentStore(properties, probeResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refuses a storage root that overlaps something the process already serves or reads.
|
||||
*
|
||||
* <p>A root under a web root turns every upload into a published file; a root under a
|
||||
* configuration directory turns one into a configuration change. Both are checked here because
|
||||
* the path is only known once, at binding time.
|
||||
*/
|
||||
private static void requireStorageRootIsIsolated(FileserverPlatformSettings.Storage storage) {
|
||||
Path root = storage.root().toAbsolutePath().normalize();
|
||||
for (Path forbidden : storage.forbiddenRootAncestors()) {
|
||||
Path ancestor = forbidden.toAbsolutePath().normalize();
|
||||
if (root.startsWith(ancestor)) {
|
||||
throw new CapabilityStartupValidationException(
|
||||
"fileserver storage root must not live under a configured forbidden ancestor");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static PublishMode publishMode(String configured) {
|
||||
String canonical = configured.trim().toUpperCase(Locale.ROOT).replace('-', '_');
|
||||
try {
|
||||
return PublishMode.valueOf(canonical);
|
||||
} catch (IllegalArgumentException unknown) {
|
||||
throw new CapabilityStartupValidationException(
|
||||
FileserverPlatformSettings.PREFIX
|
||||
+ ".storage.publish-mode must be one of atomic-move-required, "
|
||||
+ "atomic-move-preferred, metadata-pointer",
|
||||
unknown);
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.nginx.DefaultNginxInternalUriMapper;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.nginx.NginxDelegationProperties;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.nginx.NginxDownloadStrategy;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.nginx.NginxInternalUriMapper;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
class FileserverNginxConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
NginxDelegationProperties fileserverNginxDelegationProperties(
|
||||
FileserverPlatformSettings properties) {
|
||||
return new NginxDelegationProperties(
|
||||
properties.nginx().enabled(),
|
||||
properties.nginx().internalPrefix(),
|
||||
properties.nginx().objectSuffix(),
|
||||
properties.nginx().minimumSize().toBytes());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
NginxInternalUriMapper fileserverNginxInternalUriMapper(NginxDelegationProperties properties) {
|
||||
return new DefaultNginxInternalUriMapper(properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
NginxDownloadStrategy fileserverNginxDownloadStrategy(
|
||||
NginxDelegationProperties properties, NginxInternalUriMapper uriMapper) {
|
||||
return new NginxDownloadStrategy(properties, uriMapper);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* The Fileserver platform's application-owned half: the HTTP surface and startup policy.
|
||||
*
|
||||
* <p>This used to import nineteen further configurations that assembled {@code
|
||||
* adapter:outbound:fileserver}'s own storage, verification, upload and cleanup graph. Those moved
|
||||
* into that leaf, behind its own {@code FileserverCapabilityAutoConfiguration}, so the composition
|
||||
* root no longer names a capability's implementation classes — it composes the HTTP transport,
|
||||
* which is {@code adapter:inbound:web}'s, with the leaf's published beans.
|
||||
*
|
||||
* <p>Ordering is by bean dependency, not by {@code @AutoConfiguration(after = ...)} naming a leaf
|
||||
* type. Spring resolves {@code FileserverPlatformSettings} whichever order the two roots are
|
||||
* processed in, and an {@code after} pointing at a leaf-internal class is exactly the
|
||||
* export-surface hole the architecture suite rejects.
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@ConditionalOnProperty(
|
||||
prefix = FileserverPlatformSettings.PREFIX,
|
||||
name = "enabled",
|
||||
havingValue = "true")
|
||||
@Import({
|
||||
FileserverCorePolicyConfiguration.class,
|
||||
FileserverWebAssemblyConfiguration.class,
|
||||
FileserverHttpDownloadConfiguration.class,
|
||||
FileserverNginxConfiguration.class,
|
||||
FileserverProtocolConfiguration.class,
|
||||
FileserverAdminPlaneConfiguration.class,
|
||||
FileserverStartupConfiguration.class,
|
||||
// Three that could not move: they compose a sibling adapter into the capability — the JPA
|
||||
// metadata store, the identifier generator — or use the repository's structured-logging
|
||||
// arguments, which this leaf's dependency allowance does not include. Composing two adapters is
|
||||
// the composition root's job by definition, so these are where they belong rather than where
|
||||
// they were left.
|
||||
FileserverLocalStorageCoreConfiguration.class,
|
||||
FileserverUploadServiceConfiguration.class,
|
||||
FileserverCleanupConfiguration.class
|
||||
})
|
||||
public class FileserverPlatformAutoConfiguration {}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.draft12.Draft12Properties;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.tus.TusChecksumVerifier;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.tus.TusProperties;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.tus.TusRequestParser;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import java.util.List;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
class FileserverProtocolConfiguration {
|
||||
|
||||
/**
|
||||
* tus support objects, contributed only when both this switch and the master switch are on.
|
||||
*
|
||||
* <p>The nesting is the fix: previously the protocol's own flag was the only condition, so
|
||||
* enabling tus in a deployment with the Fileserver off produced a controller with no service
|
||||
* behind it.
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty(
|
||||
prefix = FileserverPlatformSettings.PREFIX + ".tus",
|
||||
name = "enabled",
|
||||
havingValue = "true")
|
||||
TusProperties fileserverTusProperties(FileserverPlatformSettings properties) {
|
||||
return new TusProperties(
|
||||
TusProperties.RESUMABLE_VERSION,
|
||||
List.of("creation", "expiration", "checksum", "termination"),
|
||||
properties.upload().maxFileSize().toBytes(),
|
||||
properties.upload().ttl());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty(
|
||||
prefix = FileserverPlatformSettings.PREFIX + ".tus",
|
||||
name = "enabled",
|
||||
havingValue = "true")
|
||||
TusRequestParser fileserverTusRequestParser(TusProperties tusProperties) {
|
||||
return new TusRequestParser(tusProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty(
|
||||
prefix = FileserverPlatformSettings.PREFIX + ".tus",
|
||||
name = "enabled",
|
||||
havingValue = "true")
|
||||
TusChecksumVerifier fileserverTusChecksumVerifier() {
|
||||
return new TusChecksumVerifier();
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings for the experimental draft, which previously had no production binding at all.
|
||||
*
|
||||
* <p>The controller existed and could be switched on, but nothing built the properties it needs,
|
||||
* so the switch produced a startup failure rather than a protocol.
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty(
|
||||
prefix = FileserverPlatformSettings.PREFIX + ".httpbis-draft12",
|
||||
name = "enabled",
|
||||
havingValue = "true")
|
||||
Draft12Properties fileserverDraft12Properties(FileserverPlatformSettings properties) {
|
||||
return new Draft12Properties(
|
||||
true, properties.upload().maxFileSize().toBytes(), properties.upload().ttl(), false);
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.nginx.NginxInternalUriMapper;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverStartupCheck;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverStartupValidator;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.local.LocalStorageProbeResult;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.local.LocalStorageProperties;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.security.UnenforcedFileAccessPolicy;
|
||||
import dev.caskeleton.adapter.outbound.support.runtime.RuntimeProfileSnapshot;
|
||||
import dev.caskeleton.application.fileserver.api.metadata.FileMetadataStore;
|
||||
import dev.caskeleton.application.fileserver.api.security.FileAccessPolicy;
|
||||
import dev.caskeleton.application.fileserver.upload.FileVerificationService;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* Runs the fail-closed startup gate against the graph that was actually assembled.
|
||||
*
|
||||
* <p>The validator existed but nothing in the production graph called it, so every claim it makes —
|
||||
* a shared metadata store behind a multi-instance deployment, a verifier behind a scanner
|
||||
* requirement, no allow-all policy in production, a proven Nginx mapping — was a documented
|
||||
* intention rather than an enforced one. Wiring it as a bean whose construction depends on the
|
||||
* things it inspects is what turns those back into startup conditions.
|
||||
*
|
||||
* <p>The Nginx mapping is attested rather than asserted: the gate asks the mapper to produce an
|
||||
* internal URI and checks the answer, instead of reading a boolean in which a deployment claims its
|
||||
* own configuration is correct.
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class FileserverStartupConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
FileserverStartupValidator fileserverStartupValidator() {
|
||||
return new FileserverStartupValidator();
|
||||
}
|
||||
|
||||
/**
|
||||
* The gate itself, expressed as a bean so its dependencies are its preconditions.
|
||||
*
|
||||
* <p>Spring cannot create it until the storage probe, the authorization policy, the metadata
|
||||
* store, and the verifier exist, which is exactly the set of facts the check needs.
|
||||
*/
|
||||
@Bean
|
||||
FileserverStartupCheck fileserverStartupCheck(
|
||||
FileserverStartupValidator validator,
|
||||
FileserverPlatformSettings settings,
|
||||
LocalStorageProperties storageProperties,
|
||||
LocalStorageProbeResult probeResult,
|
||||
FileAccessPolicy accessPolicy,
|
||||
FileMetadataStore metadataStore,
|
||||
FileVerificationService verificationService,
|
||||
NginxInternalUriMapper nginxUriMapper,
|
||||
Environment environment) {
|
||||
FileserverStartupCheck check =
|
||||
new FileserverStartupCheck(
|
||||
storageProperties.publishMode(),
|
||||
probeResult,
|
||||
storageProperties.root(),
|
||||
settings.storage().forbiddenRootAncestors(),
|
||||
!"local-node".equals(settings.instanceId()),
|
||||
metadataStore != null,
|
||||
isProductionProfile(environment),
|
||||
accessPolicy instanceof UnenforcedFileAccessPolicy,
|
||||
settings.verification().requireMediaTypeVerdict(),
|
||||
verificationService != null,
|
||||
settings.nginx().enabled(),
|
||||
nginxMappingHolds(settings, nginxUriMapper));
|
||||
validator.validate(check);
|
||||
return check;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proves the internal mapping by exercising it rather than by trusting a flag.
|
||||
*
|
||||
* <p>A delegation whose internal prefix does not round-trip answers a 200 with an empty body,
|
||||
* which is the worst possible failure: the client believes it has the file.
|
||||
*/
|
||||
private static boolean nginxMappingHolds(
|
||||
FileserverPlatformSettings settings, NginxInternalUriMapper uriMapper) {
|
||||
if (!settings.nginx().enabled()) {
|
||||
return true;
|
||||
}
|
||||
return uriMapper.attestMapping();
|
||||
}
|
||||
|
||||
private static boolean isProductionProfile(Environment environment) {
|
||||
return RuntimeProfileSnapshot.from(environment).isProduction();
|
||||
}
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverMetricsSupport;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.identifier.RandomUploadIdentifierFactory;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.local.LocalBlockingContentStore;
|
||||
import dev.caskeleton.application.fileserver.api.metadata.FileMetadataStore;
|
||||
import dev.caskeleton.application.fileserver.api.metadata.FileQuotaService;
|
||||
import dev.caskeleton.application.fileserver.api.metadata.UploadSessionStore;
|
||||
import dev.caskeleton.application.fileserver.api.security.FileAccessPolicy;
|
||||
import dev.caskeleton.application.fileserver.api.security.OriginalFilenamePolicy;
|
||||
import dev.caskeleton.application.fileserver.cleanup.CleanupQueue;
|
||||
import dev.caskeleton.application.fileserver.concurrency.DefaultWriterLeaseCoordinator;
|
||||
import dev.caskeleton.application.fileserver.concurrency.WriterLeaseCoordinator;
|
||||
import dev.caskeleton.application.fileserver.observability.FileserverMetricsPort;
|
||||
import dev.caskeleton.application.fileserver.quota.DefaultTransferAdmissionController;
|
||||
import dev.caskeleton.application.fileserver.quota.StorageUsageProbe;
|
||||
import dev.caskeleton.application.fileserver.quota.TransferAdmissionController;
|
||||
import dev.caskeleton.application.fileserver.quota.TransferAdmissionProperties;
|
||||
import dev.caskeleton.application.fileserver.recovery.RecoveryQueue;
|
||||
import dev.caskeleton.application.fileserver.upload.DefaultFinalizeUploadService;
|
||||
import dev.caskeleton.application.fileserver.upload.DefaultSingleShotUploadService;
|
||||
import dev.caskeleton.application.fileserver.upload.DefaultUploadApplicationService;
|
||||
import dev.caskeleton.application.fileserver.upload.FileVerificationService;
|
||||
import dev.caskeleton.application.fileserver.upload.FinalizeUploadService;
|
||||
import dev.caskeleton.application.fileserver.upload.QuotaCommitGateway;
|
||||
import dev.caskeleton.application.fileserver.upload.SingleShotUploadService;
|
||||
import dev.caskeleton.application.fileserver.upload.UploadApplicationService;
|
||||
import dev.caskeleton.application.fileserver.upload.UploadContentGateway;
|
||||
import dev.caskeleton.application.fileserver.upload.UploadIdentifierFactory;
|
||||
import dev.caskeleton.application.fileserver.upload.UploadPolicy;
|
||||
import dev.caskeleton.application.fileserver.upload.UploadStorageGateway;
|
||||
import dev.caskeleton.application.transaction.PolicyTransactionPort;
|
||||
import dev.caskeleton.application.transaction.TransactionPort;
|
||||
import java.time.Clock;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
class FileserverUploadServiceConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
UploadIdentifierFactory fileserverIdentifierFactory() {
|
||||
return new RandomUploadIdentifierFactory();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
TransferAdmissionProperties fileserverAdmissionProperties(FileserverPlatformSettings settings) {
|
||||
FileserverPlatformSettings.Quota quota = settings.quota();
|
||||
return new TransferAdmissionProperties(
|
||||
quota.instanceUploadPermits(),
|
||||
quota.scopeUploadPermits(),
|
||||
quota.directDownloadPermits(),
|
||||
quota.softHighWater(),
|
||||
quota.hardHighWater());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
TransferAdmissionController fileserverAdmissionController(
|
||||
TransferAdmissionProperties properties,
|
||||
StorageUsageProbe usageProbe,
|
||||
FileserverPlatformSettings settings) {
|
||||
return new DefaultTransferAdmissionController(
|
||||
properties, usageProbe, settings.upload().maxFileSize().toBytes());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
UploadApplicationService fileserverUploadService(
|
||||
FileMetadataStore metadataStore,
|
||||
UploadSessionStore sessionStore,
|
||||
WriterLeaseCoordinator leaseCoordinator,
|
||||
UploadStorageGateway storageGateway,
|
||||
FileQuotaService quotaService,
|
||||
TransferAdmissionController admissionController,
|
||||
FileAccessPolicy accessPolicy,
|
||||
OriginalFilenamePolicy filenamePolicy,
|
||||
CleanupQueue cleanupQueue,
|
||||
UploadIdentifierFactory identifierFactory,
|
||||
UploadPolicy uploadPolicy,
|
||||
ObjectProvider<FileserverMetricsPort> metrics,
|
||||
PolicyTransactionPort transactions,
|
||||
Clock clock) {
|
||||
return new DefaultUploadApplicationService(
|
||||
metadataStore,
|
||||
sessionStore,
|
||||
leaseCoordinator,
|
||||
storageGateway,
|
||||
quotaService,
|
||||
admissionController,
|
||||
accessPolicy,
|
||||
filenamePolicy,
|
||||
cleanupQueue,
|
||||
identifierFactory,
|
||||
uploadPolicy,
|
||||
FileserverMetricsSupport.metricsOrNoop(metrics),
|
||||
transactions,
|
||||
clock);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
FinalizeUploadService fileserverFinalizeService(
|
||||
FileMetadataStore metadataStore,
|
||||
UploadSessionStore sessionStore,
|
||||
UploadContentGateway contentGateway,
|
||||
FileVerificationService verificationService,
|
||||
QuotaCommitGateway quotaGateway,
|
||||
CleanupQueue cleanupQueue,
|
||||
RecoveryQueue recoveryQueue,
|
||||
LocalBlockingContentStore store,
|
||||
PolicyTransactionPort transactions,
|
||||
Clock clock) {
|
||||
return new DefaultFinalizeUploadService(
|
||||
metadataStore,
|
||||
sessionStore,
|
||||
contentGateway,
|
||||
verificationService,
|
||||
quotaGateway,
|
||||
cleanupQueue,
|
||||
recoveryQueue,
|
||||
store.effectivePublishMode(),
|
||||
transactions,
|
||||
clock);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
SingleShotUploadService fileserverSingleShotUploadService(
|
||||
UploadApplicationService uploadService, FinalizeUploadService finalizeService) {
|
||||
return new DefaultSingleShotUploadService(uploadService, finalizeService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
WriterLeaseCoordinator fileserverWriterLeaseCoordinator(
|
||||
UploadSessionStore sessionStore,
|
||||
UploadPolicy uploadPolicy,
|
||||
TransactionPort transactions,
|
||||
Clock clock) {
|
||||
return new DefaultWriterLeaseCoordinator(
|
||||
sessionStore, uploadPolicy.leaseDuration(), transactions, clock);
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.mapper.MultipartUploadRequestMapper;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.mapper.RawUploadRequestMapper;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.problem.FileserverProblemFactory;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.security.FileserverRequestContextFactory;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
class FileserverWebAssemblyConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
FileserverRequestContextFactory fileserverRequestContextFactory(
|
||||
FileserverPlatformSettings properties) {
|
||||
return new FileserverRequestContextFactory(properties.instanceId());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
FileserverProblemFactory fileserverProblemFactory() {
|
||||
return new FileserverProblemFactory();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
RawUploadRequestMapper fileserverRawUploadRequestMapper(FileserverPlatformSettings properties) {
|
||||
return new RawUploadRequestMapper(properties.upload().requireContentLength());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
MultipartUploadRequestMapper fileserverMultipartUploadRequestMapper() {
|
||||
return new MultipartUploadRequestMapper();
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
dev.caskeleton.composition.fileserver.FileserverAdminManagementContextConfiguration
|
||||
+1
@@ -0,0 +1 @@
|
||||
dev.caskeleton.composition.fileserver.FileserverPlatformAutoConfiguration
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import dev.caskeleton.application.fileserver.admin.ContentReferenceLedger;
|
||||
import dev.caskeleton.application.fileserver.api.metadata.FileMetadataStore;
|
||||
import dev.caskeleton.application.fileserver.api.metadata.FileQuotaService;
|
||||
import dev.caskeleton.application.fileserver.api.metadata.UploadSessionStore;
|
||||
import dev.caskeleton.application.fileserver.cleanup.CleanupQueue;
|
||||
import dev.caskeleton.application.fileserver.cleanup.QuotaReclaimGateway;
|
||||
import dev.caskeleton.application.fileserver.recovery.RecoveryQueue;
|
||||
import dev.caskeleton.application.fileserver.recovery.StagingUploadLocator;
|
||||
import dev.caskeleton.application.fileserver.upload.QuotaCommitGateway;
|
||||
import dev.caskeleton.application.transaction.PolicyTransactionPort;
|
||||
import dev.caskeleton.application.transaction.TransactionRequest;
|
||||
import dev.caskeleton.application.transaction.TransactionResult;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Optional;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* The persistence side of the fileserver assembly, as stand-ins.
|
||||
*
|
||||
* <p>The point of an assembly test is that every constructor argument the composition root needs
|
||||
* can be satisfied, in order, without a null. Real stores would drag a database into a test whose
|
||||
* subject is the wiring; the stores prove their own behaviour in their own modules.
|
||||
*
|
||||
* <p>The storage root is a real directory because the capability probe genuinely creates, renames,
|
||||
* and deletes files in it at startup — that check is exactly what an assembly test must not stub
|
||||
* out.
|
||||
*/
|
||||
public abstract class FileserverAssemblyFixture {
|
||||
|
||||
private static final Path STORAGE_ROOT = createStorageRoot();
|
||||
|
||||
/** Absolute path of the probe-able storage root shared by the assembly tests. */
|
||||
public static String storageRoot() {
|
||||
return STORAGE_ROOT.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* A boundary that runs its action inline.
|
||||
*
|
||||
* <p>The application services now open their own transactions, so the composition root cannot be
|
||||
* assembled without one. Nothing here reaches a database, so the boundary has nothing to protect
|
||||
* — what this proves is that the wiring supplies one at all.
|
||||
*/
|
||||
@Bean
|
||||
PolicyTransactionPort transactions() {
|
||||
return new PolicyTransactionPort() {
|
||||
@Override
|
||||
public <T> T inWrite(java.util.function.Supplier<T> action) {
|
||||
return action.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T inRootWrite(java.util.function.Supplier<T> action) {
|
||||
return action.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T inRead(java.util.function.Supplier<T> action) {
|
||||
return action.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T inNew(java.util.function.Supplier<T> action) {
|
||||
return action.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> TransactionResult<T> inTransaction(
|
||||
TransactionRequest request, java.util.function.Supplier<T> action) {
|
||||
return new TransactionResult.Committed<>(action.get(), request.operationId());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Clock fixedClock() {
|
||||
return Clock.fixed(Instant.parse("2026-08-08T09:00:00Z"), ZoneOffset.UTC);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FileMetadataStore metadataStore() {
|
||||
return mock(FileMetadataStore.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UploadSessionStore uploadSessionStore() {
|
||||
return mock(UploadSessionStore.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FileQuotaService fileQuotaService() {
|
||||
return mock(FileQuotaService.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CleanupQueue cleanupQueue() {
|
||||
return mock(CleanupQueue.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RecoveryQueue recoveryQueue() {
|
||||
return mock(RecoveryQueue.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public QuotaCommitGateway quotaCommitGateway() {
|
||||
return mock(QuotaCommitGateway.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public QuotaReclaimGateway quotaReclaimGateway() {
|
||||
return mock(QuotaReclaimGateway.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ContentReferenceLedger contentReferenceLedger() {
|
||||
return key -> false;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public StagingUploadLocator stagingUploadLocator() {
|
||||
return fileId -> Optional.empty();
|
||||
}
|
||||
|
||||
private static Path createStorageRoot() {
|
||||
try {
|
||||
Path root = Files.createTempDirectory("fileserver-assembly");
|
||||
root.toFile().deleteOnExit();
|
||||
return root.toAbsolutePath();
|
||||
} catch (IOException exception) {
|
||||
throw new UncheckedIOException("assembly fixture needs a real storage root", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
|
||||
|
||||
import com.tngtech.archunit.core.domain.JavaClass;
|
||||
import com.tngtech.archunit.core.domain.JavaMethod;
|
||||
import com.tngtech.archunit.core.importer.ImportOption;
|
||||
import com.tngtech.archunit.junit.AnalyzeClasses;
|
||||
import com.tngtech.archunit.junit.ArchTest;
|
||||
import com.tngtech.archunit.lang.ArchCondition;
|
||||
import com.tngtech.archunit.lang.ArchRule;
|
||||
import com.tngtech.archunit.lang.ConditionEvents;
|
||||
import com.tngtech.archunit.lang.SimpleConditionEvent;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* BOOT-007: Fileserver composition stays split by concern instead of regrowing god configs.
|
||||
*
|
||||
* <p>Moved here with the code it governs. While it lived in app-bootstrap it analysed {@code
|
||||
* dev.caskeleton.bootstrap.autoconfigure.fileserver}, and once that package was empty the rule
|
||||
* passed by having nothing to check.
|
||||
*/
|
||||
@AnalyzeClasses(
|
||||
packages = "dev.caskeleton.composition.fileserver",
|
||||
importOptions = ImportOption.DoNotIncludeTests.class)
|
||||
class FileserverCompositionArchitectureTest {
|
||||
|
||||
@ArchTest
|
||||
static final ArchRule FILESERVER_CONFIGURATIONS_DECLARE_AT_MOST_EIGHT_BEANS =
|
||||
classes()
|
||||
.that()
|
||||
.resideInAPackage("dev.caskeleton.composition.fileserver")
|
||||
.should(declareAtMostEightBeanMethods())
|
||||
.as(
|
||||
"BOOT-007: one Fileserver composition class declares at most eight @Bean methods; "
|
||||
+ "larger or mixed port families split into package-private concern configs")
|
||||
// No allowEmptyShould: this module is the Fileserver composition, so an empty import
|
||||
// means the analysed package moved again and the rule stopped looking at anything —
|
||||
// which is how a split-by-concern rule quietly starts permitting a god config.
|
||||
.allowEmptyShould(false);
|
||||
|
||||
private static ArchCondition<JavaClass> declareAtMostEightBeanMethods() {
|
||||
return new ArchCondition<>("declare at most eight @Bean methods") {
|
||||
@Override
|
||||
public void check(JavaClass item, ConditionEvents events) {
|
||||
long count =
|
||||
item.getMethods().stream()
|
||||
.filter(FileserverCompositionArchitectureTest::isBeanMethod)
|
||||
.count();
|
||||
if (count > 8) {
|
||||
events.add(
|
||||
SimpleConditionEvent.violated(
|
||||
item, item.getFullName() + " declares " + count + " @Bean methods"));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static boolean isBeanMethod(JavaMethod method) {
|
||||
return method.isAnnotatedWith(Bean.class);
|
||||
}
|
||||
}
|
||||
+271
@@ -0,0 +1,271 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.context.properties.bind.BindHandler;
|
||||
import org.springframework.boot.context.properties.bind.Bindable;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
|
||||
/**
|
||||
* Keeps the support claims and the endpoint list honest.
|
||||
*
|
||||
* <p>Documentation drifts silently: a level stays "Stable" long after its job was renamed, and an
|
||||
* endpoint ships without ever reaching the contract file. Both are only caught by a test, because
|
||||
* neither produces a compile error or a failing behaviour test. This one reads the documents and
|
||||
* the sources and fails when they disagree.
|
||||
*/
|
||||
class FileserverDocumentationCoverageTest {
|
||||
|
||||
private static final Pattern CI_JOB = Pattern.compile("`(fileserver-[a-z0-9-]+)`");
|
||||
private static final Pattern WORKFLOW_JOB = Pattern.compile("^ {2}([a-z0-9-]+):\\s*$");
|
||||
private static final Pattern MAPPING_PATH =
|
||||
Pattern.compile("\"(/v1/[^\"]*|/internal/fileserver[^\"]*)\"");
|
||||
|
||||
@Test
|
||||
void everySupportClaimNamesAJobThatExists() throws IOException {
|
||||
List<String> claimed =
|
||||
referencedCiJobs(repositoryRoot().resolve("docs/fileserver/support-matrix.md"));
|
||||
List<String> defined = definedWorkflowJobs();
|
||||
|
||||
assertThat(claimed)
|
||||
.as("a support level whose evidence job does not exist is an unbacked claim")
|
||||
.isNotEmpty()
|
||||
.allSatisfy(job -> assertThat(defined).contains(job));
|
||||
}
|
||||
|
||||
@Test
|
||||
void everyPublicEndpointAppearsInTheHttpContract() throws IOException {
|
||||
String contract =
|
||||
normalizePathVariables(
|
||||
Files.readString(repositoryRoot().resolve("docs/fileserver/http-contract.md")));
|
||||
List<String> declared = declaredMappingPaths();
|
||||
|
||||
assertThat(declared).isNotEmpty();
|
||||
assertThat(declared)
|
||||
.as("an endpoint that ships undocumented is an undiscoverable contract")
|
||||
.allSatisfy(path -> assertThat(contract).contains(path));
|
||||
}
|
||||
|
||||
@Test
|
||||
void everyRunbookNamesAConcreteSignalAndCommand() throws IOException {
|
||||
String operations = Files.readString(repositoryRoot().resolve("docs/fileserver/operations.md"));
|
||||
|
||||
List<String> requiredRunbooks =
|
||||
List.of(
|
||||
"Storage full",
|
||||
"Orphan growth",
|
||||
"Verification backlog",
|
||||
"NFS ambiguity",
|
||||
"PVC remount",
|
||||
"Nginx delegation failure",
|
||||
"Cleanup backlog");
|
||||
|
||||
assertThat(requiredRunbooks).allSatisfy(runbook -> assertThat(operations).contains(runbook));
|
||||
assertThat(operations)
|
||||
.as("a runbook without a metric name has no trigger")
|
||||
.contains("fileserver.quota")
|
||||
.contains("fileserver.cleanup")
|
||||
.contains("fileserver.verification.queue")
|
||||
.contains("fileserver.download.delegation");
|
||||
}
|
||||
|
||||
@Test
|
||||
void theSupportMatrixStatesWhatIsNotClaimed() throws IOException {
|
||||
String matrix = Files.readString(repositoryRoot().resolve("docs/fileserver/support-matrix.md"));
|
||||
|
||||
assertThat(matrix)
|
||||
.as("an omitted capability reads as an unstated claim; absence must be explicit")
|
||||
.contains("Explicitly not claimed")
|
||||
.contains("ReadWriteMany");
|
||||
}
|
||||
|
||||
@Test
|
||||
void theExperimentalProtocolIsLabelledAsSuchWhereverItAppears() throws IOException {
|
||||
String matrix = Files.readString(repositoryRoot().resolve("docs/fileserver/support-matrix.md"));
|
||||
String contract =
|
||||
Files.readString(repositoryRoot().resolve("docs/fileserver/http-contract.md"));
|
||||
|
||||
assertThat(matrix).contains("draft-12").contains("Experimental");
|
||||
assertThat(contract).contains("draft12").contains("Experimental");
|
||||
}
|
||||
|
||||
/**
|
||||
* Every documented setting must be a setting that exists.
|
||||
*
|
||||
* <p>Checking that a document merely mentions a word cannot catch the drift that matters: a key
|
||||
* renamed in the settings record leaves the old name in the documentation, and a reader
|
||||
* configures something no binder will accept. Binding each documented key strictly settles it —
|
||||
* the same handler the auto-configuration uses refuses an element it cannot place.
|
||||
*/
|
||||
@Test
|
||||
void everyDocumentedSettingKeyStillBinds() throws IOException {
|
||||
List<String> documented =
|
||||
documentedSettingKeys(repositoryRoot().resolve("docs/fileserver/configuration.md"));
|
||||
|
||||
assertThat(documented).as("the configuration reference must list keys").isNotEmpty();
|
||||
|
||||
Map<String, Object> properties = new LinkedHashMap<>();
|
||||
for (String key : documented) {
|
||||
properties.put(FileserverPlatformSettings.PREFIX + "." + key, placeholderFor(key));
|
||||
}
|
||||
StandardEnvironment environment = new StandardEnvironment();
|
||||
environment.getPropertySources().addFirst(new MapPropertySource("documented", properties));
|
||||
|
||||
assertThatCode(
|
||||
() ->
|
||||
Binder.get(environment)
|
||||
.bind(
|
||||
FileserverPlatformSettings.PREFIX,
|
||||
Bindable.of(FileserverPlatformSettings.class),
|
||||
new NoUnboundElementsBindHandler(BindHandler.DEFAULT))
|
||||
.orElseThrow(() -> new AssertionError("documented settings did not bind")))
|
||||
.as("a documented key that binds to nothing is a reader following instructions to nowhere")
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Table keys from the configuration reference, minus the ones already qualified by a section.
|
||||
*
|
||||
* <p>The document writes a bare key inside a per-section table (for example {@code root} under
|
||||
* "Storage") and a qualified one elsewhere ({@code upload.ttl}); only the qualified form can be
|
||||
* bound without reconstructing the section context, so the bare ones are read with their heading.
|
||||
*/
|
||||
private static List<String> documentedSettingKeys(Path configuration) throws IOException {
|
||||
List<String> keys = new ArrayList<>();
|
||||
String section = "";
|
||||
for (String line : Files.readAllLines(configuration)) {
|
||||
Matcher heading = SECTION_KEY.matcher(line);
|
||||
if (heading.find()) {
|
||||
section = heading.group(1);
|
||||
continue;
|
||||
}
|
||||
Matcher matcher = TABLE_KEY.matcher(line);
|
||||
if (matcher.find()) {
|
||||
String key = matcher.group(1);
|
||||
keys.add(key.contains(".") || section.isEmpty() ? key : section + "." + key);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* A value the binder will accept for any key, so the test measures existence and not format.
|
||||
*
|
||||
* <p>Format is already the settings record's own business, and its constructors are exercised by
|
||||
* the auto-configuration tests.
|
||||
*/
|
||||
private static Object placeholderFor(String key) {
|
||||
return DEFAULTS.getOrDefault(key, "1");
|
||||
}
|
||||
|
||||
private static final Pattern TABLE_KEY = Pattern.compile("^\\| `([a-z0-9.-]+)` \\|");
|
||||
private static final Pattern SECTION_KEY = Pattern.compile("^## .*— `([a-z-]+)`");
|
||||
|
||||
/** Keys whose type will not accept a bare "1". */
|
||||
private static final Map<String, Object> DEFAULTS =
|
||||
Map.ofEntries(
|
||||
Map.entry("storage.root", "/var/lib/backend/files"),
|
||||
Map.entry("storage.publish-mode", "atomic-move-preferred"),
|
||||
Map.entry("storage.buffer-size", "128KB"),
|
||||
Map.entry("storage.forbidden-root-ancestors", "/app"),
|
||||
Map.entry("upload.max-file-size", "100MB"),
|
||||
Map.entry("upload.max-request-size", "100MB"),
|
||||
Map.entry("upload.initial-reservation", "1MB"),
|
||||
Map.entry("upload.ttl", "1h"),
|
||||
Map.entry("upload.reservation-ttl", "1h"),
|
||||
Map.entry("upload.lease-duration", "30s"),
|
||||
Map.entry("upload.require-content-length", "false"),
|
||||
Map.entry("security.access-policy", "role-based"),
|
||||
Map.entry("security.read-roles", "ROLE_FILE_READ"),
|
||||
Map.entry("security.write-roles", "ROLE_FILE_WRITE"),
|
||||
Map.entry("security.admin-roles", "ROLE_FILE_ADMIN"),
|
||||
// The water marks are cross-validated against each other, so a shared placeholder
|
||||
// would fail the record's own invariant rather than the documentation check.
|
||||
Map.entry("quota.soft-high-water", "0.70"),
|
||||
Map.entry("quota.hard-high-water", "0.85"));
|
||||
|
||||
private static List<String> referencedCiJobs(Path supportMatrix) throws IOException {
|
||||
List<String> jobs = new ArrayList<>();
|
||||
Matcher matcher = CI_JOB.matcher(Files.readString(supportMatrix));
|
||||
while (matcher.find()) {
|
||||
jobs.add(matcher.group(1));
|
||||
}
|
||||
return jobs;
|
||||
}
|
||||
|
||||
/** Job identifiers across every fileserver workflow, read from the two-space indent level. */
|
||||
private static List<String> definedWorkflowJobs() throws IOException {
|
||||
List<String> jobs = new ArrayList<>();
|
||||
Path workflows = repositoryRoot().resolve(".github/workflows");
|
||||
try (Stream<Path> files = Files.list(workflows)) {
|
||||
for (Path file :
|
||||
files.filter(path -> path.getFileName().toString().startsWith("fileserver-")).toList()) {
|
||||
for (String line : Files.readAllLines(file)) {
|
||||
Matcher matcher = WORKFLOW_JOB.matcher(line);
|
||||
if (matcher.matches()) {
|
||||
jobs.add(matcher.group(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return jobs;
|
||||
}
|
||||
|
||||
/** Literal request-mapping paths declared by the fileserver transport sources. */
|
||||
private static List<String> declaredMappingPaths() throws IOException {
|
||||
List<String> paths = new ArrayList<>();
|
||||
Path fileserverWeb =
|
||||
repositoryRoot()
|
||||
.resolve(
|
||||
"src/adapter/inbound/web-fileserver/src/main/java/dev/caskeleton/adapter/inbound/web/fileserver");
|
||||
try (Stream<Path> sources = Files.walk(fileserverWeb)) {
|
||||
for (Path source : sources.filter(path -> path.toString().endsWith(".java")).toList()) {
|
||||
String body = Files.readString(source);
|
||||
Matcher matcher = MAPPING_PATH.matcher(body);
|
||||
while (matcher.find()) {
|
||||
paths.add(normalizePathVariables(matcher.group(1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return paths.stream().distinct().toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces every path variable to one placeholder.
|
||||
*
|
||||
* <p>Both sides are normalized the same way, so renaming a handler's path variable — which
|
||||
* changes nothing a client observes — cannot fail this test.
|
||||
*/
|
||||
private static String normalizePathVariables(String text) {
|
||||
return text.replaceAll("\\{[a-zA-Z][a-zA-Z0-9]*}", "{id}");
|
||||
}
|
||||
|
||||
/** Repository root, resolved from the Gradle working directory rather than assumed. */
|
||||
private static Path repositoryRoot() {
|
||||
Path working = Path.of("").toAbsolutePath();
|
||||
Path candidate = working;
|
||||
while (candidate != null && !Files.isDirectory(candidate.resolve(".github/workflows"))) {
|
||||
candidate = candidate.getParent();
|
||||
}
|
||||
if (candidate == null) {
|
||||
throw new IllegalStateException("repository root not found above " + working);
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
+273
@@ -0,0 +1,273 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.config.BlockingTransferExecutor;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.config.FileserverWebProperties;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.config.MvcTransferExecutorConfiguration;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.http.HttpDownloadPolicy;
|
||||
import dev.caskeleton.adapter.inbound.web.fileserver.nginx.NginxDelegationProperties;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverCapabilityAutoConfiguration;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import dev.caskeleton.application.fileserver.observability.FileserverMetricsPort;
|
||||
import dev.caskeleton.application.fileserver.observability.SafeFileFingerprint;
|
||||
import dev.caskeleton.application.fileserver.upload.UploadPolicy;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.task.TaskDecorator;
|
||||
|
||||
class FileserverPlatformAutoConfigurationTest {
|
||||
|
||||
private final ApplicationContextRunner runner =
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(
|
||||
// Both halves. The capability's own assembly is the leaf's root now, and
|
||||
// the composition root carries the HTTP surface and startup policy; a
|
||||
// deployment gets both from AutoConfiguration.imports, so a test that
|
||||
// supplied only one would be asserting a shape no deployment produces.
|
||||
AutoConfigurations.of(
|
||||
FileserverCapabilityAutoConfiguration.class,
|
||||
FileserverPlatformAutoConfiguration.class))
|
||||
.withUserConfiguration(SupportingBeansConfiguration.class);
|
||||
|
||||
@Test
|
||||
void disabledCapabilityIgnoresDetailAndSubFeatureSettings() {
|
||||
runner
|
||||
.withPropertyValues(
|
||||
"app.fileserver-platform.upload.ttl=not-a-duration",
|
||||
"app.fileserver-platform.storage.buffer-size=not-a-size",
|
||||
"app.fileserver-platform.storage.root=relative/path",
|
||||
"app.fileserver-platform.admin.enabled=true",
|
||||
"app.fileserver-platform.tus.enabled=true",
|
||||
"app.fileserver-platform.httpbis-draft12.enabled=true",
|
||||
"app.fileserver-platform.cleanup.enabled=true")
|
||||
.run(
|
||||
context -> {
|
||||
assertThat(context).hasNotFailed();
|
||||
assertThat(context).doesNotHaveBean(FileserverWebProperties.class);
|
||||
assertThat(context).doesNotHaveBean(BlockingTransferExecutor.class);
|
||||
assertThat(context).doesNotHaveBean(FileserverMetricsPort.class);
|
||||
assertThat(context).doesNotHaveBean(FileserverPlatformSettings.class);
|
||||
assertThat(context).doesNotHaveBean(FileserverCleanupWorker.class);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A misspelled key is a configuration error, not a silently ignored one.
|
||||
*
|
||||
* <p>Dropping {@code uplaod.max-file-size} leaves the node running the default limit while its
|
||||
* configuration file says otherwise — the kind of divergence a file capability should never make
|
||||
* an operator discover from an incident.
|
||||
*/
|
||||
@Test
|
||||
void anUnknownKeyUnderThePrefixIsRefused() {
|
||||
enabled()
|
||||
.withPropertyValues("app.fileserver-platform.uplaod.max-file-size=1MB")
|
||||
.run(context -> assertThat(context).hasFailed());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCorePoolLargerThanItsMaximumIsRefused() {
|
||||
enabled()
|
||||
.withPropertyValues(
|
||||
"app.fileserver-platform.transfer.core-size=64",
|
||||
"app.fileserver-platform.transfer.max-size=8")
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context)
|
||||
.hasFailed()
|
||||
.getFailure()
|
||||
.hasStackTraceContaining("transfer.core-size"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSoftWaterMarkAtOrAboveTheHardOneIsRefused() {
|
||||
enabled()
|
||||
.withPropertyValues(
|
||||
"app.fileserver-platform.quota.soft-high-water=0.90",
|
||||
"app.fileserver-platform.quota.hard-high-water=0.85")
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context)
|
||||
.hasFailed()
|
||||
.getFailure()
|
||||
.hasStackTraceContaining("soft-high-water"));
|
||||
}
|
||||
|
||||
/** The byte ceiling applies to the default single-range profile, not only to multi-range. */
|
||||
@Test
|
||||
void theRangeByteCeilingAppliesToTheSingleRangeProfile() {
|
||||
enabled()
|
||||
.withPropertyValues("app.fileserver-platform.download.max-range-bytes=4MB")
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context.getBean(HttpDownloadPolicy.class).rangePolicy().maxTotalBytes())
|
||||
.isEqualTo(4L * 1024 * 1024));
|
||||
}
|
||||
|
||||
/**
|
||||
* A master switch that is not a boolean must fail loudly and early.
|
||||
*
|
||||
* <p>Spring's property condition treats anything that is not the expected value as "no", so
|
||||
* {@code enabled=yes} silently disables the capability. A deployment that meant to turn the
|
||||
* Fileserver on then serves 404s with a configuration file that says otherwise, and nothing in
|
||||
* the startup log mentions it.
|
||||
*/
|
||||
@Test
|
||||
void aMasterSwitchThatIsNotABooleanDoesNotSilentlyEnableTheCapability() {
|
||||
runner
|
||||
.withPropertyValues("app.fileserver-platform.enabled=yes")
|
||||
.run(
|
||||
context -> {
|
||||
assertThat(context).hasNotFailed();
|
||||
assertThat(context).doesNotHaveBean(FileserverPlatformSettings.class);
|
||||
assertThat(context).doesNotHaveBean(FileserverWebProperties.class);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The three file capabilities share nothing but a word in their names.
|
||||
*
|
||||
* <p>They previously shared a configuration prefix, so switching the HTTP platform on also
|
||||
* switched on the R1 publication and its directory initialisation. Each namespace must now move
|
||||
* exactly one capability.
|
||||
*/
|
||||
/**
|
||||
* A delegation whose internal mapping does not round-trip must not start.
|
||||
*
|
||||
* <p>Nginx answers an unresolvable internal redirect with an empty {@code 200}: the client
|
||||
* believes it received the file. Failing at startup is the only point at which that is visible.
|
||||
*/
|
||||
@Test
|
||||
void nginxDelegationWithAnUnusableInternalPrefixFailsStartup() {
|
||||
enabled()
|
||||
.withPropertyValues(
|
||||
"app.fileserver-platform.nginx.enabled=true",
|
||||
"app.fileserver-platform.nginx.internal-prefix=files/")
|
||||
.run(context -> assertThat(context).hasFailed());
|
||||
}
|
||||
|
||||
@Test
|
||||
void enabledDefaultsAssembleTheExpectedRuntime() {
|
||||
enabled()
|
||||
.withPropertyValues("app.fileserver.enabled=false", "app.file-export.enabled=false")
|
||||
.run(
|
||||
context -> {
|
||||
assertThat(context).hasNotFailed();
|
||||
assertThat(context).hasSingleBean(FileserverPlatformSettings.class);
|
||||
assertThat(context).hasSingleBean(FileserverWebProperties.class);
|
||||
assertThat(context).hasSingleBean(UploadPolicy.class);
|
||||
assertThat(context).hasSingleBean(HttpDownloadPolicy.class);
|
||||
assertThat(context).hasSingleBean(BlockingTransferExecutor.class);
|
||||
assertThat(context).hasSingleBean(SafeFileFingerprint.class);
|
||||
|
||||
HttpDownloadPolicy download = context.getBean(HttpDownloadPolicy.class);
|
||||
assertThat(download.cacheControl()).isEqualTo("private, no-store");
|
||||
assertThat(download.inlineAllowed()).isFalse();
|
||||
assertThat(download.rangePolicy().allowsMultipleRanges()).isFalse();
|
||||
assertThat(context.getBean(NginxDelegationProperties.class).enabled()).isFalse();
|
||||
assertThat(context.getBean(FileserverWebProperties.class).maxBatchParts())
|
||||
.isEqualTo(16);
|
||||
|
||||
assertThat(
|
||||
context.getBean(
|
||||
dev.caskeleton.adapter.inbound.web.fileserver.config
|
||||
.TransferExecutorProperties.class))
|
||||
.satisfies(
|
||||
properties -> {
|
||||
assertThat(properties.coreSize()).isEqualTo(8);
|
||||
assertThat(properties.maxSize()).isEqualTo(32);
|
||||
assertThat(properties.queueCapacity()).isEqualTo(64);
|
||||
});
|
||||
|
||||
assertThat(context.getEnvironment().getProperty("app.fileserver.enabled"))
|
||||
.isEqualTo("false");
|
||||
assertThat(context.getEnvironment().getProperty("app.file-export.enabled"))
|
||||
.isEqualTo("false");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnkeyedTelemetryFingerprintIsRefusedRatherThanDowngraded() {
|
||||
runner
|
||||
.withPropertyValues(
|
||||
"app.fileserver-platform.enabled=true",
|
||||
"app.fileserver-platform.security.access-policy=role-based",
|
||||
"app.fileserver-platform.storage.root=" + FileserverAssemblyFixture.storageRoot())
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context)
|
||||
.hasFailed()
|
||||
.getFailure()
|
||||
.hasStackTraceContaining("fingerprint-key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void propertiesOverrideTheDefaults() {
|
||||
enabled()
|
||||
.withPropertyValues(
|
||||
"app.fileserver-platform.download.inline-allowed=true",
|
||||
"app.fileserver-platform.download.max-ranges=4",
|
||||
"app.fileserver-platform.upload.max-file-size=1MB",
|
||||
"app.fileserver-platform.upload.max-request-size=2MB",
|
||||
"app.fileserver-platform.upload.initial-reservation=512KB",
|
||||
"app.fileserver-platform.nginx.enabled=true")
|
||||
.run(
|
||||
context -> {
|
||||
assertThat(context.getBean(HttpDownloadPolicy.class).inlineAllowed()).isTrue();
|
||||
assertThat(context.getBean(HttpDownloadPolicy.class).rangePolicy().maxRanges())
|
||||
.isEqualTo(4);
|
||||
assertThat(context.getBean(UploadPolicy.class).maximumFileSize())
|
||||
.isEqualTo(1024L * 1024);
|
||||
assertThat(context.getBean(NginxDelegationProperties.class).enabled()).isTrue();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void metricsCanBeTurnedOffWithoutDisablingTheCapability() {
|
||||
enabled()
|
||||
.withPropertyValues("app.fileserver-platform.observability.metrics-enabled=false")
|
||||
.run(
|
||||
context -> {
|
||||
assertThat(context).hasSingleBean(FileserverWebProperties.class);
|
||||
assertThat(context).doesNotHaveBean(FileserverMetricsPort.class);
|
||||
});
|
||||
}
|
||||
|
||||
private ApplicationContextRunner enabled() {
|
||||
return runner.withPropertyValues(
|
||||
"app.fileserver-platform.enabled=true",
|
||||
"app.fileserver-platform.observability.fingerprint-key=a-sixteen-byte-key!!",
|
||||
"app.fileserver-platform.security.access-policy=role-based",
|
||||
"app.fileserver-platform.storage.root=" + FileserverAssemblyFixture.storageRoot());
|
||||
}
|
||||
|
||||
/**
|
||||
* The collaborators the composition root normally supplies.
|
||||
*
|
||||
* <p>A real registry, so the Micrometer implementation is exercised rather than mocked away, and
|
||||
* a real decorator, because the transfer pool refuses to be built without one. The persistence
|
||||
* ports are stand-ins: this test proves the assembly graph closes, and the stores prove their own
|
||||
* behaviour in their own module.
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Import(MvcTransferExecutorConfiguration.class)
|
||||
static class SupportingBeansConfiguration extends FileserverAssemblyFixture {
|
||||
|
||||
@Bean
|
||||
MeterRegistry meterRegistry() {
|
||||
return new SimpleMeterRegistry();
|
||||
}
|
||||
|
||||
@Bean
|
||||
TaskDecorator taskDecorator() {
|
||||
return runnable -> runnable;
|
||||
}
|
||||
}
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverPlatformSettings;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.context.properties.bind.BindHandler;
|
||||
import org.springframework.boot.context.properties.bind.Bindable;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.core.env.SystemEnvironmentPropertySource;
|
||||
|
||||
/**
|
||||
* Closes the loop between the shipped {@code .env} and the typed settings.
|
||||
*
|
||||
* <p>The Gradle {@code verifyEnvKeys} check compares three text files, which proves a key is
|
||||
* declared everywhere but not that anything reads it. A key can be spelled correctly in {@code
|
||||
* .env}, {@code application.yml} and the registry and still map to no field at all — which is
|
||||
* exactly how a documented setting ends up doing nothing.
|
||||
*
|
||||
* <p>The names go in as real environment variables rather than as hand-translated property names,
|
||||
* so what is under test is the mapping the runtime actually performs — including the cases where an
|
||||
* underscore becomes a hyphen inside one property name rather than a level of nesting. Binding
|
||||
* strictly then settles the rest: the same handler the auto-configuration uses refuses an element
|
||||
* it cannot place, so a key with no field fails here instead of in production.
|
||||
*/
|
||||
class FileserverPlatformEnvRoundTripTest {
|
||||
|
||||
private static final String ENV_PREFIX = "APP_FILESERVER_PLATFORM_";
|
||||
|
||||
@Test
|
||||
void everyDeclaredEnvKeyBindsToAField() {
|
||||
Map<String, Object> environmentVariables = declaredPlatformEnvironment();
|
||||
|
||||
assertThat(environmentVariables)
|
||||
.as("src/.env must declare the platform's operational surface")
|
||||
.isNotEmpty();
|
||||
|
||||
FileserverPlatformSettings bound = bindStrictly(environmentVariables);
|
||||
|
||||
assertThat(bound.enabled()).isFalse();
|
||||
assertThat(bound.storage().root().isAbsolute()).isTrue();
|
||||
assertThat(bound.upload().maxRequestSize().toBytes())
|
||||
.isGreaterThanOrEqualTo(bound.upload().maxFileSize().toBytes());
|
||||
assertThat(bound.security().readRoles()).containsExactly("ROLE_FILE_READ");
|
||||
assertThat(bound.storage().forbiddenRootAncestors()).isNotEmpty();
|
||||
}
|
||||
|
||||
/** The shipped defaults must be the conservative ones, in the file operators actually copy. */
|
||||
@Test
|
||||
void theShippedEnvironmentKeepsEveryOptionalSurfaceOff() {
|
||||
Map<String, Object> environmentVariables = declaredPlatformEnvironment();
|
||||
|
||||
assertThat(environmentVariables)
|
||||
.containsEntry("APP_FILESERVER_PLATFORM_ENABLED", "false")
|
||||
.containsEntry("APP_FILESERVER_PLATFORM_ADMIN_ENABLED", "false")
|
||||
.containsEntry("APP_FILESERVER_PLATFORM_CLEANUP_ENABLED", "false")
|
||||
.containsEntry("APP_FILESERVER_PLATFORM_TUS_ENABLED", "false")
|
||||
.containsEntry("APP_FILESERVER_PLATFORM_HTTPBIS_DRAFT12_ENABLED", "false")
|
||||
.containsEntry("APP_FILESERVER_PLATFORM_NGINX_ENABLED", "false")
|
||||
.containsEntry("APP_FILESERVER_PLATFORM_DOWNLOAD_INLINE_ALLOWED", "false")
|
||||
.containsEntry("APP_FILESERVER_PLATFORM_SECURITY_ACCESS_POLICY", "required");
|
||||
}
|
||||
|
||||
private static FileserverPlatformSettings bindStrictly(Map<String, Object> environmentVariables) {
|
||||
StandardEnvironment environment = new StandardEnvironment();
|
||||
environment
|
||||
.getPropertySources()
|
||||
.addFirst(
|
||||
new SystemEnvironmentPropertySource(
|
||||
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, environmentVariables));
|
||||
BindHandler strict = new NoUnboundElementsBindHandler(BindHandler.DEFAULT);
|
||||
return Binder.get(environment)
|
||||
.bind(
|
||||
FileserverPlatformSettings.PREFIX,
|
||||
Bindable.of(FileserverPlatformSettings.class),
|
||||
strict)
|
||||
.orElseThrow(
|
||||
() -> new AssertionError("the declared environment did not bind to any settings"));
|
||||
}
|
||||
|
||||
private static Map<String, Object> declaredPlatformEnvironment() {
|
||||
Map<String, Object> variables = new LinkedHashMap<>();
|
||||
for (String line : readEnvFile()) {
|
||||
String trimmed = line.trim();
|
||||
if (!trimmed.startsWith(ENV_PREFIX)) {
|
||||
continue;
|
||||
}
|
||||
int separator = trimmed.indexOf('=');
|
||||
String value = trimmed.substring(separator + 1);
|
||||
if (value.isBlank()) {
|
||||
// A blank secret is a deliberate placeholder, not a value the binder should see.
|
||||
continue;
|
||||
}
|
||||
variables.put(trimmed.substring(0, separator), value);
|
||||
}
|
||||
return variables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the repository's tracked {@code src/.env.example}.
|
||||
*
|
||||
* <p>A copy in the test resources would drift from the shipped contract, which is the drift this
|
||||
* test exists to catch — so it reads the repository file rather than a fixture.
|
||||
*
|
||||
* <p>It reads {@code .env.example}, not {@code .env}. {@code .gitignore} states the rule: the
|
||||
* real {@code .env} is operator input and the examples beside it are the tracked contract. A real
|
||||
* {@code .env} exists only on a developer machine, so pointing this test at it made the test pass
|
||||
* locally and fail on every clean checkout — which is where CI runs.
|
||||
*/
|
||||
private static List<String> readEnvFile() {
|
||||
// Walked upward rather than counted. The previous form resolved `../.env.example`, which was a
|
||||
// correct guess only while this test lived one directory below `src/`; the moment it moved with
|
||||
// the code it tests, the fixed number of `..` was wrong and the failure read as a missing
|
||||
// contract file rather than as a moved test.
|
||||
Path env = null;
|
||||
for (Path directory = Path.of(System.getProperty("user.dir")).toAbsolutePath();
|
||||
directory != null;
|
||||
directory = directory.getParent()) {
|
||||
Path candidate = directory.resolve(".env.example");
|
||||
if (Files.exists(candidate)) {
|
||||
env = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (env == null) {
|
||||
throw new UncheckedIOException(
|
||||
"src/.env.example could not be read",
|
||||
new IOException("no .env.example in any ancestor of " + System.getProperty("user.dir")));
|
||||
}
|
||||
try {
|
||||
return Files.readAllLines(env);
|
||||
} catch (IOException exception) {
|
||||
throw new UncheckedIOException("src/.env.example could not be read", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.autoconfigure.FileserverCapabilityAutoConfiguration;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.security.RoleBasedFileAccessPolicy;
|
||||
import dev.caskeleton.adapter.outbound.fileserver.platform.security.UnenforcedFileAccessPolicy;
|
||||
import dev.caskeleton.application.fileserver.admin.AdminAuditPort;
|
||||
import dev.caskeleton.application.fileserver.admin.FileserverAdminService;
|
||||
import dev.caskeleton.application.fileserver.admin.OrphanScanPort;
|
||||
import dev.caskeleton.application.fileserver.admin.StorageHealthPort;
|
||||
import dev.caskeleton.application.fileserver.api.security.FileAccessPolicy;
|
||||
import dev.caskeleton.application.fileserver.cleanup.CleanupContentGateway;
|
||||
import dev.caskeleton.application.fileserver.cleanup.CleanupService;
|
||||
import dev.caskeleton.application.fileserver.concurrency.WriterLeaseCoordinator;
|
||||
import dev.caskeleton.application.fileserver.download.DownloadApplicationService;
|
||||
import dev.caskeleton.application.fileserver.download.DownloadContentGateway;
|
||||
import dev.caskeleton.application.fileserver.download.ZeroCopyDownloadGateway;
|
||||
import dev.caskeleton.application.fileserver.lifecycle.CopyContentGateway;
|
||||
import dev.caskeleton.application.fileserver.lifecycle.FileLifecycleService;
|
||||
import dev.caskeleton.application.fileserver.observability.FileserverAuditPort;
|
||||
import dev.caskeleton.application.fileserver.quota.StorageUsageProbe;
|
||||
import dev.caskeleton.application.fileserver.quota.TransferAdmissionController;
|
||||
import dev.caskeleton.application.fileserver.recovery.FileReconciliationService;
|
||||
import dev.caskeleton.application.fileserver.recovery.ReconciliationContentProbe;
|
||||
import dev.caskeleton.application.fileserver.upload.FileVerificationService;
|
||||
import dev.caskeleton.application.fileserver.upload.FinalizeUploadService;
|
||||
import dev.caskeleton.application.fileserver.upload.SingleShotUploadService;
|
||||
import dev.caskeleton.application.fileserver.upload.UploadApplicationService;
|
||||
import dev.caskeleton.application.fileserver.upload.UploadContentGateway;
|
||||
import dev.caskeleton.application.fileserver.upload.UploadIdentifierFactory;
|
||||
import dev.caskeleton.application.fileserver.upload.UploadStorageGateway;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.task.TaskDecorator;
|
||||
|
||||
/**
|
||||
* Proves the capability is assembled, not merely present.
|
||||
*
|
||||
* <p>Every other fileserver test builds its subject by hand, so a port with no production
|
||||
* implementation and a composition root that never wires one both stay invisible: the code
|
||||
* compiles, the unit tests pass, and the first thing to notice is a failed startup in an
|
||||
* environment where the flag was finally switched on. This test switches it on.
|
||||
*
|
||||
* <p>It asserts on interfaces rather than implementations wherever the design allows a substitute,
|
||||
* so replacing a storage backend or an authorization policy does not break it — what it pins is
|
||||
* that something satisfies each seam.
|
||||
*/
|
||||
class FileserverRuntimeAssemblyTest {
|
||||
|
||||
private final ApplicationContextRunner runner =
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(
|
||||
// Both halves. The capability's own assembly is the leaf's root now, and
|
||||
// the composition root carries the HTTP surface and startup policy; a
|
||||
// deployment gets both from AutoConfiguration.imports, so a test that
|
||||
// supplied only one would be asserting a shape no deployment produces.
|
||||
AutoConfigurations.of(
|
||||
FileserverCapabilityAutoConfiguration.class,
|
||||
FileserverPlatformAutoConfiguration.class))
|
||||
.withUserConfiguration(AssemblySupport.class);
|
||||
|
||||
@Test
|
||||
void enabledBaselineAssemblesTheCompleteRuntime() {
|
||||
enabled()
|
||||
.run(
|
||||
context -> {
|
||||
assertThat(context).hasNotFailed();
|
||||
|
||||
List.of(
|
||||
UploadStorageGateway.class,
|
||||
UploadContentGateway.class,
|
||||
DownloadContentGateway.class,
|
||||
ZeroCopyDownloadGateway.class,
|
||||
CopyContentGateway.class,
|
||||
CleanupContentGateway.class,
|
||||
ReconciliationContentProbe.class,
|
||||
StorageUsageProbe.class,
|
||||
StorageHealthPort.class,
|
||||
OrphanScanPort.class,
|
||||
FileVerificationService.class)
|
||||
.forEach(port -> assertThat(context).hasSingleBean(port));
|
||||
|
||||
List.of(
|
||||
UploadApplicationService.class,
|
||||
FinalizeUploadService.class,
|
||||
SingleShotUploadService.class,
|
||||
DownloadApplicationService.class,
|
||||
FileLifecycleService.class,
|
||||
CleanupService.class,
|
||||
FileReconciliationService.class,
|
||||
WriterLeaseCoordinator.class,
|
||||
TransferAdmissionController.class,
|
||||
UploadIdentifierFactory.class)
|
||||
.forEach(service -> assertThat(context).hasSingleBean(service));
|
||||
|
||||
assertThat(context).hasSingleBean(FileAccessPolicy.class);
|
||||
assertThat(context).hasSingleBean(AdminAuditPort.class);
|
||||
assertThat(context).hasSingleBean(FileserverAuditPort.class);
|
||||
assertThat(context.getBean(FileAccessPolicy.class))
|
||||
.isInstanceOf(RoleBasedFileAccessPolicy.class);
|
||||
assertThat(context).doesNotHaveBean(FileserverAdminService.class);
|
||||
assertThat(context).doesNotHaveBean(FileserverCleanupWorker.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void anEnabledCapabilityWithoutAnAuthorizationDecisionRefusesToStart() {
|
||||
baseline()
|
||||
.withPropertyValues("app.fileserver-platform.enabled=true")
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context)
|
||||
.hasFailed()
|
||||
.getFailure()
|
||||
.hasMessageContaining("without an authorization policy"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theUnenforcedPolicyIsAvailableForDevelopment() {
|
||||
baseline()
|
||||
.withPropertyValues(
|
||||
"app.fileserver-platform.enabled=true",
|
||||
"app.fileserver-platform.security.access-policy=unenforced")
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context.getBean(FileAccessPolicy.class))
|
||||
.isInstanceOf(UnenforcedFileAccessPolicy.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theUnenforcedPolicyIsRefusedUnderAProductionProfile() {
|
||||
baseline()
|
||||
.withPropertyValues(
|
||||
"app.fileserver-platform.enabled=true",
|
||||
"app.fileserver-platform.security.access-policy=unenforced")
|
||||
.withPropertyValues("spring.profiles.active=prod")
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context)
|
||||
.hasFailed()
|
||||
.getFailure()
|
||||
.hasMessageContaining("must not be active under the 'prod' profile"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theAdminPlaneAppearsOnItsOwnSwitch() {
|
||||
enabled()
|
||||
.withPropertyValues("app.fileserver-platform.admin.enabled=true")
|
||||
.run(context -> assertThat(context).hasSingleBean(FileserverAdminService.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theCleanupWorkerAppearsOnItsOwnSwitch() {
|
||||
enabled()
|
||||
.withPropertyValues("app.fileserver-platform.cleanup.enabled=true")
|
||||
.run(context -> assertThat(context).hasSingleBean(FileserverCleanupWorker.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStorageRootThatCannotBeProbedRefusesToStart() {
|
||||
enabled()
|
||||
.withPropertyValues(
|
||||
"app.fileserver-platform.storage.root=" + FileserverAssemblyFixture.storageRoot(),
|
||||
"app.fileserver-platform.storage.forbidden-root-ancestors="
|
||||
+ FileserverAssemblyFixture.storageRoot())
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context)
|
||||
.hasFailed()
|
||||
.getFailure()
|
||||
.hasMessageContaining("forbidden ancestor"));
|
||||
}
|
||||
|
||||
private ApplicationContextRunner enabled() {
|
||||
return baseline()
|
||||
.withPropertyValues(
|
||||
"app.fileserver-platform.enabled=true",
|
||||
"app.fileserver-platform.security.access-policy=role-based");
|
||||
}
|
||||
|
||||
private ApplicationContextRunner baseline() {
|
||||
return runner.withPropertyValues(
|
||||
"app.fileserver-platform.observability.fingerprint-key=a-sixteen-byte-key!!",
|
||||
"app.fileserver-platform.storage.root=" + FileserverAssemblyFixture.storageRoot());
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class AssemblySupport extends FileserverAssemblyFixture {
|
||||
|
||||
@Bean
|
||||
MeterRegistry meterRegistry() {
|
||||
return new SimpleMeterRegistry();
|
||||
}
|
||||
|
||||
@Bean
|
||||
TaskDecorator taskDecorator() {
|
||||
return runnable -> runnable;
|
||||
}
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package dev.caskeleton.composition.fileserver;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.core.read.ListAppender;
|
||||
import dev.caskeleton.application.fileserver.cleanup.CleanupBatchResult;
|
||||
import dev.caskeleton.application.fileserver.cleanup.CleanupService;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The cleanup worker's structured-logging contract.
|
||||
*
|
||||
* <p>Split out of app-bootstrap's {@code BootstrapStructuredRuntimeLoggingTest} when the worker
|
||||
* moved here. That file asserts one contract — bounded, classified outcome fields with no unbounded
|
||||
* key in them — across several capabilities, and the two halves stayed together only because the
|
||||
* code did. What the contract says is unchanged; where it is checked now follows the worker.
|
||||
*/
|
||||
class FileserverStructuredLoggingTest {
|
||||
|
||||
@Test
|
||||
void fileserverCleanupSuccessCarriesBoundedOutcomeFields() {
|
||||
CleanupService cleanup = (maxItems, maxBytes) -> new CleanupBatchResult(1, 2, 3, 4, 5L);
|
||||
|
||||
try (CapturedLogger captured = capture(FileserverCleanupWorker.class)) {
|
||||
new FileserverCleanupWorker(cleanup, 10, 1_024L).runBatch();
|
||||
|
||||
ILoggingEvent event = captured.singleEvent();
|
||||
assertThat(event.getLevel()).isEqualTo(Level.INFO);
|
||||
assertThat(event.getFormattedMessage()).contains("deleted=1").contains("reclaimedBytes=5");
|
||||
assertThat(renderedArguments(event))
|
||||
.contains("capability=fileserver")
|
||||
.contains("operation=cleanup")
|
||||
.contains("cleanup.deleted=1")
|
||||
.contains("cleanup.failed=4")
|
||||
.contains("cleanup.reclaimed_bytes=5");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void fileserverCleanupFailureCarriesRetryDisposition() {
|
||||
CleanupService cleanup =
|
||||
(maxItems, maxBytes) -> {
|
||||
throw new IllegalStateException("storage unavailable");
|
||||
};
|
||||
|
||||
try (CapturedLogger captured = capture(FileserverCleanupWorker.class)) {
|
||||
new FileserverCleanupWorker(cleanup, 10, 1_024L).runBatch();
|
||||
|
||||
ILoggingEvent event = captured.singleEvent();
|
||||
assertThat(event.getLevel()).isEqualTo(Level.WARN);
|
||||
assertThat(renderedArguments(event))
|
||||
.contains("capability=fileserver")
|
||||
.contains("operation=cleanup")
|
||||
.contains("warning.kind=scheduled-task-failed")
|
||||
.contains("retry.disposition=next-run");
|
||||
assertThat(event.getThrowableProxy()).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
private static CapturedLogger capture(Class<?> owner) {
|
||||
Logger logger = (Logger) LoggerFactory.getLogger(owner);
|
||||
ListAppender<ILoggingEvent> appender = new ListAppender<>();
|
||||
appender.setContext((LoggerContext) LoggerFactory.getILoggerFactory());
|
||||
appender.start();
|
||||
logger.addAppender(appender);
|
||||
return new CapturedLogger(logger, appender);
|
||||
}
|
||||
|
||||
private static String renderedArguments(ILoggingEvent event) {
|
||||
Object[] arguments = event.getArgumentArray();
|
||||
if (arguments == null) {
|
||||
return "";
|
||||
}
|
||||
return Arrays.stream(arguments).map(String::valueOf).collect(Collectors.joining(" | "));
|
||||
}
|
||||
|
||||
private record CapturedLogger(Logger logger, ListAppender<ILoggingEvent> appender)
|
||||
implements AutoCloseable {
|
||||
|
||||
ILoggingEvent singleEvent() {
|
||||
assertThat(appender.list).hasSize(1);
|
||||
return appender.list.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
logger.detachAppender(appender);
|
||||
appender.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user