public URL getAgentUri()

in src/main/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerResourceProvider.java [243:268]


    public URL getAgentUri(RestRequest request) throws IOException {
        String redirectEndpoint = request.param("redirectEndpoint");
        String urlScheme = isHttpsEnabled ? "https://" : "http://";
        String redirectBasePath =
                urlScheme + "localhost:" + portNumber + RestConfig.PA_BASE_URI + "/";
        // Need to register all params in OpenSearch request else opensearch throws
        // illegal_argument_exception
        for (String key : request.params().keySet()) {
            request.param(key);
        }

        // Add Handler whenever add new redirectAgent path
        if (SUPPORTED_REDIRECTIONS.contains(redirectEndpoint)) {
            String uri = null;
            if (request.uri().contains(AGENT_PATH)) {
                uri = redirectBasePath + request.uri().split(AGENT_PATH)[1];
            } else if (request.uri().contains(LEGACY_AGENT_PATH)) {
                uri = redirectBasePath + request.uri().split(LEGACY_AGENT_PATH)[1];
            } else {
                throw new IOException();
            }

            return new URL(uri);
        }
        return null;
    }