forked from openiap/opencore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.ts
More file actions
115 lines (107 loc) · 5.75 KB
/
Copy pathConfig.ts
File metadata and controls
115 lines (107 loc) · 5.75 KB
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
import { fetch, toPassportConfig } from "passport-saml-metadata";
import * as fs from "fs";
import * as retry from "async-retry";
import { json } from "body-parser";
import { DatabaseConnection } from "./DatabaseConnection";
import { Provider } from "./LoginProvider";
import { TokenUser } from "./TokenUser";
import { Logger } from "./Logger";
import { Util } from "./Util";
export class Config {
public static db: DatabaseConnection = null;
public static auto_create_users: boolean = Config.parseBoolean(Config.getEnv("auto_create_users", "false"));
public static auto_create_domains: string[] = Config.parseArray(Config.getEnv("auto_create_domains", ""));
public static allow_user_registration: boolean = Config.parseBoolean(Config.getEnv("allow_user_registration", "false"));
public static allow_personal_nodered: boolean = Config.parseBoolean(Config.getEnv("allow_personal_nodered", "false"));
public static force_queue_prefix: boolean = Config.parseBoolean(Config.getEnv("force_queue_prefix", "true"));
public static nodered_image: string = Config.getEnv("nodered_image", "cloudhack/openflownodered:edge");
public static saml_federation_metadata: string = Config.getEnv("saml_federation_metadata", "");
public static api_ws_url: string = Config.getEnv("api_ws_url", "ws://localhost:3000");
public static api_bypass_perm_check: boolean = Config.parseBoolean(Config.getEnv("api_bypass_perm_check", "false"));
public static websocket_package_size: number = parseInt(Config.getEnv("websocket_package_size", "1024"), 10);
public static websocket_max_package_count: number = parseInt(Config.getEnv("websocket_max_package_count", "1024"), 10);
public static signing_crt: string = Config.getEnv("signing_crt", "");
public static singing_key: string = Config.getEnv("singing_key", "");
public static tls_crt: string = Config.getEnv("tls_crt", "");
public static tls_key: string = Config.getEnv("tls_key", "");
public static tls_ca: string = Config.getEnv("tls_ca", "");
public static tls_passphrase: string = Config.getEnv("tls_passphrase", "");
public static port: number = parseInt(Config.getEnv("port", "3000"));
public static domain: string = Config.getEnv("domain", "localhost");
public static namespace: string = Config.getEnv("namespace", "");
public static nodered_domain_schema: string = Config.getEnv("nodered_domain_schema", "");
public static protocol: string = Config.getEnv("protocol", "http");
public static saml_issuer: string = Config.getEnv("saml_issuer", "the-issuer");
// public static login_providers:Provider[] = [];
public static amqp_url: string = Config.getEnv("amqp_url", "amqp://localhost");
public static mongodb_url: string = Config.getEnv("mongodb_url", "mongodb://localhost:27017");
public static mongodb_db: string = Config.getEnv("mongodb_db", "openflow");
public static aes_secret: string = Config.getEnv("aes_secret", "");
public static skip_history_collections: string = Config.getEnv("skip_history_collections", "");
public static baseurl(): string {
var result: string = "";
if (Config.tls_crt != '' && Config.tls_key != '') {
result = "https://" + Config.domain;
} else {
result = Config.protocol + "://" + Config.domain;
}
if (Config.port != 80 && Config.port != 443) {
result = result + ":" + Config.port + "/";
} else { result = result + "/"; }
return result;
}
// public static async get_login_providers():Promise<void> {
// this.login_providers = await Config.db.query<Provider>({_type: "provider"}, null, 1, 0, null, "config", TokenUser.rootToken());
// // if(this.login_providers.length > 0) { return; }
// if(fs.existsSync("config/login_providers.json")) {
// // this.login_providers = JSON.parse(fs.readFileSync("config/login_providers.json", "utf8"));
// }
// }
public static getEnv(name: string, defaultvalue: string): string {
var value: any = process.env[name];
if (!value || value === "") { value = defaultvalue; }
return value;
}
public static async parse_federation_metadata(url: string): Promise<any> {
// if anything throws, we retry
var metadata: any = await retry(async bail => {
var reader: any = await fetch({ url });
if (Util.IsNullUndefinded(reader)) { bail(new Error("Failed getting result")); return; }
var config: any = toPassportConfig(reader);
// we need this, for Office 365 :-/
if (reader.signingCerts && reader.signingCerts.length > 1) {
config.cert = reader.signingCerts;
}
return config;
}, {
retries: 50,
onRetry: function (error: Error, count: number): void {
Logger.instanse.warn("retry " + count + " error " + error.message + " getting " + url);
}
});
return metadata;
}
public static parseArray(s: string): string[] {
var arr = s.split(",");
arr = arr.map(p => p.trim());
arr = arr.filter(result => (result.trim() !== ""));
return arr;
}
public static parseBoolean(s: any): boolean {
var val: string = "false";
if (typeof s === "number") {
val = s.toString();
} else if (typeof s === "string") {
val = s.toLowerCase().trim();
} else if (typeof s === "boolean") {
val = s.toString();
} else {
throw new Error("Unknown type!");
}
switch (val) {
case "true": case "yes": case "1": return true;
case "false": case "no": case "0": case null: return false;
default: return Boolean(s);
}
}
}