-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathparseBalancer.ts
49 lines (41 loc) · 1.32 KB
/
parseBalancer.ts
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
export const removeViewerPathname = (value: string) => {
return value.replace(/\/viewer\/json/, '');
};
export const removeProtocol = (value: string) => {
return value.replace(/http[s]?:\/\//, '');
};
export const removePort = (value: string) => {
return value.replace(/:\d+$/, '');
};
interface ParsedBalancer {
balancer: string;
proxy: string | undefined;
}
/**
* Parse balancer with proxy. Initial format https://proxy/balancer/viewer/json
*
* Full current balancers list could be viewed in YDB Meta cluster\
* /Root/ydb/MasterClusterExt.db
*/
export const parseBalancer = (rawBalancer: string): ParsedBalancer => {
// Delete protocol and viewer/json path from raw value
const value = removeViewerPathname(removeProtocol(rawBalancer));
// After split the first element is considered a proxy, other - balancer value
const parts = value.split('/');
// If there is only one element, balancer is without proxy
if (parts.length === 1) {
return {
balancer: parts[0],
proxy: undefined,
};
}
const proxy = parts[0];
const balancer = value.replace(proxy + '/', '');
return {
balancer,
proxy,
};
};
export const getCleanBalancerValue = (rawBalancer: string) => {
return removePort(parseBalancer(rawBalancer).balancer);
};