-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
146 lines (126 loc) · 5.08 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Author: Jean-Marie Thewes
//Modules:
const fs = require("fs").promises;
//Global vars:
var config;
//Functions:
async function init(){//read the filename from environment and load it
if(process.env.configFileName === undefined){
throw new Error("Cannot find configFileName env Variable");
}else{
config = await JSON.parse(await fs.readFile(process.env.configFileName))
}
}//------------------------------------------------------------------------------------------
function getConfig(){//return the whole config
if(config == undefined){init()}
return config;
}//------------------------------------------------------------------------------------------
async function getLogConfig(){
if(config == undefined){await init()}
if("logConfig" in config){
if(Array.isArray(config.logConfig)){
return config.logConfig;
}else{
return [config.logConfig];
}
}else{
throw new Error("Error no log configuration in file")
}
}//------------------------------------------------------------------------------------------
async function getLogTimestampFormat(){
if(config == undefined){await init()}
if("logTimestampFormat" in config){
return config.logTimestampFormat;
}else{
return "YYYY-MM-DDTHH:mm:ss";
}
}//------------------------------------------------------------------------------------------
async function getMaxLogAgeInDays(){
if(config == undefined){await init()}
if("maxLogAgeInDays" in config){
return config.maxLogAgeInDays;
}else{
return 30;
}
}//------------------------------------------------------------------------------------------
async function getApiPath(){
if(config == undefined){await init()}
if("apiPath" in config){
return config.apiPath;
}else{throw new Error ("no API Path found in config")}
}//------------------------------------------------------------------------------------------
async function getApiKey(){
if(config == undefined){await init()}
if("apiKey" in config){
return config.apiKey;
}else{throw new Error ("no API Key found in config")}
}//------------------------------------------------------------------------------------------
async function getAlmaPrinters(){
if(config == undefined){await init()}
if("almaPrinterProfiles" in config){
return config.almaPrinterProfiles;
}else{throw new Error("No Printers defined in config")}
}//------------------------------------------------------------------------------------------
async function getProxy(){
if(config == undefined){await init()}
if("proxy" in config){
if(config.proxy == ""){
return undefined
}else{
return config.proxy;
}
}else{return undefined}
}//------------------------------------------------------------------------------------------
function getMailEnabled(){
if("mailEnabled" in config){
return config.mailEnabled
}else{return false}
}//------------------------------------------------------------------------------------------
function getMailServer(){
if("mailServer" in config){
return config.mailServer
}else{throw new Error("mailserver must be defined in config")}
}//------------------------------------------------------------------------------------------
function getMailPort(){
if("mailPort" in config){
return config.mailPort
}else{throw new Error("mailport must be defined in config")}
}//------------------------------------------------------------------------------------------
function getMailSender(){
if("mailSender" in config){
return config.mailSender
}else{throw new Error("mailsender must be defined in config")}
}//------------------------------------------------------------------------------------------
function getMailRecipient(){
if("mailRecipient" in config){
return config.mailRecipient
}else{throw new Error("mailrecipient must be defined in config")}
}//------------------------------------------------------------------------------------------
function getMailSubject(){
if("mailSubject" in config){
return config.mailSubject
}else{throw new Error("mailrecipient must be defined in config")}
}//------------------------------------------------------------------------------------------
function getMailText(){
if("mailText" in config){
return config.mailText
}else{throw new Error("mailrecipient must be defined in config")}
}//------------------------------------------------------------------------------------------
module.exports={
init:init,
getMailServer:getMailServer,
getMailPort:getMailPort,
getMailSender:getMailSender,
getMailRecipient:getMailRecipient,
getMailEnabled:getMailEnabled,
getMailSubject:getMailSubject,
getMailText:getMailText,
getConfig:getConfig,
getLogConfig:getLogConfig,
getLogTimestampFormat:getLogTimestampFormat,
getMaxLogAgeInDays:getMaxLogAgeInDays,
getApiPath:getApiPath,
getApiKey:getApiKey,
getAlmaPrinters:getAlmaPrinters,
getProxy:getProxy
}