diff --git a/out/searchProvider.js b/out/searchProvider.js index a1b883b..4d2e4d4 100644 --- a/out/searchProvider.js +++ b/out/searchProvider.js @@ -2,6 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const vscode = require("vscode"); const axios = require("axios"); +const { getClient } = require('./notebooks/splunk'); class SearchProvider { constructor() { @@ -32,10 +33,15 @@ class SearchProvider { } let searchResults = "No results"; + + const exportUrl = await shouldUseDeprecatedSearchAPIs() + ? `${this.splunkUrl}/services/search/jobs/export?output_mode=${this.outputMode}` + : `${this.splunkUrl}/services/search/v2/jobs/export?output_mode=${this.outputMode}`; + await axios( { method: "POST", - url: `${this.splunkUrl}/services/search/jobs/export?output_mode=${this.outputMode}`, + url: exportUrl, data: "search=" + encodeURIComponent(`search ${search}`) }) .then(response => { @@ -117,10 +123,15 @@ class SavedSearchProvider { } let searchResults = "No results"; + + const exportUrl = await shouldUseDeprecatedSearchAPIs() + ? `${this.splunkUrl}/servicesNS/${savedSearchItem.owner}/${savedSearchItem.app}/search/jobs/export?output_mode=${this.outputMode}` + : `${this.splunkUrl}/servicesNS/${savedSearchItem.owner}/${savedSearchItem.app}/search/v2/jobs/export?output_mode=${this.outputMode}`; + await axios( { method: "POST", - url: `${this.splunkUrl}/servicesNS/${savedSearchItem.owner}/${savedSearchItem.app}/search/jobs/export?output_mode=${this.outputMode}`, + url: exportUrl, data: "search=" + encodeURIComponent(`| savedsearch "${savedSearchItem.label}"`) }) .then(response => { @@ -147,4 +158,23 @@ class SavedSearch extends vscode.TreeItem { this.contextValue = 'savedSearch'; } } -exports.SavedSearch = SavedSearch; \ No newline at end of file +exports.SavedSearch = SavedSearch; + +let cachedDisableV2SearchApi = null; // avoid multiple calls +async function shouldUseDeprecatedSearchAPIs() { + if (cachedDisableV2SearchApi !== null) { + console.log(`shouldUseDeprecatedSearchAPIs found cachedDisableV2SearchApi=${cachedDisableV2SearchApi}`); + return cachedDisableV2SearchApi; + } + // retrieve Splunk version and deployment info for disableV2SearchApi() + const service = getClient(); + try { + await service.getInfo(); + } catch (error) { + console.warn("error retrieving Splunk version with service.getInfo():"); + console.warn(error); + }; + cachedDisableV2SearchApi = service.disableV2SearchApi(); + console.log(`shouldUseDeprecatedSearchAPIs service.disableV2SearchApi()=${cachedDisableV2SearchApi}`); + return cachedDisableV2SearchApi; +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 2c429f4..b583f79 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "splunk", - "version": "0.3.2", + "version": "0.3.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "splunk", - "version": "0.3.2", + "version": "0.3.3", "license": "MIT", "dependencies": { "@babel/core": "^7.22.8", @@ -23,7 +23,7 @@ "querystring-es3": "^0.2.1", "react": "^16.14.0", "react-dom": "^16.14.0", - "splunk-sdk": "^1.12.1", + "splunk-sdk": "^2.0.0", "styled-components": "^5.1.1", "tar-fs": "^2.1.1", "ts-loader": "^9.4.2", @@ -11947,9 +11947,9 @@ } }, "node_modules/splunk-sdk": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/splunk-sdk/-/splunk-sdk-1.12.1.tgz", - "integrity": "sha512-LhXTNYZ6ozGNuCeP8krdZmbrOe89QgfbZcP4SicsfciBRrh64fVRZmkZPoKeLrYvWHEpYv4NjBmDhrjvWQiL4w==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/splunk-sdk/-/splunk-sdk-2.0.0.tgz", + "integrity": "sha512-xmkoZ1I6KxQrs7B15db5nUqLGDR+ohDZ21/sGfcLRwOYfTCGR8uHVP/huEwTtrSXJ/WcgyevDwnIniOjuKhcOQ==", "dependencies": { "cookie": "0.4.2", "dotenv": "16.0.0", diff --git a/package.json b/package.json index b8bd544..fe7000c 100644 --- a/package.json +++ b/package.json @@ -460,7 +460,7 @@ "querystring-es3": "^0.2.1", "react": "^16.14.0", "react-dom": "^16.14.0", - "splunk-sdk": "^1.12.1", + "splunk-sdk": "^2.0.0", "styled-components": "^5.1.1", "tar-fs": "^2.1.1", "ts-loader": "^9.4.2",