public void execute()

in src/main/java/co/elastic/support/diagnostics/commands/CheckDiagnosticVersion.java [37:116]


    public void execute(DiagnosticContext context) {

        // For airgapped environments allow them to bypass this check
        if (context.diagnosticInputs.bypassDiagVerify) {
            return;
        }

        logger.info(Constants.CONSOLE, "Checking for diagnostic version updates.");
        // Only need this once so let it auto-close at the end of the try catch block.
        try(RestClient restClient = RestClient.getClient(
                    context.diagsConfig.diagReleaseHost,
                    Constants.DEEFAULT_HTTPS_PORT,
                    context.diagsConfig.diagReleaseScheme,
                    "",
                    "",
                    "",
                    0,
                    "",
                    "",
                    "",
                    "",
                    true,
                    context.diagsConfig.extraHeaders,
                    context.diagsConfig.connectionTimeout,
                    context.diagsConfig.connectionRequestTimeout,
                    context.diagsConfig.socketTimeout)){

            // Get the current diagnostic version that was populated in the
            // manifest generation step - if we're running in
            // the IDE via a run configuration and/or debugger it will
            // have a value of "debug" instead of an actual version.
            context.diagVersion = getToolVersion();
            if (context.diagVersion.equals(Constants.runningInIde) || StringUtils.isEmpty(context.diagVersion)) {
                logger.info(Constants.CONSOLE, "Running in IDE");
                // Default it to something that won't blow up the Semver but shows it's not a normal run.
                context.diagVersion = "0.0.0";
                return;
            }

            RestResult restResult = new RestResult(restClient.execGet(
                    context.diagsConfig.diagLatestRelease), context.diagsConfig.diagLatestRelease);
            JsonNode rootNode = JsonYamlUtils.createJsonNodeFromString(restResult.toString());
            // newer tags are prefixed with `v`, so remove it
            String ver = rootNode.path("tag_name").asText().replaceAll("^v", "");

            Semver diagVer = new Semver(context.diagVersion);
            String rule = ">= " + ver;

            if (!diagVer.satisfies(rule)) {

                logger.info(Constants.CONSOLE, "Warning: DiagnosticService version:{} is not the current recommended release", context.diagVersion);
                logger.info(Constants.CONSOLE, "The current release is {}", ver);

                // Try to get the link for the download url of the current release.
                List<JsonNode> assets = rootNode.findValues("assets");
                JsonNode asset = assets.get(0);
                ArrayNode attachments = null;
                if(asset.isArray()){
                    attachments = (ArrayNode)asset;
                    asset = attachments.get(0);
                }
                String downloadUrl = asset.path("browser_download_url").asText();
                if(StringUtils.isEmpty(downloadUrl)){
                    downloadUrl = context.diagsConfig.diagLatestRelease;
                }

                logger.info(Constants.CONSOLE, "The latest version can be downloaded at {}", downloadUrl);
                logger.info(Constants.CONSOLE, "Press the Enter key to continue.");

                Scanner sc = new Scanner(System.in);
                sc.nextLine();
            }

        } catch (Exception e) {
            logger.error( e);
            logger.info(Constants.CONSOLE, "Issue encountered while checking diagnostic version for updates.");
            logger.info(Constants.CONSOLE, "Failed to get current diagnostic version from Github.");
            logger.info(Constants.CONSOLE, "If Github is not accessible from this environment current supported version cannot be confirmed.");
        }
    }