Skip to content

Commit

Permalink
Use Node-RED internal helper function to evaluate configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
nj0yeh committed Nov 14, 2024
1 parent 4d4e37b commit 8372ca5
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions elastic-search-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,22 @@ module.exports = function (RED) {
let transports = [];

// Elastic settings
let url = "";
if(config.urlType == "global"){
url = this.context().global.get(config.url);
} else {
url = config.url;
}
let url = RED.util.evaluateNodeProperty(config.url, config.urlType, this);
if (url == "") {
this.error("Elastic search url is not set");
}

let user = "";
if(config.usernameType == "global") {
user = this.context().global.get(this.credentials.username);
} else {
user = this.credentials.username;
}
let user = RED.util.evaluateNodeProperty(this.credentials.username, config.usernameType, this);
if (user == "") {
this.error("Elastic search username is not set");
}

let password = "";
if(config.passwordType == "global") {
password = this.context().global.get(this.credentials.password);
} else {
password = this.credentials.password;
}
let password = RED.util.evaluateNodeProperty(this.credentials.password, config.passwordType, this);
if (password == "") {
this.error("Elastic search password is not set");
}

let index = "";
if(config.indexType == "global") {
index = this.context().global.get(this.credentials.index);
} else {
index = this.credentials.index;
}
let index = RED.util.evaluateNodeProperty(this.credentials.index, config.indexType, this);
if (index == "") {
this.error("Elastic search index is not set");
}
Expand Down

0 comments on commit 8372ca5

Please sign in to comment.