-
Notifications
You must be signed in to change notification settings - Fork 92
/
config.ts
150 lines (138 loc) · 4.34 KB
/
config.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
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
146
147
148
149
150
import { ClientConfiguration } from "../connection/connection_params.ts";
import config_file1 from "./config.json" assert { type: "json" };
type TcpConfiguration = Omit<ClientConfiguration, "connection"> & {
host_type: "tcp";
};
type SocketConfiguration = Omit<ClientConfiguration, "connection" | "tls"> & {
host_type: "socket";
};
let DEV_MODE: string | undefined;
try {
DEV_MODE = Deno.env.get("DENO_POSTGRES_DEVELOPMENT");
} catch (e) {
if (e instanceof Deno.errors.PermissionDenied) {
throw new Error(
"You need to provide ENV access in order to run the test suite",
);
}
throw e;
}
const config = DEV_MODE === "true" ? config_file1.local : config_file1.ci;
const enabled_tls = {
caCertificates: [
Deno.readTextFileSync(
new URL("../docker/certs/ca.crt", import.meta.url),
),
],
enabled: true,
enforce: true,
};
const disabled_tls = {
caCertificates: [],
enabled: false,
enforce: false,
};
export const getClearConfiguration = (
tls: boolean,
): TcpConfiguration => {
return {
applicationName: config.postgres_clear.applicationName,
database: config.postgres_clear.database,
host_type: "tcp",
hostname: config.postgres_clear.hostname,
options: {},
password: config.postgres_clear.password,
port: config.postgres_clear.port,
tls: tls ? enabled_tls : disabled_tls,
user: config.postgres_clear.users.clear,
};
};
export const getClearSocketConfiguration = (): SocketConfiguration => {
return {
applicationName: config.postgres_clear.applicationName,
database: config.postgres_clear.database,
host_type: "socket",
hostname: config.postgres_clear.socket,
options: {},
password: config.postgres_clear.password,
port: config.postgres_clear.port,
user: config.postgres_clear.users.socket,
};
};
/** MD5 authenticated user with privileged access to the database */
export const getMainConfiguration = (): TcpConfiguration => {
return {
applicationName: config.postgres_md5.applicationName,
database: config.postgres_md5.database,
hostname: config.postgres_md5.hostname,
host_type: "tcp",
options: {},
password: config.postgres_md5.password,
port: config.postgres_md5.port,
tls: enabled_tls,
user: config.postgres_md5.users.main,
};
};
export const getMd5Configuration = (tls: boolean): TcpConfiguration => {
return {
applicationName: config.postgres_md5.applicationName,
database: config.postgres_md5.database,
hostname: config.postgres_md5.hostname,
host_type: "tcp",
options: {},
password: config.postgres_md5.password,
port: config.postgres_md5.port,
tls: tls ? enabled_tls : disabled_tls,
user: config.postgres_md5.users.md5,
};
};
export const getMd5SocketConfiguration = (): SocketConfiguration => {
return {
applicationName: config.postgres_md5.applicationName,
database: config.postgres_md5.database,
hostname: config.postgres_md5.socket,
host_type: "socket",
options: {},
password: config.postgres_md5.password,
port: config.postgres_md5.port,
user: config.postgres_md5.users.socket,
};
};
export const getScramConfiguration = (tls: boolean): TcpConfiguration => {
return {
applicationName: config.postgres_scram.applicationName,
database: config.postgres_scram.database,
hostname: config.postgres_scram.hostname,
host_type: "tcp",
options: {},
password: config.postgres_scram.password,
port: config.postgres_scram.port,
tls: tls ? enabled_tls : disabled_tls,
user: config.postgres_scram.users.scram,
};
};
export const getScramSocketConfiguration = (): SocketConfiguration => {
return {
applicationName: config.postgres_scram.applicationName,
database: config.postgres_scram.database,
hostname: config.postgres_scram.socket,
host_type: "socket",
options: {},
password: config.postgres_scram.password,
port: config.postgres_scram.port,
user: config.postgres_scram.users.socket,
};
};
export const getTlsOnlyConfiguration = (): TcpConfiguration => {
return {
applicationName: config.postgres_md5.applicationName,
database: config.postgres_md5.database,
hostname: config.postgres_md5.hostname,
host_type: "tcp",
options: {},
password: config.postgres_md5.password,
port: config.postgres_md5.port,
tls: enabled_tls,
user: config.postgres_md5.users.tls_only,
};
};