Skip to content

Callback promises migration #162

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 35 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4235212
code refactor
akaila-splunk Jun 27, 2022
3d29152
Update http.js
akaila-splunk Jul 5, 2022
27c389c
Update context.js
akaila-splunk Jul 5, 2022
e398c2d
Update service.js
akaila-splunk Jul 5, 2022
18e2f92
Update service.js
akaila-splunk Jul 5, 2022
4d6a05f
Update service.js
akaila-splunk Jul 12, 2022
a523a50
Promise refractoring
ashah-splunk Aug 2, 2022
0e19ed4
promise refactor changes
ashah-splunk Aug 4, 2022
2d8e4d2
Test cases updated with Async/await
ashah-splunk Aug 5, 2022
c231ff4
refactor crud func. methods
akaila-splunk Aug 8, 2022
dfe4c01
browser test cases updated.
ashah-splunk Aug 9, 2022
9a3fb7b
code refactoring
ashah-splunk Aug 9, 2022
14a09ef
Update endpoint.js
ashah-splunk Aug 9, 2022
9e1c203
update methods comment and example
akaila-splunk Aug 12, 2022
c4ee9e6
Update proxy_http.js
akaila-splunk Aug 17, 2022
8d6a651
testcase refactor
akaila-splunk Aug 30, 2022
c54ed14
Update test_utils.js
ashah-splunk Aug 30, 2022
13db35a
review updates
ashah-splunk Sep 19, 2022
8bb498a
Update browser.test.entry.js
ashah-splunk Sep 19, 2022
e640a36
merge updates from develop branch
ashah-splunk Sep 20, 2022
9c2633e
refactor browser side testcases
akaila-splunk Oct 11, 2022
882af21
updated compile files
ashah-splunk Oct 11, 2022
271c275
conflict resolve
ashah-splunk Oct 12, 2022
507f2f8
compiled files conflict resolve
ashah-splunk Oct 12, 2022
804c828
Revert "conflict resolve"
ashah-splunk Oct 12, 2022
6f73da3
Revert "compiled files conflict resolve"
ashah-splunk Oct 12, 2022
b6b17a8
conflict resolve
ashah-splunk Oct 12, 2022
dc131cc
Merge branch 'develop' into callback-promises-migration
ashah-splunk Oct 12, 2022
750f32d
compiled files
ashah-splunk Oct 12, 2022
c281e53
README changes
ashah-splunk Oct 14, 2022
cd9e97c
replace statuscode with 504
akaila-splunk Oct 31, 2022
6b7d83b
compiled files
ashah-splunk Oct 31, 2022
122ba74
Update CHANGELOG.md
akaila-splunk Oct 31, 2022
4465c19
update browser-side abort timeout
akaila-splunk Nov 2, 2022
e7aa58d
compiled files
ashah-splunk Nov 2, 2022
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
Prev Previous commit
Next Next commit
merge updates from develop branch
  • Loading branch information
ashah-splunk committed Sep 20, 2022
commit e640a36dfcfaaea3396de5cf27adb45114531413
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Generate docs
run: |
node sdkdo docs
zip -r docs.zip docs/${{ steps.pkgjson.outputs.packageVersion }}/refs
zip -r docs.zip docs/${{ steps.pkgjson.outputs.packageVersion }}

- name: Upload Artifact
uses: actions/upload-artifact@v3
Expand Down
34 changes: 25 additions & 9 deletions client/splunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,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 @@ -181,7 +182,8 @@ var __exportName = 'splunkjs';
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.getInfo = utils.bind(this, this.getInfo);
this.disableV2SearchApi = utils.bind(this, this.disableV2SearchApi);
},

