@@ -1788,6 +1788,7 @@ function outputHelpIfNecessary(cmd, options) {
1788
1788
this.version = params.version || "default";
1789
1789
this.timeout = params.timeout || 0;
1790
1790
this.autologin = true;
1791
+ this.instanceType = "";
1791
1792
1792
1793
// Initialize autologin
1793
1794
// The reason we explicitly check to see if 'autologin'
@@ -1822,16 +1823,17 @@ function outputHelpIfNecessary(cmd, options) {
1822
1823
1823
1824
// We perform the bindings so that every function works
1824
1825
// 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);
1835
1837
},
1836
1838
1837
1839
/**
@@ -2002,19 +2004,21 @@ function outputHelpIfNecessary(cmd, options) {
2002
2004
* @method splunkjs.Context
2003
2005
* @private
2004
2006
*/
2005
- getVersion : function (callback) {
2007
+ getInfo : function (callback) {
2006
2008
var that = this;
2007
2009
var url = this.paths.info;
2008
2010
2009
2011
callback = callback || function() {};
2010
2012
2011
2013
var wrappedCallback = function(err, response) {
2012
2014
var hasVersion = !!(!err && response.data && response.data.generator.version);
2015
+ let hasInstanceType = !!(!err && response.data && response.data.generator["instance_type"]);
2013
2016
2014
2017
if (err || !hasVersion) {
2015
2018
callback(err || "No version found", false);
2016
2019
}
2017
2020
else {
2021
+ that.instanceType = hasInstanceType ? response.data.generator["instance_type"] : "";
2018
2022
that.version = response.data.generator.version;
2019
2023
that.http.version = that.version;
2020
2024
callback(null, true);
@@ -2059,7 +2063,7 @@ function outputHelpIfNecessary(cmd, options) {
2059
2063
}
2060
2064
else {
2061
2065
that.sessionKey = response.data.sessionKey;
2062
- that.getVersion (callback);
2066
+ that.getInfo (callback);
2063
2067
}
2064
2068
};
2065
2069
return this.http.post(
@@ -2236,6 +2240,16 @@ function outputHelpIfNecessary(cmd, options) {
2236
2240
}
2237
2241
}
2238
2242
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;
2239
2253
}
2240
2254
});
2241
2255
@@ -3668,7 +3682,7 @@ window.SplunkTest = {
3668
3682
params.q = query;
3669
3683
3670
3684
// Pre-9.0 uses GET and v1 endpoint
3671
- if (this.versionCompare("9.0.2") < 0 ) {
3685
+ if (this.disableV2SearchApi() ) {
3672
3686
return this.get(Paths.parser, params, function(err, response) {
3673
3687
if (err) {
3674
3688
callback(err);
@@ -6452,7 +6466,7 @@ window.SplunkTest = {
6452
6466
*/
6453
6467
path: function () {
6454
6468
// Pre-9.0 uses v1 endpoint
6455
- if (this.versionCompare("9.0.2") < 0 ) {
6469
+ if (this.disableV2SearchApi() ) {
6456
6470
return Paths.jobs + "/" + encodeURIComponent(this.name);
6457
6471
}
6458
6472
// Post-9.0 uses v2 endpoint
@@ -6477,6 +6491,7 @@ window.SplunkTest = {
6477
6491
// Passing the service version and versionCompare to this.path() before instantiating splunkjs.Service.Entity.
6478
6492
this.version = service.version;
6479
6493
this.versionCompare = service.versionCompare;
6494
+ this.disableV2SearchApi = service.disableV2SearchApi;
6480
6495
6481
6496
this.name = sid;
6482
6497
this._super(service, this.path(), namespace);
@@ -6601,7 +6616,7 @@ window.SplunkTest = {
6601
6616
var eventsPath = Paths.jobsV2 + "/" + encodeURIComponent(this.name) + "/events";
6602
6617
// Splunk version pre-9.0 doesn't support v2
6603
6618
// v1(GET), v2(POST)
6604
- if (this.versionCompare("9.0.2") < 0 ) {
6619
+ if (this.disableV2SearchApi() ) {
6605
6620
eventsPath = Paths.jobs + "/" + encodeURIComponent(this.name) + "/events";
6606
6621
return this.get(eventsPath, params, function(err, response) {
6607
6622
if (err) {
@@ -6717,7 +6732,7 @@ window.SplunkTest = {
6717
6732
var resultsPreviewPath = Paths.jobsV2 + "/" + encodeURIComponent(this.name) + "/results_preview";
6718
6733
// Splunk version pre-9.0 doesn't support v2
6719
6734
// v1(GET), v2(POST)
6720
- if (this.versionCompare("9.0.2") < 0 ) {
6735
+ if (this.disableV2SearchApi() ) {
6721
6736
resultsPreviewPath = Paths.jobs + "/" + encodeURIComponent(this.name) + "/results_preview";
6722
6737
return this.get(resultsPreviewPath, params, function(err, response) {
6723
6738
if (err) {
@@ -6770,7 +6785,7 @@ window.SplunkTest = {
6770
6785
var resultsPath = Paths.jobsV2 + "/" + encodeURIComponent(this.name) + "/results";
6771
6786
// Splunk version pre-9.0 doesn't support v2
6772
6787
// v1(GET), v2(POST)
6773
- if (this.versionCompare("9.0.2") < 0 ) {
6788
+ if (this.disableV2SearchApi() ) {
6774
6789
resultsPath = Paths.jobs + "/" + encodeURIComponent(this.name) + "/results";
6775
6790
return this.get(resultsPath, params, function(err, response) {
6776
6791
if (err) {
@@ -7111,7 +7126,7 @@ window.SplunkTest = {
7111
7126
*/
7112
7127
path: function () {
7113
7128
// Pre-9.0 uses v1 endpoint
7114
- if (this.versionCompare("9.0.2") < 0 ) {
7129
+ if (this.disableV2SearchApi() ) {
7115
7130
return Paths.jobs;
7116
7131
}
7117
7132
// Post-9.0 uses v2 endpoint
@@ -7149,6 +7164,7 @@ window.SplunkTest = {
7149
7164
// Passing the service version and versionCompare to this.path() before instantiating splunkjs.Service.Collection.
7150
7165
this.version = service.version;
7151
7166
this.versionCompare = service.versionCompare;
7167
+ this.disableV2SearchApi = service.disableV2SearchApi;
7152
7168
7153
7169
this._super(service, this.path(), namespace);
7154
7170
// We perform the bindings so that every function works
@@ -70981,6 +70997,7 @@ exports.setup = function (svc) {
70981
70997
for (var i = 0; i < jobsList.length; i++) {
70982
70998
assert.ok(jobsList[i]);
70983
70999
}
71000
+
70984
71001
done();
70985
71002
});
70986
71003
});
@@ -74677,6 +74694,17 @@ exports.setup = function (svc) {
74677
74694
done();
74678
74695
});
74679
74696
})
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
+ })
74680
74708
})
74681
74709
);
74682
74710
};
0 commit comments