Skip to content

Commit 7a43714

Browse files
committed
Updated client files
1 parent 03dab5c commit 7a43714

File tree

4 files changed

+82
-38
lines changed

4 files changed

+82
-38
lines changed

client/splunk.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ var __exportName = 'splunkjs';
683683
this.version = params.version || "default";
684684
this.timeout = params.timeout || 0;
685685
this.autologin = true;
686+
this.instanceType = "";
686687

687688
// Initialize autologin
688689
// The reason we explicitly check to see if 'autologin'
@@ -717,16 +718,17 @@ var __exportName = 'splunkjs';
717718

718719
// We perform the bindings so that every function works
719720
// properly when it is passed as a callback.
720-
this._headers = utils.bind(this, this._headers);
721-
this.fullpath = utils.bind(this, this.fullpath);
722-
this.urlify = utils.bind(this, this.urlify);
723-
this.get = utils.bind(this, this.get);
724-
this.del = utils.bind(this, this.del);
725-
this.post = utils.bind(this, this.post);
726-
this.login = utils.bind(this, this.login);
727-
this._shouldAutoLogin = utils.bind(this, this._shouldAutoLogin);
728-
this._requestWrapper = utils.bind(this, this._requestWrapper);
729-
this.getVersion = utils.bind(this, this.getVersion);
721+
this._headers = utils.bind(this, this._headers);
722+
this.fullpath = utils.bind(this, this.fullpath);
723+
this.urlify = utils.bind(this, this.urlify);
724+
this.get = utils.bind(this, this.get);
725+
this.del = utils.bind(this, this.del);
726+
this.post = utils.bind(this, this.post);
727+
this.login = utils.bind(this, this.login);
728+
this._shouldAutoLogin = utils.bind(this, this._shouldAutoLogin);
729+
this._requestWrapper = utils.bind(this, this._requestWrapper);
730+
this.getInfo = utils.bind(this, this.getInfo);
731+
this.disableV2SearchApi = utils.bind(this, this.disableV2SearchApi);
730732
},
731733

732734
/**
@@ -897,19 +899,21 @@ var __exportName = 'splunkjs';
897899
* @method splunkjs.Context
898900
* @private
899901
*/
900-
getVersion: function (callback) {
902+
getInfo: function (callback) {
901903
var that = this;
902904
var url = this.paths.info;
903905

904906
callback = callback || function() {};
905907

906908
var wrappedCallback = function(err, response) {
907909
var hasVersion = !!(!err && response.data && response.data.generator.version);
910+
let hasInstanceType = !!(!err && response.data && response.data.generator["instance_type"]);
908911

909912
if (err || !hasVersion) {
910913
callback(err || "No version found", false);
911914
}
912915
else {
916+
that.instanceType = hasInstanceType ? response.data.generator["instance_type"] : "";
913917
that.version = response.data.generator.version;
914918
that.http.version = that.version;
915919
callback(null, true);
@@ -954,7 +958,7 @@ var __exportName = 'splunkjs';
954958
}
955959
else {
956960
that.sessionKey = response.data.sessionKey;
957-
that.getVersion(callback);
961+
that.getInfo(callback);
958962
}
959963
};
960964
return this.http.post(
@@ -1131,6 +1135,16 @@ var __exportName = 'splunkjs';
11311135
}
11321136
}
11331137
return 0;
1138+
},
1139+
1140+
disableV2SearchApi: function(){
1141+
let val;
1142+
if(this.instanceType.toLowerCase() == "cloud"){
1143+
val = this.versionCompare("9.0.2209");
1144+
}else{
1145+
val = this.versionCompare("9.0.2")
1146+
}
1147+
return val < 0;
11341148
}
11351149
});
11361150

@@ -2910,7 +2924,7 @@ var __exportName = 'splunkjs';
29102924
params.q = query;
29112925

