async getCloudInfoForCluster()

in packages/azure-kusto-data/src/cloudSettings.ts [40:78]


    async getCloudInfoForCluster(kustoUri: string): Promise<CloudInfo> {
        kustoUri = this.normalizeUrl(kustoUri);
        if (kustoUri in this.cloudCache) {
            return this.cloudCache[kustoUri];
        }

        try {
            const response = await axios.get<{ AzureAD: CloudInfo | undefined }>(this.getAuthMetadataEndpointFromClusterUri(kustoUri), {
                headers: {
                    "Cache-Control": "no-cache",
                    // Disable caching - it's being cached in memory (Service returns max-age).
                    // The original motivation for this is due to a CORS issue in Ibiza due to a dynamic subdomain.
                    // The first dynamic subdomain is attached to the cache and for some reason isn't invalidated
                    // when there is a new subdomain. It causes the request failure due to CORS.
                    // Example:
                    // Access to XMLHttpRequest at 'https://safrankecc.canadacentral.kusto.windows.net/v1/rest/auth/metadata' from origin
                    // 'https://sandbox-46-11.reactblade.portal.azure.net' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value
                    // 'https://sandbox-46-10.reactblade.portal.azure.net' that is not equal to the supplied origin.
                },
                maxRedirects: 0,
            });
            if (response.status === 200) {
                this.cloudCache[kustoUri] = response.data.AzureAD || this.defaultCloudInfo;
            } else {
                throw new Error(`Kusto returned an invalid cloud metadata response - ${response}`);
            }
        } catch (ex) {
            if (axios.isAxiosError(ex)) {
                // Axios library has a bug in browser, not propagating the status code, see: https://github.com/axios/axios/issues/5330
                if ((isNode && ex.response?.status === 404) || (!isNode && (!ex.code || ex.code === AXIOS_ERR_NETWORK))) {
                    // For now as long not all proxies implement the metadata endpoint, if no endpoint exists return public cloud data
                    this.cloudCache[kustoUri] = this.defaultCloudInfo;
                } else {
                    throw new Error(`Failed to get cloud info for cluster ${kustoUri} - ${ex}`);
                }
            }
        }
        return this.cloudCache[kustoUri];
    }