Skip to content

Update version checks for v2 #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 46 additions & 24 deletions client/splunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ var __exportName = 'splunkjs';
this.version = params.version || "default";
this.timeout = params.timeout || 0;
this.autologin = true;
this.instanceType = "";

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

// We perform the bindings so that every function works
// properly when it is passed as a callback.
this._headers = utils.bind(this, this._headers);
this.fullpath = utils.bind(this, this.fullpath);
this.urlify = utils.bind(this, this.urlify);
this.get = utils.bind(this, this.get);
this.del = utils.bind(this, this.del);
this.post = utils.bind(this, this.post);
this.login = utils.bind(this, this.login);
this._shouldAutoLogin = utils.bind(this, this._shouldAutoLogin);
this._requestWrapper = utils.bind(this, this._requestWrapper);
this.getVersion = utils.bind(this, this.getVersion);
this._headers = utils.bind(this, this._headers);
this.fullpath = utils.bind(this, this.fullpath);
this.urlify = utils.bind(this, this.urlify);
this.get = utils.bind(this, this.get);
this.del = utils.bind(this, this.del);
this.post = utils.bind(this, this.post);
this.login = utils.bind(this, this.login);
this._shouldAutoLogin = utils.bind(this, this._shouldAutoLogin);
this._requestWrapper = utils.bind(this, this._requestWrapper);
this.getInfo = utils.bind(this, this.getInfo);
this.disableV2SearchApi = utils.bind(this, this.disableV2SearchApi);
},

/**
Expand Down Expand Up @@ -897,19 +899,21 @@ var __exportName = 'splunkjs';
* @method splunkjs.Context
* @private
*/
getVersion: function (callback) {
getInfo: function (callback) {
var that = this;
var url = this.paths.info;

callback = callback || function() {};

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

if (err || !hasVersion) {
callback(err || "No version found", false);
}
else {
that.instanceType = hasInstanceType ? response.data.generator["instance_type"] : "";
that.version = response.data.generator.version;
that.http.version = that.version;
callback(null, true);
Expand Down Expand Up @@ -954,7 +958,7 @@ var __exportName = 'splunkjs';
}
else {
that.sessionKey = response.data.sessionKey;
that.getVersion(callback);
that.getInfo(callback);
}
};
return this.http.post(
Expand Down Expand Up @@ -1131,6 +1135,16 @@ var __exportName = 'splunkjs';
}
}
return 0;
},

disableV2SearchApi: function(){
let val;
if(this.instanceType.toLowerCase() == "cloud"){
val = this.versionCompare("9.0.2209");
}else{
val = this.versionCompare("9.0.2")
}
return val < 0;
}
});

Expand Down Expand Up @@ -2910,7 +2924,7 @@ var __exportName = 'splunkjs';
params.q = query;

