Skip to content

.conf CRUD functionality added #141

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 11 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactored
  • Loading branch information
vmalaviya-splunk committed Dec 2, 2021
commit b00bef30ad073b5b187958d7f9a9ccdff543fd92
35 changes: 19 additions & 16 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,29 +356,32 @@
*
* @method splunkjs.Context
*/
get: function(path, params, callback) {
get: function(path, params, callback, isAsync) {
var that = this;
var request = function(callback) {

if(isAsync) {
return that.http.get(
that.urlify(path),
that._headers(),
params,
that.timeout,
callback
null,
true
);
};

return this._requestWrapper(request, callback);
},

getAsync: function(path, params) {
var that = this;
return that.http.getAsync(
that.urlify(path),
that._headers(),
params,
that.timeout,
);
}
else {
var request = function(callback) {
return that.http.get(
that.urlify(path),
that._headers(),
params,
that.timeout,
callback
);
};

return this._requestWrapper(request, callback);
}
},

/**
Expand Down
19 changes: 4 additions & 15 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,15 @@
*
* @method splunkjs.Http
*/
get: function(url, headers, params, timeout, callback) {
get: function(url, headers, params, timeout, callback, isAsync) {
var message = {
method: "GET",
headers: headers,
timeout: timeout,
query: params
};

return this.request(url, message, callback);
},

getAsync: function(url, headers, params, timeout) {
var message = {
method: "GET",
headers: headers,
timeout: timeout,
query: params
};

return this.request(url, message, true);
return this.request(url, message, callback, isAsync);
},

/**
Expand Down Expand Up @@ -213,7 +202,7 @@
* @method splunkjs.Http
* @see makeRequest
*/
request: function(url, message, callback) {
request: function(url, message, callback, isAsync) {
var that = this;
var query = utils.getWithVersion(this.version, queryBuilderMap)(message);
var post = message.post || {};
Expand Down Expand Up @@ -241,7 +230,7 @@

// Now we can invoke the user-provided HTTP class,
// passing in our "wrapped" callback
if(callback && typeof callback === 'boolean') {
if(isAsync) {
return this.makeRequestAsync(encodedUrl, options);
}
else {
Expand Down
26 changes: 6 additions & 20 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@
*
* @method splunkjs.Service.Endpoint
*/
get: function(relpath, params, callback) {
get: function(relpath, params, callback, isAsync) {
var url = this.qualifiedPath;

// If we have a relative path, we will append it with a preceding
Expand All @@ -729,22 +729,8 @@
return this.service.get(
url,
params,
callback
);
},

getAsync: function(relpath, params) {
var url = this.qualifiedPath;

// If we have a relative path, we will append it with a preceding
// slash.
if (relpath) {
url = url + "/" + relpath;
}

return this.service.getAsync(
url,
params,
callback,
isAsync
);
},

Expand Down Expand Up @@ -1417,7 +1403,7 @@
}

var that = this;
var response = await that.getAsync("", options);
var response = await that.get("", options, null, true);
that._load(response.body);
return that;
},
Expand Down Expand Up @@ -3125,7 +3111,7 @@
var that = this;

// 1. Fetch files list
var response = await this.getAsync("", {__conf: filename});
var response = await this.get("", {__conf: filename}, null, true);

// 2. Filter the files
var files = response
Expand Down Expand Up @@ -3169,7 +3155,7 @@
}
},

createAsync: async function (configs, svc, filename, stanza, keyValueMap, callback) {
createAsync: async function (filename, stanza, keyValueMap, callback) {
callback = callback || function() {};
var that = this;

Expand Down
2 changes: 1 addition & 1 deletion tests/service_tests/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ exports.setup = function (svc) {
keyValueMap[property1] = value1;
keyValueMap[property2] = value2;

configs.createAsync(configs, svc, filename, stanza, keyValueMap, done);
configs.createAsync(filename, stanza, keyValueMap, done);
},
async function (done) {
var configs = svc.configurations(namespace);
Expand Down