Skip to content
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
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@

if (typeof(window) === 'undefined') {
root.NodeHttp = require('./lib/platform/node/node_http').NodeHttp;
} else {
let jqueryHttp = require('./lib/platform/client/jquery_http').JQueryHttp;
let proxyHttps = require('./lib/platform/client/proxy_http');
root.ProxyHttp = proxyHttps.ProxyHttp;
root.JQueryHttp = jqueryHttp;
root.SplunkWebHttp = proxyHttps.SplunkWebHttp;
}
})();
44 changes: 44 additions & 0 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,50 @@
throw new Error("While creating StoragePasswords, namespace cannot have wildcards.");
}
return this._super(params,response_timeout);
},
createOrReplace: async function (params, response_timeout) {
let that = this;

const { name, realm } = params;

// Check if password exists
let passwordExists = this.does_storage_password_exist(realm, name);

// If password exists delete it
if (passwordExists) {
await this.del(realm + ":" + name + ":");
}

let response = await this.post("", params, response_timeout);
let props = response.data.entry;
if (utils.isArray(props)) {
props = props[0];
}

let entity = that.instantiateEntity(props);
entity._load(props);
if (that.fetchOnEntityCreation) {
await entity.fetch(response_timeout);
}
let passwordCreated = false;

while (!passwordCreated) {
await this.fetch(response_timeout);
passwordCreated = this.does_storage_password_exist(realm, name);
}

return entity;
},
does_storage_password_exist: function (realm, name) {
let storage_passwords = this.list();
const password_id = realm + ":" + name + ":";

for (let index = 0; index < storage_passwords.length; index++) {
if (storage_passwords[index].name === password_id) {
return true;
}
}
return false;
}
});

Expand Down
16 changes: 16 additions & 0 deletions tests/service_tests/storagepasswords.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,22 @@ exports.setup = function (svc) {
assert.strictEqual(startcount, storagePasswords.list().length);
})

it("Create Or Replace StoragePassword", async function () {
let startcount = -1;
let name = "delete-me-" + getNextId();
let realm = "delete-me-" + getNextId();
var that = this;
let storagePasswords = await that.service.storagePasswords().fetch();
startcount = storagePasswords.list().length;
let storagePasswordOld = await storagePasswords.createOrReplace({ name: name, realm: realm, password: "changed!" });
assert.strictEqual(name, storagePasswordOld.properties().username);
let storagePassword = await storagePasswords.createOrReplace({ name: name, realm: realm, password: "changed!" });
assert.strictEqual(name, storagePassword.properties().username);
assert.strictEqual(realm + ":" + name + ":", storagePassword.name);
assert.strictEqual("changed!", storagePassword.properties().clear_password);
assert.strictEqual(realm, storagePassword.properties().realm);
})

it("Read", async function () {
let startcount = -1;
let name = "delete-me-" + getNextId();
Expand Down