// Pre-9.0 uses GET and v1 endpoint
if (this.versionCompare("9.0") < 0) {
if (this.disableV2SearchApi()) {
return this.get(Paths.parser, params, function(err, response) {
if (err) {
callback(err);
Expand Down Expand Up @@ -4433,6 +4447,12 @@ var __exportName = 'splunkjs';
*/
init: function(service, namespace) {
this._super(service, this.path(), namespace);
},
create: function(params, callback){
if(this.service.app == '-' || this.service.owner == '-'){
throw new Error("While creating StoragePasswords, namespace cannot have wildcards.");
}
this._super(params,callback);
}
});

Expand Down Expand Up @@ -5688,7 +5708,7 @@ var __exportName = 'splunkjs';
*/
path: function () {
// Pre-9.0 uses v1 endpoint
if (this.versionCompare("9.0") < 0) {
if (this.disableV2SearchApi()) {
return Paths.jobs + "/" + encodeURIComponent(this.name);
}
// Post-9.0 uses v2 endpoint
Expand All @@ -5713,6 +5733,7 @@ var __exportName = 'splunkjs';
// Passing the service version and versionCompare to this.path() before instantiating splunkjs.Service.Entity.
this.version = service.version;
this.versionCompare = service.versionCompare;
this.disableV2SearchApi = service.disableV2SearchApi;

this.name = sid;
this._super(service, this.path(), namespace);
Expand Down Expand Up @@ -5837,7 +5858,7 @@ var __exportName = 'splunkjs';
var eventsPath = Paths.jobsV2 + "/" + encodeURIComponent(this.name) + "/events";
// Splunk version pre-9.0 doesn't support v2
// v1(GET), v2(POST)
if (this.versionCompare("9.0") < 0) {
if (this.disableV2SearchApi()) {
eventsPath = Paths.jobs + "/" + encodeURIComponent(this.name) + "/events";
return this.get(eventsPath, params, function(err, response) {
if (err) {
Expand Down Expand Up @@ -5953,7 +5974,7 @@ var __exportName = 'splunkjs';
var resultsPreviewPath = Paths.jobsV2 + "/" + encodeURIComponent(this.name) + "/results_preview";
// Splunk version pre-9.0 doesn't support v2
// v1(GET), v2(POST)
if (this.versionCompare("9.0") < 0) {
if (this.disableV2SearchApi()) {
resultsPreviewPath = Paths.jobs + "/" + encodeURIComponent(this.name) + "/results_preview";
return this.get(resultsPreviewPath, params, function(err, response) {
if (err) {
Expand Down Expand Up @@ -6006,7 +6027,7 @@ var __exportName = 'splunkjs';
var resultsPath = Paths.jobsV2 + "/" + encodeURIComponent(this.name) + "/results";
// Splunk version pre-9.0 doesn't support v2
// v1(GET), v2(POST)
if (this.versionCompare("9.0") < 0) {
if (this.disableV2SearchApi()) {
resultsPath = Paths.jobs + "/" + encodeURIComponent(this.name) + "/results";
return this.get(resultsPath, params, function(err, response) {
if (err) {
Expand Down Expand Up @@ -6347,7 +6368,7 @@ var __exportName = 'splunkjs';
*/
path: function () {
// Pre-9.0 uses v1 endpoint
if (this.versionCompare("9.0") < 0) {
if (this.disableV2SearchApi()) {
return Paths.jobs;
}
// Post-9.0 uses v2 endpoint
Expand Down Expand Up @@ -6385,6 +6406,7 @@ var __exportName = 'splunkjs';
// Passing the service version and versionCompare to this.path() before instantiating splunkjs.Service.Collection.
this.version = service.version;
this.versionCompare = service.versionCompare;
this.disableV2SearchApi = service.disableV2SearchApi;

this._super(service, this.path(), namespace);
// We perform the bindings so that every function works
Expand Down Expand Up @@ -29945,7 +29967,7 @@ module.exports={
"_args": [
[
"elliptic@6.5.4",
"/Users/tpavlik/src/enterprise/semantic-versioning/splunk-sdk-javascript"
"/Users/abhis/Documents/JS/splunk-sdk-javascript"
]
],
"_development": true,
Expand All @@ -29971,7 +29993,7 @@ module.exports={
],
"_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz",
"_spec": "6.5.4",
"_where": "/Users/tpavlik/src/enterprise/semantic-versioning/splunk-sdk-javascript",
"_where": "/Users/abhis/Documents/JS/splunk-sdk-javascript",
"author": {
"name": "Fedor Indutny",
"email": "fedor@indutny.com"
Expand Down Expand Up @@ -39855,7 +39877,7 @@ module.exports={
"_args": [
[
"needle@3.0.0",
"/Users/tpavlik/src/enterprise/semantic-versioning/splunk-sdk-javascript"
"/Users/abhis/Documents/JS/splunk-sdk-javascript"
]
],
"_from": "needle@3.0.0",
Expand All @@ -39879,13 +39901,13 @@ module.exports={
],
"_resolved": "https://registry.npmjs.org/needle/-/needle-3.0.0.tgz",
"_spec": "3.0.0",
"_where": "/Users/tpavlik/src/enterprise/semantic-versioning/splunk-sdk-javascript",
"_where": "/Users/abhis/Documents/JS/splunk-sdk-javascript",
"author": {
"name": "Tomás Pollak",
"email": "tomas@forkhq.com"
},
"bin": {
"needle": "bin/needle"
"needle": "./bin/needle"
},
"bugs": {
"url": "https://github.com/tomas/needle/issues"
Expand Down Expand Up @@ -55692,7 +55714,7 @@ function extend() {
},{}],259:[function(require,module,exports){
module.exports={
"name": "splunk-sdk",
"version": "1.11.0",
"version": "1.12.0",
"description": "SDK for usage with the Splunk REST API",
"homepage": "http://dev.splunk.com",
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion client/splunk.min.js

Large diffs are not rendered by default.

Loading