From f14f5c7219739f9886d8648701b11d4e9d71005b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Hilles=C3=B8y?= Date: Fri, 7 Jun 2024 09:11:02 +0200 Subject: [PATCH 1/4] fix: updated version of search endpoint /search/v2/jobs/export --- out/searchProvider.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/out/searchProvider.js b/out/searchProvider.js index a1b883b..736446d 100644 --- a/out/searchProvider.js +++ b/out/searchProvider.js @@ -35,7 +35,7 @@ class SearchProvider { await axios( { method: "POST", - url: `${this.splunkUrl}/services/search/jobs/export?output_mode=${this.outputMode}`, + url: `${this.splunkUrl}/services/search/v2/jobs/export?output_mode=${this.outputMode}`, data: "search=" + encodeURIComponent(`search ${search}`) }) .then(response => { @@ -120,7 +120,7 @@ class SavedSearchProvider { await axios( { method: "POST", - url: `${this.splunkUrl}/servicesNS/${savedSearchItem.owner}/${savedSearchItem.app}/search/jobs/export?output_mode=${this.outputMode}`, + url: `${this.splunkUrl}/servicesNS/${savedSearchItem.owner}/${savedSearchItem.app}/search/v2/jobs/export?output_mode=${this.outputMode}`, data: "search=" + encodeURIComponent(`| savedsearch "${savedSearchItem.label}"`) }) .then(response => { From 33efbc1f7897741dd4ae48f22beda6ab0e2d67d5 Mon Sep 17 00:00:00 2001 From: Tim Pavlik Date: Wed, 3 Jul 2024 17:00:40 -0700 Subject: [PATCH 2/4] Selectively use search v2 APIs depending on Splunk version from /server/info endpoint. --- out/searchProvider.js | 32 +++++++++++++++++++++++++++++--- package-lock.json | 12 ++++++------ package.json | 2 +- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/out/searchProvider.js b/out/searchProvider.js index 736446d..eaceb1b 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/v2/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/v2/jobs/export?output_mode=${this.outputMode}`, + url: exportUrl, data: "search=" + encodeURIComponent(`| savedsearch "${savedSearchItem.label}"`) }) .then(response => { @@ -147,4 +158,19 @@ 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) { + return cachedDisableV2SearchApi; + } + // retrieve Splunk version and deployment info for disableV2SearchApi() + const service = getClient(); + await service.getInfo().catch(error => { + console.warn("error retrieving Splunk version with service.getInfo():"); + console.warn(error); + }); + cachedDisableV2SearchApi = service.disableV2SearchApi(); + 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", From 7f9080d7204ac5c82e5db637279f1b95d5725482 Mon Sep 17 00:00:00 2001 From: Tim Pavlik Date: Wed, 3 Jul 2024 17:07:41 -0700 Subject: [PATCH 3/4] Add logging --- out/searchProvider.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/out/searchProvider.js b/out/searchProvider.js index eaceb1b..1dbf032 100644 --- a/out/searchProvider.js +++ b/out/searchProvider.js @@ -163,6 +163,7 @@ 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() @@ -172,5 +173,6 @@ async function shouldUseDeprecatedSearchAPIs() { console.warn(error); }); cachedDisableV2SearchApi = service.disableV2SearchApi(); + console.log(`shouldUseDeprecatedSearchAPIs service.disableV2SearchApi()=${cachedDisableV2SearchApi}`); return cachedDisableV2SearchApi; } \ No newline at end of file From ae7ef1277d4c2b44f229fb883ba00dc950165515 Mon Sep 17 00:00:00 2001 From: Tim Pavlik Date: Tue, 3 Sep 2024 08:23:35 -0700 Subject: [PATCH 4/4] Fix issue in catch handling per review feedback --- out/searchProvider.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/out/searchProvider.js b/out/searchProvider.js index 1dbf032..4d2e4d4 100644 --- a/out/searchProvider.js +++ b/out/searchProvider.js @@ -168,10 +168,12 @@ async function shouldUseDeprecatedSearchAPIs() { } // retrieve Splunk version and deployment info for disableV2SearchApi() const service = getClient(); - await service.getInfo().catch(error => { + 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;