diff --git a/Dockerfile.native b/Dockerfile.native
new file mode 100644
index 0000000..4f613ff
--- /dev/null
+++ b/Dockerfile.native
@@ -0,0 +1,27 @@
+FROM ghcr.io/graalvm/graalvm-community:22 AS build
+
+ARG MAVEN_VERSION=3.9.9
+ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
+
+RUN mkdir -p /usr/share/maven /usr/share/maven/ref
+ADD ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz /tmp/apache-maven.tar.gz
+RUN tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
+ && rm -f /tmp/apache-maven.tar.gz \
+ && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
+
+WORKDIR /usr/src/app
+
+COPY pom.xml .
+RUN mvn dependency:go-offline
+
+COPY . .
+
+RUN mvn -DskipTests -Pprod -Pnative native:compile
+
+FROM debian:bookworm-slim
+
+WORKDIR /app
+
+COPY --from=build /usr/src/app/target/switcher-ac /app/switcher-ac
+
+CMD ["/app/switcher-ac"]
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 9ccd293..626cd19 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,7 +50,7 @@
org.springframework.boot
spring-boot-starter-parent
- 3.3.5
+ 3.4.0
@@ -59,14 +59,15 @@
${java.version}
4.0.0-M1
- 2.2.0
+ 2.2.1
0.12.6
2.13.0
2.11.0
- 2.6.0
+ 2.7.0
4.16.1
+ 4.12.0
0.10.3
@@ -86,21 +87,27 @@
-
- local
-
- true
-
-
- local
-
-
prod
prod
+
+ native
+
+
+
+ org.graalvm.buildtools
+ native-maven-plugin
+ ${native-image-plugin.version}
+
+ com.github.switcherapi.ac.SwitcherAcApplication
+
+
+
+
+
coverage
@@ -268,20 +275,28 @@
- com.squareup.okhttp3
- okhttp
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+ org.springframework.security
+ spring-security-test
test
com.squareup.okhttp3
- mockwebserver
+ okhttp
+ ${okhttp.version}
test
- org.springframework.security
- spring-security-test
+ com.squareup.okhttp3
+ mockwebserver
+ ${okhttp.version}
test
@@ -297,12 +312,6 @@
${flapdoodle.embed.mongo.version}
test
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
@@ -317,11 +326,6 @@
-
- org.graalvm.buildtools
- native-maven-plugin
- ${native-image-plugin.version}
-
org.springframework.boot
spring-boot-maven-plugin
diff --git a/src/main/java/com/github/switcherapi/ac/SwitcherAcApplication.java b/src/main/java/com/github/switcherapi/ac/SwitcherAcApplication.java
index f205a83..95b5058 100644
--- a/src/main/java/com/github/switcherapi/ac/SwitcherAcApplication.java
+++ b/src/main/java/com/github/switcherapi/ac/SwitcherAcApplication.java
@@ -9,8 +9,6 @@
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.ComponentScan;
-import static com.github.switcherapi.ac.config.SwitcherFeatures.checkSwitchers;
-
@SpringBootApplication
@ConfigurationPropertiesScan
@ComponentScan(basePackages = { "com.github.switcherapi.ac" })
@@ -29,8 +27,6 @@ public static void main(String[] args) {
@Override
public void run(String... args) {
- checkSwitchers();
-
log.info("Loading default Plan...");
planService.createPlan(Plan.loadDefault());
log.info("Plan loaded");
diff --git a/src/main/java/com/github/switcherapi/ac/config/SwitcherConfig.java b/src/main/java/com/github/switcherapi/ac/config/SwitcherConfig.java
deleted file mode 100644
index f94577a..0000000
--- a/src/main/java/com/github/switcherapi/ac/config/SwitcherConfig.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.github.switcherapi.ac.config;
-
-import com.github.switcherapi.ac.util.FileUtil;
-import com.github.switcherapi.client.ContextBuilder;
-import com.github.switcherapi.client.SnapshotCallback;
-import jakarta.annotation.PostConstruct;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-import static com.github.switcherapi.ac.config.SwitcherFeatures.configure;
-import static com.github.switcherapi.ac.config.SwitcherFeatures.initializeClient;
-import static com.github.switcherapi.ac.config.SwitcherFeatures.scheduleSnapshotAutoUpdate;
-
-@Slf4j
-@ConfigurationProperties(prefix = "switcher")
-public record SwitcherConfig(
- String url,
- String apikey,
- String domain,
- String component,
- String environment,
- boolean local,
- String silent,
- SnapshotConfig snapshot,
- String relayCode,
- TruststoreConfig truststore) implements SnapshotCallback {
-
- record SnapshotConfig(
- String autoUpdateInterval,
- String location,
- boolean auto) { }
-
- record TruststoreConfig(
- String path,
- String password) { }
-
- @PostConstruct
- private void configureSwitcher() {
- configure(ContextBuilder.builder()
- .contextLocation(SwitcherFeatures.class.getName())
- .url(url)
- .apiKey(apikey)
- .domain(domain)
- .environment(environment)
- .component(component)
- .local(local)
- .silentMode(silent)
- .snapshotLocation(StringUtils.isNotBlank(snapshot.location()) ? snapshot.location() : null)
- .snapshotAutoLoad(snapshot.auto())
- .truststorePath(StringUtils.isNotBlank(truststore.path()) ? FileUtil.getFilePathFromResource(truststore.path()) : null)
- .truststorePassword(StringUtils.isNotBlank(truststore.password()) ? truststore.password() : null));
-
- initializeClient();
- scheduleSnapshotAutoUpdate(snapshot.autoUpdateInterval(), this);
- }
-
- @Override
- public void onSnapshotUpdate(long version) {
- log.info("Snapshot updated: {}", version);
- }
-
-}
diff --git a/src/main/java/com/github/switcherapi/ac/config/SwitcherFeatures.java b/src/main/java/com/github/switcherapi/ac/config/SwitcherFeatures.java
index 3f5f6f3..a9b18e6 100644
--- a/src/main/java/com/github/switcherapi/ac/config/SwitcherFeatures.java
+++ b/src/main/java/com/github/switcherapi/ac/config/SwitcherFeatures.java
@@ -1,11 +1,39 @@
package com.github.switcherapi.ac.config;
+import com.github.switcherapi.ac.util.FileUtil;
+import com.github.switcherapi.client.SnapshotCallback;
import com.github.switcherapi.client.SwitcherContextBase;
import com.github.switcherapi.client.SwitcherKey;
+import jakarta.annotation.PostConstruct;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@Slf4j
+@Getter
+@Setter
+@ConfigurationProperties(prefix = "switcher")
+public class SwitcherFeatures extends SwitcherContextBase implements SnapshotCallback {
-public class SwitcherFeatures extends SwitcherContextBase {
-
@SwitcherKey
public static final String SWITCHER_AC_ADM = "SWITCHER_AC_ADM";
+ private String relayCode;
+
+ @PostConstruct
+ @Override
+ protected void configureClient() {
+ super.truststore.setPath(FileUtil.getFilePathFromResource(truststore.getPath()));
+ super.configureClient();
+
+ scheduleSnapshotAutoUpdate(snapshot.getUpdateInterval(), this);
+ checkSwitchers();
+ }
+
+ @Override
+ public void onSnapshotUpdate(long version) {
+ log.info("Snapshot updated: {}", version);
+ }
+
}
diff --git a/src/main/java/com/github/switcherapi/ac/controller/SwitcherRelayController.java b/src/main/java/com/github/switcherapi/ac/controller/SwitcherRelayController.java
index 27b395a..408c8ee 100644
--- a/src/main/java/com/github/switcherapi/ac/controller/SwitcherRelayController.java
+++ b/src/main/java/com/github/switcherapi/ac/controller/SwitcherRelayController.java
@@ -1,12 +1,12 @@
package com.github.switcherapi.ac.controller;
-import com.github.switcherapi.ac.config.SwitcherConfig;
+import com.github.switcherapi.ac.config.SwitcherFeatures;
import com.github.switcherapi.ac.model.domain.FeaturePayload;
import com.github.switcherapi.ac.model.dto.RequestRelayDTO;
import com.github.switcherapi.ac.model.dto.ResponseRelayDTO;
import com.github.switcherapi.ac.service.AccountService;
-import com.github.switcherapi.ac.service.ValidatorService;
-import com.github.switcherapi.ac.service.validator.ValidatorFactory;
+import com.github.switcherapi.ac.service.ValidatorBasicService;
+import com.github.switcherapi.ac.service.validator.ValidatorBuilderService;
import com.google.gson.Gson;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.ResponseEntity;
@@ -25,26 +25,26 @@ public class SwitcherRelayController {
private final AccountService accountService;
- private final ValidatorFactory validatorFactory;
+ private final ValidatorBuilderService validatorBuilderService;
- private final ValidatorService validatorService;
+ private final ValidatorBasicService validatorBasicService;
- private final SwitcherConfig switcherConfig;
+ private final SwitcherFeatures switcherConfig;
public SwitcherRelayController(
- AccountService accountService,
- ValidatorFactory validatorFactory,
- ValidatorService validatorService,
- SwitcherConfig switcherConfig) {
+ AccountService accountService,
+ ValidatorBuilderService validatorBuilderService,
+ ValidatorBasicService validatorBasicService,
+ SwitcherFeatures switcherConfig) {
this.accountService = accountService;
- this.validatorFactory = validatorFactory;
- this.validatorService = validatorService;
+ this.validatorBuilderService = validatorBuilderService;
+ this.validatorBasicService = validatorBasicService;
this.switcherConfig = switcherConfig;
}
@GetMapping(value = "/verify")
public ResponseEntity