--- /dev/null
+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<>();
+ }
+ }
+}
--- /dev/null
+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