/**
Expand Down Expand Up @@ -307,7 +309,7 @@ var __exportName = 'splunkjs';
* @method splunkjs.Context
* @private
*/
getVersion: function (response_timeout) {
getInfo: function (response_timeout) {
var that = this;
let url = this.paths.info;
return this.http.get(
Expand All @@ -318,11 +320,13 @@ var __exportName = 'splunkjs';
response_timeout
).then((response)=>{
let hasVersion = !!(response.data && response.data.generator.version);
let hasInstanceType = !!(response.data && response.data.generator["instance_type"]);

if (!hasVersion) {
return Promise.reject("No version found");
}
else{
that.instanceType = hasInstanceType ? response.data.generator["instance_type"] : "";
that.version = response.data.generator.version;
that.http.version = that.version;
return Promise.resolve(true);
Expand Down Expand Up @@ -362,7 +366,7 @@ var __exportName = 'splunkjs';
}
else {
that.sessionKey = response.data.sessionKey;
return that.getVersion();
return that.getInfo();
}
})
},
Expand Down Expand Up @@ -523,6 +527,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 @@ -2315,7 +2329,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, response_timeout).then((response) => {
return response.data;
});
Expand Down Expand Up @@ -4913,7 +4927,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 @@ -4938,6 +4952,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 @@ -5056,7 +5071,7 @@ var __exportName = 'splunkjs';
let 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, response_timeout).then((response) => {
return [response.data, that];
Expand Down Expand Up @@ -5158,7 +5173,7 @@ var __exportName = 'splunkjs';
let 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, response_timeout).then((response) => {
return [response.data, that];
Expand Down Expand Up @@ -5203,7 +5218,7 @@ var __exportName = 'splunkjs';
let 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, response_timeout).then((response) => {
return [response.data, that];
Expand Down Expand Up @@ -5489,7 +5504,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 @@ -5527,6 +5542,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 properly
Expand Down
2 changes: 1 addition & 1 deletion client/splunk.min.js

Large diffs are not rendered by default.

46 changes: 36 additions & 10 deletions client/splunk.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,7 @@ function outputHelpIfNecessary(cmd, options) {
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 @@ -1286,7 +1287,8 @@ function outputHelpIfNecessary(cmd, options) {
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.getInfo = utils.bind(this, this.getInfo);
this.disableV2SearchApi = utils.bind(this, this.disableV2SearchApi);
},

/**
Expand Down Expand Up @@ -1412,7 +1414,7 @@ function outputHelpIfNecessary(cmd, options) {
* @method splunkjs.Context
* @private
*/
getVersion: function (response_timeout) {
getInfo: function (response_timeout) {
var that = this;
let url = this.paths.info;
return this.http.get(
Expand All @@ -1423,11 +1425,13 @@ function outputHelpIfNecessary(cmd, options) {
response_timeout
).then((response)=>{
let hasVersion = !!(response.data && response.data.generator.version);
let hasInstanceType = !!(response.data && response.data.generator["instance_type"]);

if (!hasVersion) {
return Promise.reject("No version found");
}
else{
that.instanceType = hasInstanceType ? response.data.generator["instance_type"] : "";
that.version = response.data.generator.version;
that.http.version = that.version;
return Promise.resolve(true);
Expand Down Expand Up @@ -1467,7 +1471,7 @@ function outputHelpIfNecessary(cmd, options) {
}
else {
that.sessionKey = response.data.sessionKey;
return that.getVersion();
return that.getInfo();
}
})
},
Expand Down Expand Up @@ -1628,6 +1632,16 @@ function outputHelpIfNecessary(cmd, options) {
}
}
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 @@ -1662,7 +1676,6 @@ function outputHelpIfNecessary(cmd, options) {

window.SplunkTest = {
Utils : require('../../tests/test_utils'),
// Async : require('../../tests/test_async'),
Http : require('../../tests/test_http'),
Context : require('../../tests/test_context'),
Service : require('../../tests/test_service')
Expand Down Expand Up @@ -3028,7 +3041,7 @@ window.SplunkTest = {
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, response_timeout).then((response) => {
return response.data;
});
Expand Down Expand Up @@ -5626,7 +5639,7 @@ window.SplunkTest = {
*/
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 @@ -5651,6 +5664,7 @@ window.SplunkTest = {
// 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 @@ -5769,7 +5783,7 @@ window.SplunkTest = {
let 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, response_timeout).then((response) => {
return [response.data, that];
Expand Down Expand Up @@ -5871,7 +5885,7 @@ window.SplunkTest = {
let 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, response_timeout).then((response) => {
return [response.data, that];
Expand Down Expand Up @@ -5916,7 +5930,7 @@ window.SplunkTest = {
let 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, response_timeout).then((response) => {
return [response.data, that];
Expand Down Expand Up @@ -6202,7 +6216,7 @@ window.SplunkTest = {
*/
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 @@ -6240,6 +6254,7 @@ window.SplunkTest = {
// 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 properly
Expand Down Expand Up @@ -72513,6 +72528,17 @@ exports.setup = function (svc) {
assert.ok(info.properties().hasOwnProperty("serverName"));
assert.ok(info.properties().hasOwnProperty("os_version"));
})

it("V2 Search APIs Enable/Disabled", function (done) {
let service = this.service;
let flag = service.disableV2SearchApi();
if(service.instanceType == "cloud"){
service.versionCompare("9.0.2209") < 0 ? assert.isTrue(flag) : assert.isFalse(flag);
}else{
service.versionCompare("9.0.2") < 0 ? assert.isTrue(flag) : assert.isFalse(flag);
}
done();
})
})
);
};
Expand Down
2 changes: 1 addition & 1 deletion client/splunk.test.min.js

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
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 @@ -124,7 +125,8 @@
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.getInfo = utils.bind(this, this.getInfo);
this.disableV2SearchApi = utils.bind(this, this.disableV2SearchApi);
},

/**
Expand Down Expand Up @@ -250,7 +252,7 @@
* @method splunkjs.Context
* @private
*/
getVersion: function (response_timeout) {
getInfo: function (response_timeout) {
var that = this;
let url = this.paths.info;
return this.http.get(
Expand All @@ -261,11 +263,13 @@
response_timeout
).then((response)=>{
let hasVersion = !!(response.data && response.data.generator.version);
let hasInstanceType = !!(response.data && response.data.generator["instance_type"]);

if (!hasVersion) {
return Promise.reject("No version found");
}
else{
that.instanceType = hasInstanceType ? response.data.generator["instance_type"] : "";
that.version = response.data.generator.version;
that.http.version = that.version;
return Promise.resolve(true);
Expand Down Expand Up @@ -305,7 +309,7 @@
}
else {
that.sessionKey = response.data.sessionKey;
return that.getVersion();
return that.getInfo();
}
})
},
Expand Down Expand Up @@ -466,6 +470,16 @@
}
}
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
Loading