29122926
// Pre-9.0 uses GET and v1 endpoint
2913-
if (this.versionCompare("9.0.2") < 0) {
2927+
if (this.disableV2SearchApi()) {
29142928
return this.get(Paths.parser, params, function(err, response) {
29152929
if (err) {
29162930
callback(err);
@@ -5694,7 +5708,7 @@ var __exportName = 'splunkjs';
56945708
*/
56955709
path: function () {
56965710
// Pre-9.0 uses v1 endpoint
5697-
if (this.versionCompare("9.0.2") < 0) {
5711+
if (this.disableV2SearchApi()) {
56985712
return Paths.jobs + "/" + encodeURIComponent(this.name);
56995713
}
57005714
// Post-9.0 uses v2 endpoint
@@ -5719,6 +5733,7 @@ var __exportName = 'splunkjs';
57195733
// Passing the service version and versionCompare to this.path() before instantiating splunkjs.Service.Entity.
57205734
this.version = service.version;
57215735
this.versionCompare = service.versionCompare;
5736+
this.disableV2SearchApi = service.disableV2SearchApi;
57225737

57235738
this.name = sid;
57245739
this._super(service, this.path(), namespace);
@@ -5843,7 +5858,7 @@ var __exportName = 'splunkjs';
58435858
var eventsPath = Paths.jobsV2 + "/" + encodeURIComponent(this.name) + "/events";
58445859
// Splunk version pre-9.0 doesn't support v2
58455860
// v1(GET), v2(POST)
5846-
if (this.versionCompare("9.0.2") < 0) {
5861+
if (this.disableV2SearchApi()) {
58475862
eventsPath = Paths.jobs + "/" + encodeURIComponent(this.name) + "/events";
58485863
return this.get(eventsPath, params, function(err, response) {
58495864
if (err) {
@@ -5959,7 +5974,7 @@ var __exportName = 'splunkjs';
59595974
var resultsPreviewPath = Paths.jobsV2 + "/" + encodeURIComponent(this.name) + "/results_preview";
59605975
// Splunk version pre-9.0 doesn't support v2
59615976
// v1(GET), v2(POST)
5962-
if (this.versionCompare("9.0.2") < 0) {
5977+
if (this.disableV2SearchApi()) {
59635978
resultsPreviewPath = Paths.jobs + "/" + encodeURIComponent(this.name) + "/results_preview";
59645979
return this.get(resultsPreviewPath, params, function(err, response) {
59655980
if (err) {
@@ -6012,7 +6027,7 @@ var __exportName = 'splunkjs';
60126027
var resultsPath = Paths.jobsV2 + "/" + encodeURIComponent(this.name) + "/results";
60136028
// Splunk version pre-9.0 doesn't support v2
60146029
// v1(GET), v2(POST)
6015-
if (this.versionCompare("9.0.2") < 0) {
6030+
if (this.disableV2SearchApi()) {
60166031
resultsPath = Paths.jobs + "/" + encodeURIComponent(this.name) + "/results";
60176032
return this.get(resultsPath, params, function(err, response) {
60186033
if (err) {
@@ -6353,7 +6368,7 @@ var __exportName = 'splunkjs';
63536368
*/
63546369
path: function () {
63556370
// Pre-9.0 uses v1 endpoint
6356-
if (this.versionCompare("9.0.2") < 0) {
6371+
if (this.disableV2SearchApi()) {
63576372
return Paths.jobs;
63586373
}
63596374
// Post-9.0 uses v2 endpoint
@@ -6391,6 +6406,7 @@ var __exportName = 'splunkjs';
63916406
// Passing the service version and versionCompare to this.path() before instantiating splunkjs.Service.Collection.
63926407
this.version = service.version;
63936408
this.versionCompare = service.versionCompare;
6409+
this.disableV2SearchApi = service.disableV2SearchApi;
63946410

63956411
this._super(service, this.path(), namespace);
63966412
// We perform the bindings so that every function works

client/splunk.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/splunk.test.js

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,7 @@ function outputHelpIfNecessary(cmd, options) {
17881788
this.version = params.version || "default";
17891789
this.timeout = params.timeout || 0;
17901790
this.autologin = true;
1791+
this.instanceType = "";
17911792

17921793
// Initialize autologin
17931794
// The reason we explicitly check to see if 'autologin'
@@ -1822,16 +1823,17 @@ function outputHelpIfNecessary(cmd, options) {
18221823

18231824
// We perform the bindings so that every function works
18241825
// properly when it is passed as a callback.
1825-
this._headers = utils.bind(this, this._headers);
1826-
this.fullpath = utils.bind(this, this.fullpath);
1827-
this.urlify = utils.bind(this, this.urlify);
1828-
this.get = utils.bind(this, this.get);
1829-
this.del = utils.bind(this, this.del);
1830-
this.post = utils.bind(this, this.post);
1831-
this.login = utils.bind(this, this.login);
1832-
this._shouldAutoLogin = utils.bind(this, this._shouldAutoLogin);
1833-
this._requestWrapper = utils.bind(this, this._requestWrapper);
1834-
this.getVersion = utils.bind(this, this.getVersion);
1826+
this._headers = utils.bind(this, this._headers);
1827+
this.fullpath = utils.bind(this, this.fullpath);
1828+
this.urlify = utils.bind(this, this.urlify);
1829+
this.get = utils.bind(this, this.get);
1830+
this.del = utils.bind(this, this.del);
1831+
this.post = utils.bind(this, this.post);
1832+
this.login = utils.bind(this, this.login);
1833+
this._shouldAutoLogin = utils.bind(this, this._shouldAutoLogin);
1834+
this._requestWrapper = utils.bind(this, this._requestWrapper);
1835+
this.getInfo = utils.bind(this, this.getInfo);
1836+
this.disableV2SearchApi = utils.bind(this, this.disableV2SearchApi);
18351837
},
18361838

18371839
/**
@@ -2002,19 +2004,21 @@ function outputHelpIfNecessary(cmd, options) {
20022004
* @method splunkjs.Context
20032005
* @private
20042006
*/
2005-
getVersion: function (callback) {
2007+
getInfo: function (callback) {
20062008
var that = this;
20072009
var url = this.paths.info;
20082010

20092011
callback = callback || function() {};
20102012

20112013
var wrappedCallback = function(err, response) {
20122014
var hasVersion = !!(!err && response.data && response.data.generator.version);
2015+
let hasInstanceType = !!(!err && response.data && response.data.generator["instance_type"]);
20132016

20142017
if (err || !hasVersion) {
20152018
callback(err || "No version found", false);
20162019
}
20172020
else {
2021+
that.instanceType = hasInstanceType ? response.data.generator["instance_type"] : "";
20182022
that.version = response.data.generator.version;
20192023
that.http.version = that.version;
20202024
callback(null, true);
@@ -2059,7 +2063,7 @@ function outputHelpIfNecessary(cmd, options) {
20592063
}
20602064
else {
20612065
that.sessionKey = response.data.sessionKey;
2062-
that.getVersion(callback);
2066+
that.getInfo(callback);
20632067
}
20642068
};
20652069
return this.http.post(
@@ -2236,6 +2240,16 @@ function outputHelpIfNecessary(cmd, options) {
22362240
}
22372241
}
22382242
return 0;
2243+
},
2244+
2245+
disableV2SearchApi: function(){
2246+
let val;
2247+
if(this.instanceType.toLowerCase() == "cloud"){
2248+
val = this.versionCompare("9.0.2209");
2249+
}else{
2250+
val = this.versionCompare("9.0.2")
2251+
}
2252+
return val < 0;
22392253
}
22402254
});
22412255

@@ -3668,7 +3682,7 @@ window.SplunkTest = {
36683682
params.q = query;
36693683

36703684
// Pre-9.0 uses GET and v1 endpoint
3671-
if (this.versionCompare("9.0.2") < 0) {
3685+
if (this.disableV2SearchApi()) {
36723686
return this.get(Paths.parser, params, function(err, response) {
36733687
if (err) {
36743688
callback(err);
@@ -6452,7 +6466,7 @@ window.SplunkTest = {
64526466
*/
64536467
path: function () {
64546468
// Pre-9.0 uses v1 endpoint
6455-
if (this.versionCompare("9.0.2") < 0) {
6469+
if (this.disableV2SearchApi()) {
64566470
return Paths.jobs + "/" + encodeURIComponent(this.name);
64576471
}
64586472
// Post-9.0 uses v2 endpoint
@@ -6477,6 +6491,7 @@ window.SplunkTest = {
64776491
// Passing the service version and versionCompare to this.path() before instantiating splunkjs.Service.Entity.
64786492
this.version = service.version;
64796493
this.versionCompare = service.versionCompare;
6494+
this.disableV2SearchApi = service.disableV2SearchApi;
64806495

64816496
this.name = sid;
64826497
this._super(service, this.path(), namespace);
@@ -6601,7 +6616,7 @@ window.SplunkTest = {
66016616
var eventsPath = Paths.jobsV2 + "/" + encodeURIComponent(this.name) + "/events";
66026617
// Splunk version pre-9.0 doesn't support v2
66036618
// v1(GET), v2(POST)
6604-
if (this.versionCompare("9.0.2") < 0) {
6619+
if (this.disableV2SearchApi()) {
66056620
eventsPath = Paths.jobs + "/" + encodeURIComponent(this.name) + "/events";
66066621
return this.get(eventsPath, params, function(err, response) {
66076622
if (err) {
@@ -6717,7 +6732,7 @@ window.SplunkTest = {
67176732
var resultsPreviewPath = Paths.jobsV2 + "/" + encodeURIComponent(this.name) + "/results_preview";
67186733
// Splunk version pre-9.0 doesn't support v2
67196734
// v1(GET), v2(POST)
6720-
if (this.versionCompare("9.0.2") < 0) {
6735+
if (this.disableV2SearchApi()) {
67216736
resultsPreviewPath = Paths.jobs + "/" + encodeURIComponent(this.name) + "/results_preview";
67226737
return this.get(resultsPreviewPath, params, function(err, response) {
67236738
if (err) {
@@ -6770,7 +6785,7 @@ window.SplunkTest = {
67706785
var resultsPath = Paths.jobsV2 + "/" + encodeURIComponent(this.name) + "/results";
67716786
// Splunk version pre-9.0 doesn't support v2
67726787
// v1(GET), v2(POST)
6773-
if (this.versionCompare("9.0.2") < 0) {
6788+
if (this.disableV2SearchApi()) {
67746789
resultsPath = Paths.jobs + "/" + encodeURIComponent(this.name) + "/results";
67756790
return this.get(resultsPath, params, function(err, response) {
67766791
if (err) {
@@ -7111,7 +7126,7 @@ window.SplunkTest = {
71117126
*/
71127127
path: function () {
71137128
// Pre-9.0 uses v1 endpoint
7114-
if (this.versionCompare("9.0.2") < 0) {
7129+
if (this.disableV2SearchApi()) {
71157130
return Paths.jobs;
71167131
}
71177132
// Post-9.0 uses v2 endpoint
@@ -7149,6 +7164,7 @@ window.SplunkTest = {
71497164
// Passing the service version and versionCompare to this.path() before instantiating splunkjs.Service.Collection.
71507165
this.version = service.version;
71517166
this.versionCompare = service.versionCompare;
7167+
this.disableV2SearchApi = service.disableV2SearchApi;
71527168

71537169
this._super(service, this.path(), namespace);
71547170
// We perform the bindings so that every function works
@@ -70981,6 +70997,7 @@ exports.setup = function (svc) {
7098170997
for (var i = 0; i < jobsList.length; i++) {
7098270998
assert.ok(jobsList[i]);
7098370999
}
71000+
7098471001
done();
7098571002
});
7098671003
});
@@ -74677,6 +74694,17 @@ exports.setup = function (svc) {
7467774694
done();
7467874695
});
7467974696
})
74697+
74698+
it("V2 Search APIs Enable/Disabled", function (done) {
74699+
let service = this.service;
74700+
let flag = service.disableV2SearchApi();
74701+
if(service.instanceType == "cloud"){
74702+
service.versionCompare("9.0.2209") < 0 ? assert.isTrue(flag) : assert.isFalse(flag);
74703+
}else{
74704+
service.versionCompare("9.0.2") < 0 ? assert.isTrue(flag) : assert.isFalse(flag);
74705+
}
74706+
done();
74707+
})
7468074708
})
7468174709
);
7468274710
};

client/splunk.test.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)