]> git.frustrated-labs.net Git - gradle-configvalidator-plugin.git/commitdiff
add andes configuration source
authorAlexander Goussas <[email protected]>
Fri, 26 Dec 2025 14:30:44 +0000 (09:30 -0500)
committerAlexander Goussas <[email protected]>
Fri, 26 Dec 2025 14:30:44 +0000 (09:30 -0500)
.idea/vcs.xml [new file with mode: 0644]
lib/build.gradle.kts
lib/src/main/java/io/github/aloussase/configvalidator/sources/AndesConfigurationVariableSource.java [new file with mode: 0644]
lib/src/test/java/io/github/aloussase/configvalidator/sources/AndesConfigurationVariableSourceTest.java [new file with mode: 0644]

diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644 (file)
index 0000000..94a25f7
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>
\ No newline at end of file
index 0d96185040ab0faf91beafb2c2523be576c884b5..dc0bd47db538fa39002499b00cee6906e727e09a 100644 (file)
@@ -16,6 +16,8 @@ repositories {
 
 dependencies {
     implementation("org.yaml:snakeyaml:2.2")
+    implementation("com.squareup.okhttp3:okhttp:5.3.0")
+    implementation("com.fasterxml.jackson.core:jackson-databind:2.20.0-rc1")
     testImplementation(libs.junit.jupiter)
     testRuntimeOnly("org.junit.platform:junit-platform-launcher")
 }
diff --git a/lib/src/main/java/io/github/aloussase/configvalidator/sources/AndesConfigurationVariableSource.java b/lib/src/main/java/io/github/aloussase/configvalidator/sources/AndesConfigurationVariableSource.java
new file mode 100644 (file)
index 0000000..821e806
--- /dev/null
@@ -0,0 +1,104 @@
+package io.github.aloussase.configvalidator.sources;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.github.aloussase.configvalidator.ConfigurationVariable;
+import io.github.aloussase.configvalidator.ConfigurationVariableSource;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class AndesConfigurationVariableSource implements ConfigurationVariableSource {
+
+    private final OkHttpClient httpClient;
+
+    private final String apiUrl;
+
+    private final String bluePrint;
+
+    private final String authToken;
+
+    private final String deploymentId;
+
+    private final ObjectMapper objectMapper;
+
+    public AndesConfigurationVariableSource(OkHttpClient httpClient, String apiUrl, String bluePrint, String authToken, String deploymentId, ObjectMapper objectMapper) {
+        this.httpClient = httpClient;
+        this.apiUrl = apiUrl;
+        this.bluePrint = bluePrint;
+        this.authToken = authToken;
+        this.deploymentId = deploymentId;
+        this.objectMapper = objectMapper;
+    }
+
+    // TODO: Better error handling to let the user know what went wrong.
+
+    @Override
+    public List<ConfigurationVariable> readConfigurationVariables(String env) {
+        final var requestBody = """
+                    {
+                        "query": {
+                            "combinator": "and",
+                            "rules": [
+                                {
+                                    "combinator": "and",
+                                     "rules": [
+                                        {
+                                            "property": "deployment_id",
+                                             "operator": "=",
+                                             "value": "%s"
+                                        },
+                                        {
+                                             "property": "entorno_name",
+                                             "operator": "=",
+                                             "value": "%s"
+                                        }
+                                     ]
+                                }
+                            ]
+                        },
+                        "include": ["$title", "value"]
+                    }
+                """
+                .formatted(deploymentId, env)
+                .trim();
+
+        final var request = new Request.Builder()
+                .post(RequestBody.create(requestBody.getBytes()))
+                .url("%s/v1/blueprints/%s/entities/search".formatted(apiUrl, bluePrint))
+                .header("Authorization", "Bearer " + authToken)
+                .header("Accept", "application/json")
+                .header("Content-Type", "application/json")
+                .build();
+
+        Response response;
+
+        try {
+            response = httpClient.newCall(request).execute();
+        } catch (IOException ignored) {
+            return new ArrayList<>();
+        }
+
+        if (!response.isSuccessful()) {
+            return new ArrayList<>();
+        }
+
+        try (final var inputStream = response.body().byteStream()) {
+            final var rootNode = objectMapper.readTree(inputStream);
+            return rootNode
+                    .get("entities")
+                    .valueStream()
+                    .map(node -> new ConfigurationVariable(
+                            node.get("title").asText(),
+                            node.get("properties").get("value").asText()
+                    ))
+                    .toList();
+        } catch (IOException ignored) {
+            return new ArrayList<>();
+        }
+    }
+}
diff --git a/lib/src/test/java/io/github/aloussase/configvalidator/sources/AndesConfigurationVariableSourceTest.java b/lib/src/test/java/io/github/aloussase/configvalidator/sources/AndesConfigurationVariableSourceTest.java
new file mode 100644 (file)
index 0000000..a7a4aaa
--- /dev/null
@@ -0,0 +1,34 @@
+package io.github.aloussase.configvalidator.sources;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import okhttp3.OkHttpClient;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class AndesConfigurationVariableSourceTest {
+
+    @Test
+    public void givenRealDataSourceParametersWhenReadingConfigurationVariablesCallReturnsWithSuccess() {
+        final var apiUrl = System.getenv("ANDES_API_URL");
+        final var bluePrint = System.getenv("ANDES_BLUEPRINT");
+        final var authToken = System.getenv("ANDES_AUTH_TOKEN");
+        final var deploymentId = System.getenv("ANDES_DEPLOYMENT_ID");
+
+        if (apiUrl == null || authToken == null || deploymentId == null || bluePrint == null) {
+            return;
+        }
+
+        final var httpClient = new OkHttpClient.Builder().build();
+        final var objectMapper = new ObjectMapper();
+
+        final var dataSource = new AndesConfigurationVariableSource(httpClient, apiUrl, bluePrint, authToken, deploymentId, objectMapper);
+
+        final var variables = dataSource.readConfigurationVariables("DEV");
+
+        assertNotNull(variables);
+        assertFalse(variables.isEmpty());
+    }
+
+}
\ No newline at end of file