feat: #6533 salix class to handle salix calls

This commit is contained in:
Javier Segarra 2024-04-24 14:15:44 +02:00
parent 2bb99bf093
commit ac21ae5b92
1 changed files with 43 additions and 0 deletions

43
lib/salix.js Normal file
View File

@ -0,0 +1,43 @@
module.exports = class Salix {
constructor() {
this.conf = null;
this._logInfo = [];
this._salixVersion = null;
}
async init(logger) {
this.conf = logger.conf;
setInterval(() => this.getSalixVersion, this.conf.salix.renewInterval);
await this.salixLogInfo();
}
async getSalixVersion(){
console.log("SALIX - CHECK VERSION");
let salixCall = await fetch(`${this.conf.salix.url}/applications/version`, {
method: "GET",
});
let salixVersion = JSON.parse(await salixCall.text());
console.log("SALIX - VERSION CHECKED");
if(this._salixVersion !== salixVersion) fetch();
}
async salixLogInfo() {
console.log("SALIX - LOGINFO REQUEST");
let salixCall = await fetch(`${this.conf.salix.url}/schemas/logInfo`, {
method: "GET",
});
let salixLogConfig = [JSON.parse(await salixCall.text())];
this._salixVersion = salixCall.headers.get("Salix-version");
this._logInfo = salixLogConfig
console.log("SALIX- LOGINFO REQUESTED");
}
get logInfo(){
return this._logInfo
}
get salixVersion(){
return this._salixVersion;
}
};