private List getKibanaSpacesIds()

in src/main/java/co/elastic/support/diagnostics/commands/RunKibanaQueries.java [64:88]


    private List<String> getKibanaSpacesIds(DiagnosticContext context) throws DiagnosticException {
        RestClient restClient = context.resourceCache.getRestClient(Constants.restInputHost);
        String url = context.fullElasticRestCalls.get("kibana_spaces").getUrl();
        RestResult result = restClient.execQuery(url);
        
        if (result.getStatus() != 200) {
            throw new DiagnosticException(String.format(
                "Kibana responded with [%d] for [%s]. Unable to proceed.",
                result.getStatus(), url));
        }

        JsonNode spacesResponse = JsonYamlUtils.createJsonNodeFromString(result.toString());
        if (!spacesResponse.isArray()) {
            throw new DiagnosticException("Kibana Spaces API returned an invalid response. A list of Spaces was expected.");
        }
        ArrayNode arrayNode = (ArrayNode) spacesResponse;
        List<String> spacesIds = new ArrayList<>();
        for (JsonNode node : arrayNode) {
            JsonNode idNode = node.path("id");
            if(!idNode.isMissingNode()) {
                spacesIds.add(idNode.asText());
            }
        }
        return spacesIds;
    }