Skip to content

Commit 46ef112

Browse files
Merge pull request #176 from splunk/release/2.0.0
Release/2.0.0
2 parents 5dbfad3 + 16a71a8 commit 46ef112

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+27476
-33855
lines changed

.github/workflows/release.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ jobs:
2222
id: pkgjson
2323

2424
- name: Generate docs
25-
run: |
26-
node sdkdo docs
27-
zip -r docs.zip docs-${{ steps.pkgjson.outputs.packageVersion }}
25+
run: node sdkdo docs
2826

2927
- name: Upload Artifact
3028
uses: actions/upload-artifact@v3
3129
with:
32-
name: apidocs
33-
path: docs.zip
30+
name: js_sdk_docs
31+
path: docs-${{ steps.pkgjson.outputs.packageVersion }}/

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Splunk Enterprise SDK for JavaScript Changelog
22

3+
## v2.0.0
4+
5+
### New features and APIs
6+
* Callbacks have been removed and instead we are returning Promises which enables users to use Async/Await features of JS. ([PR#162](https://github.com/splunk/splunk-sdk-javascript/pull/162))
7+
* Added 'response_timeout' parameter which enables user to specify the timeout for a particular API call.
8+
* Removed Async.js file and the required methods have been migrated to Utils.js following the Promise structure.
9+
10+
### Minor changes
11+
* Update doc generation logic in GitHub ci ([PR#167](https://github.com/splunk/splunk-sdk-javascript/pull/167))
12+
* Updated minimist library versions ([PR#166](https://github.com/splunk/splunk-sdk-javascript/pull/166))
13+
* Added feature that allows to update ACL properties of an entity ([PR#170](https://github.com/splunk/splunk-sdk-javascript/pull/170))
14+
* Support for updated SDK examples ([PR#171](https://github.com/splunk/splunk-sdk-javascript/pull/171))
15+
316
## v1.12.1
417

518
### Minor changes

README.md

+99-88
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Build Status](https://travis-ci.org/splunk/splunk-sdk-javascript.svg?branch=master)](https://travis-ci.org/splunk/splunk-sdk-javascript)
22
# The Splunk Enterprise Software Development Kit for JavaScript
33

4-
#### Version 1.12.1
4+
#### Version 2.0.0
55

66
The Splunk Enterprise Software Development Kit (SDK) for JavaScript contains library code and examples designed to enable developers to build applications using the Splunk platform and JavaScript. This SDK supports server-side and client-side JavaScript.
77

@@ -52,12 +52,44 @@ To use the Splunk Enterprise SDK for JavaScript with your Node.js programs, inst
5252

5353
Then, to include the Splunk Enterprise SDK for JavaScript, use the `require` function in your code:
5454

55-
var splunkjs = require('splunk-sdk');
55+
let splunkjs = require('splunk-sdk');
5656

5757
## Usage
5858

5959
The following examples show you how to list search jobs using client-side and server-side code.
6060

61+
### Migrate from Callbacks(v1.x) to Promise/async-await(v2.x)
62+
63+
Previous Callback Approach:
64+
```javascript
65+
let appName = "<app-name>";
66+
67+
service.apps().fetch(function (err, apps) {
68+
if (err) {
69+
done(err);
70+
}
71+
let appList = apps.list();
72+
// other code
73+
done();
74+
});
75+
```
76+
77+
From v2.x, Splunk Enterprise SDK for JavaScript methods are updated to return Promises, which will enable users to utilize Async/await feature of JS.
78+
79+
Promise Approach:
80+
```javascript
81+
let appName = "<app-name>";
82+
try {
83+
let apps = await service.apps().fetch();
84+
let appList = apps.list();
85+
// other code
86+
} catch (err) {
87+
console.log("There was an error retrieving the list of applications:", err);
88+
}
89+
```
90+
91+
>**Note**: `abort()` method has been replaced with 'response_timeout' parameter which enables user to specify the timeout for a particular API call.
92+
6193
### Client-side code example
6294

6395
This HTML example uses the Splunk Enterprise SDK for JavaScript to list all jobs:
@@ -66,22 +98,18 @@ This HTML example uses the Splunk Enterprise SDK for JavaScript to list all jobs
6698
<script type="text/javascript" src="jquery.min.js"></script>
6799

68100
<script type="text/javascript" charset="utf-8">
69-
70-
var service = new splunkjs.Service({username: "admin", password: "changed!"});
71-
service.login(function(err, success) {
72-
if (err) {
73-
throw err;
101+
try {
102+
let service = new splunkjs.Service({username: "admin", password: "changed!"});
103+
await service.login();
104+
console.log("Login was successful");
105+
let jobs = await service.jobs().fetch();
106+
let jobList = jobs.list();
107+
for(let i = 0; i < jobList.length; i++) {
108+
console.log("Job " + i + ": " + jobList[i].sid);
74109
}
75-
76-
console.log("Login was successful: " + success);
77-
service.jobs().fetch(function(err, jobs) {
78-
var jobList = jobs.list();
79-
for(var i = 0; i < jobList.length; i++) {
80-
console.log("Job " + i + ": " + jobList[i].sid);
81-
}
82-
});
83-
});
84-
110+
} catch(err) {
111+
console.log(err);
112+
}
85113
</script>
86114
```
87115

@@ -92,22 +120,21 @@ This example shows how to use the Splunk Enterprise SDK for JavaScript and Node.
92120
##### Login with username and password
93121

94122
```javascript
95-
var splunkjs = require('splunk-sdk');
96-
97-
var service = new splunkjs.Service({username: "admin", password: "changed!"});
98-
service.login(function(err, success) {
99-
if (err) {
100-
throw err;
101-
}
123+
let splunkjs = require('splunk-sdk');
102124

125+
let service = new splunkjs.Service({username: "admin", password: "changed!"});
126+
try {
127+
await service.login();
103128
console.log("Login was successful: " + success);
104-
service.jobs().fetch(function(err, jobs) {
105-
var jobList = jobs.list();
106-
for(var i = 0; i < jobList.length; i++) {
107-
console.log("Job " + i + ": " + jobList[i].sid);
108-
}
109-
});
110-
});
129+
let jobs = await jobs.fetch();
130+
let jobList = jobs.list();
131+
for(let i = 0; i < jobList.length; i++) {
132+
console.log("Job " + i + ": " + jobList[i].sid);
133+
}
134+
} catch(err) {
135+
console.log(err);
136+
}
137+
111138
```
112139
##### Login with sessionKey
113140

@@ -117,24 +144,20 @@ curl -k -u <username>:<password> <scheme>://<host>:<port>/services/auth/login -
117144
```
118145

119146
```javascript
120-
var serviceWithSessionKey = new splunkjs.Service(
121-
{
122-
// Replace the host if you are accessing remote host
123-
scheme: 'https',
124-
host: 'localhost',
125-
port: '8089',
126-
sessionKey: SESSION_KEY, // Add your sessionKey here
127-
version: '9.0',
128-
});
129-
130-
serviceWithSessionKey.get("search/jobs", { count: 1 }, function (err, res) {
131-
if (err) {
132-
console.log(err);
133-
} else }
134-
console.log("Login successful with sessionKey");
135-
}
147+
let serviceWithSessionKey = new splunkjs.Service({
148+
// Replace the host if you are accessing remote host
149+
scheme: 'https',
150+
host: 'localhost',
151+
port: '8089',
152+
sessionKey: SESSION_KEY, // Add your sessionKey here
153+
version: '9.0',
136154
});
137-
```
155+
try {
156+
let jobs = await serviceWithSessionKey.jobs({ count: 1 });
157+
console.log("Login successful with sessionKey");
158+
} catch(err) {
159+
console.log(err);
160+
}
138161

139162
##### Login with token
140163

@@ -159,22 +182,21 @@ Go to settings > Tokens and click on 'Enable Token Authentication'
159182
```
160183

161184
```javascript
162-
var serviceWithBearerToken = new splunkjs.Service(
163-
{
164-
// Replace the host if you are accessing remote host
165-
scheme: 'https',
166-
host: 'localhost',
167-
port: '8089',
168-
sessionKey: TOKEN, // Add your token here
169-
version: '8',
170-
});
171-
172-
serviceWithBearerToken.get("search/jobs", { count: 2 }, function (err, res) {
173-
if (err)
174-
console.log(err);
175-
else
176-
console.log("Login successful with bearer token");
185+
let serviceWithBearerToken = new splunkjs.Service({
186+
// Replace the host if you are accessing remote host
187+
scheme: 'https',
188+
host: 'localhost',
189+
port: '8089',
190+
sessionKey: TOKEN, // Add your token here
191+
version: '8',
177192
});
193+
try {
194+
let res = await serviceWithBearerToken.jobs({ count: 2 });
195+
console.log("Login successful with bearer token");
196+
} catch(err) {
197+
console.log(err);
198+
}
199+
178200
```
179201

180202
### Modular inputs examples
@@ -224,29 +246,18 @@ Save the file as **.splunkrc** in the current user's home directory.
224246
225247
### Create/Update a .conf file
226248
```javascript
227-
228-
Async.chain([
229-
function (done) {
230-
// Fetch configurations
231-
var configs = svc.configurations(namespace);
232-
configs.fetch(done);
233-
},
234-
async function (configs, done) {
235-
// Create a key-value map to store under a stanza
236-
const filename = "app.conf";
237-
const stanzaName = "install";
238-
var keyValueMap = {}
239-
keyValueMap["state"] = "enabled";
240-
keyValueMap["python.version"] = "python3";
241-
242-
// If file/stanza doesn't exist, it will be created
243-
// else it will be updated.
244-
configs.createAsync(filename, stanzaName, keyValueMap, done);
245-
}
246-
],
247-
function (err) {
248-
done();
249-
});
249+
let configs = svc.configurations(namespace);
250+
configs = await configs.fetch();
251+
// Create a key-value map to store under a stanza
252+
const filename = "app.conf";
253+
const stanzaName = "install";
254+
let keyValueMap = {};
255+
keyValueMap["state"] = "enabled";
256+
keyValueMap["python.version"] = "python3";
257+
258+
// If file/stanza doesn't exist, it will be created
259+
// else it will be updated.
260+
await configs.createAsync(filename, stanzaName, keyValueMap);
250261
```
251262
252263
## Development
@@ -276,9 +287,9 @@ To run all tests, enter:
276287
277288
node sdkdo tests
278289
279-
To run the HTTP and the Async tests, enter:
290+
To run the HTTP and the utils tests, enter:
280291
281-
node sdkdo tests http,async
292+
node sdkdo tests http,utils
282293
283294
To run tests containing a particular string, enter:
284295

0 commit comments

Comments
 (0)