@tmlmobilidade/databases 20260709.1401.58 → 20260710.2210.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/go-clickhouse.js +5 -41
- package/dist/clients/go-mongo.js +4 -42
- package/dist/clients/go-redis.js +3 -41
- package/dist/clients/pcgi-file-manager.js +6 -42
- package/dist/clients/pcgi-raw.js +6 -42
- package/dist/clients/pcgi-ticketing.js +4 -42
- package/dist/clients/pcgi-validations.js +4 -42
- package/package.json +1 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { ClickHouseLogLevel, createClient } from '@clickhouse/client';
|
|
3
3
|
import { Logger } from '@tmlmobilidade/logger';
|
|
4
|
-
import {
|
|
5
|
-
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { goSshTunnel } from '@tmlmobilidade/ssh';
|
|
6
5
|
/* * */
|
|
7
6
|
export class GOClickHouseClient {
|
|
8
7
|
//
|
|
@@ -75,50 +74,15 @@ export class GOClickHouseClient {
|
|
|
75
74
|
//
|
|
76
75
|
//
|
|
77
76
|
// Validate required environment variables
|
|
78
|
-
if (process.env.GO_CLICKHOUSE_TUNNEL_ENABLED !== 'true' && process.env.GO_CLICKHOUSE_TUNNEL_ENABLED !== 'false') {
|
|
79
|
-
throw new Error('Missing GO_CLICKHOUSE_TUNNEL_ENABLED. Please indicate whether SSH tunneling is required by setting GO_CLICKHOUSE_TUNNEL_ENABLED to "true" or "false".');
|
|
80
|
-
}
|
|
81
77
|
if (!process.env.GO_CLICKHOUSE_HOST || !process.env.GO_CLICKHOUSE_PORT) {
|
|
82
78
|
throw new Error('Missing GO_CLICKHOUSE_HOST or GO_CLICKHOUSE_PORT');
|
|
83
79
|
}
|
|
84
|
-
|
|
80
|
+
//
|
|
81
|
+
// Setup SSH Tunnel
|
|
82
|
+
this.tunnel = goSshTunnel({ dstAddr: process.env.GO_CLICKHOUSE_HOST, dstPort: Number(process.env.GO_CLICKHOUSE_PORT) });
|
|
83
|
+
if (!this.tunnel) {
|
|
85
84
|
return `http://${process.env.GO_CLICKHOUSE_USER}:${process.env.GO_CLICKHOUSE_PASSWORD}@${process.env.GO_CLICKHOUSE_HOST}:${process.env.GO_CLICKHOUSE_PORT}`;
|
|
86
85
|
}
|
|
87
|
-
// SSH required
|
|
88
|
-
if (!process.env.GO_CLICKHOUSE_TUNNEL_LOCAL_PORT) {
|
|
89
|
-
throw new Error('Missing GO_CLICKHOUSE_TUNNEL_LOCAL_PORT');
|
|
90
|
-
}
|
|
91
|
-
if (!process.env.GO_CLICKHOUSE_TUNNEL_SSH_HOST || !process.env.GO_CLICKHOUSE_TUNNEL_SSH_USERNAME) {
|
|
92
|
-
throw new Error('Missing SSH config');
|
|
93
|
-
}
|
|
94
|
-
const sshConfig = {
|
|
95
|
-
forwardOptions: {
|
|
96
|
-
dstAddr: process.env.GO_CLICKHOUSE_HOST,
|
|
97
|
-
dstPort: Number(process.env.GO_CLICKHOUSE_PORT),
|
|
98
|
-
srcAddr: 'localhost',
|
|
99
|
-
srcPort: Number(process.env.GO_CLICKHOUSE_TUNNEL_LOCAL_PORT),
|
|
100
|
-
},
|
|
101
|
-
serverOptions: {
|
|
102
|
-
port: Number(process.env.GO_CLICKHOUSE_TUNNEL_LOCAL_PORT),
|
|
103
|
-
},
|
|
104
|
-
sshOptions: {
|
|
105
|
-
agent: (process.env.GO_CLICKHOUSE_TUNNEL_SSH_KEY_PATH || process.env.GO_CLICKHOUSE_TUNNEL_SSH_KEY) ? undefined : process.env.SSH_AUTH_SOCK,
|
|
106
|
-
host: process.env.GO_CLICKHOUSE_TUNNEL_SSH_HOST,
|
|
107
|
-
keepaliveCountMax: 3,
|
|
108
|
-
keepaliveInterval: 10_000,
|
|
109
|
-
port: 22,
|
|
110
|
-
privateKey: process.env.GO_CLICKHOUSE_TUNNEL_SSH_KEY_PATH ? readFileSync(process.env.GO_CLICKHOUSE_TUNNEL_SSH_KEY_PATH) : process.env.GO_CLICKHOUSE_TUNNEL_SSH_KEY ? process.env.GO_CLICKHOUSE_TUNNEL_SSH_KEY : undefined,
|
|
111
|
-
username: process.env.GO_CLICKHOUSE_TUNNEL_SSH_USERNAME,
|
|
112
|
-
},
|
|
113
|
-
tunnelOptions: {
|
|
114
|
-
autoClose: false,
|
|
115
|
-
reconnectOnError: true,
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
const sshOptions = {
|
|
119
|
-
maxRetries: 3,
|
|
120
|
-
};
|
|
121
|
-
this.tunnel = new SshTunnelService(sshConfig, sshOptions);
|
|
122
86
|
Logger.info({ message: '[GOClickHouseClient] Setting up SSH Tunnel...' });
|
|
123
87
|
const connection = await this.tunnel.connect();
|
|
124
88
|
const addr = connection.address();
|
package/dist/clients/go-mongo.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { Logger } from '@tmlmobilidade/logger';
|
|
3
|
-
import {
|
|
3
|
+
import { goSshTunnel } from '@tmlmobilidade/ssh';
|
|
4
4
|
import { MongoClient } from 'mongodb';
|
|
5
|
-
import { readFileSync } from 'node:fs';
|
|
6
5
|
/* * */
|
|
7
6
|
export class GOMongoClient {
|
|
8
7
|
//
|
|
@@ -45,7 +44,7 @@ export class GOMongoClient {
|
|
|
45
44
|
const connectionString = await this.getConnectionString();
|
|
46
45
|
this.client = new MongoClient(connectionString, {
|
|
47
46
|
connectTimeoutMS: 10_000,
|
|
48
|
-
directConnection:
|
|
47
|
+
directConnection: this.tunnel ? true : false,
|
|
49
48
|
maxPoolSize: 20,
|
|
50
49
|
minPoolSize: 2,
|
|
51
50
|
readPreference: 'primary',
|
|
@@ -92,9 +91,6 @@ export class GOMongoClient {
|
|
|
92
91
|
//
|
|
93
92
|
//
|
|
94
93
|
// Validate required environment variables
|
|
95
|
-
if (process.env.GO_MONGO_TUNNEL_ENABLED !== 'true' && process.env.GO_MONGO_TUNNEL_ENABLED !== 'false') {
|
|
96
|
-
throw new Error('Missing GO_MONGO_TUNNEL_ENABLED. Please indicate whether SSH tunneling is required by setting GO_MONGO_TUNNEL_ENABLED to "true" or "false".');
|
|
97
|
-
}
|
|
98
94
|
if (!process.env.GO_MONGO_HOST_1 || !process.env.GO_MONGO_PORT_1) {
|
|
99
95
|
throw new Error('Missing GO_MONGO_HOST_1 or GO_MONGO_PORT_1');
|
|
100
96
|
}
|
|
@@ -107,44 +103,10 @@ export class GOMongoClient {
|
|
|
107
103
|
if (!process.env.GO_MONGO_RS_NAME) {
|
|
108
104
|
throw new Error('Missing GO_MONGO_RS_NAME');
|
|
109
105
|
}
|
|
110
|
-
|
|
106
|
+
this.tunnel = goSshTunnel({ dstAddr: process.env.GO_MONGO_HOST_1, dstPort: Number(process.env.GO_MONGO_PORT_1) });
|
|
107
|
+
if (!this.tunnel) {
|
|
111
108
|
return `mongodb://${process.env.GO_MONGO_USER}:${process.env.GO_MONGO_PASSWORD}@${process.env.GO_MONGO_HOST_1}:${process.env.GO_MONGO_PORT_1},${process.env.GO_MONGO_HOST_2}:${process.env.GO_MONGO_PORT_2},${process.env.GO_MONGO_HOST_3}:${process.env.GO_MONGO_PORT_3}/`;
|
|
112
109
|
}
|
|
113
|
-
// SSH required
|
|
114
|
-
if (!process.env.GO_MONGO_TUNNEL_LOCAL_PORT) {
|
|
115
|
-
throw new Error('Missing GO_MONGO_TUNNEL_LOCAL_PORT');
|
|
116
|
-
}
|
|
117
|
-
if (!process.env.GO_MONGO_TUNNEL_SSH_HOST || !process.env.GO_MONGO_TUNNEL_SSH_USERNAME) {
|
|
118
|
-
throw new Error('Missing SSH config');
|
|
119
|
-
}
|
|
120
|
-
const sshConfig = {
|
|
121
|
-
forwardOptions: {
|
|
122
|
-
dstAddr: process.env.GO_MONGO_HOST_1,
|
|
123
|
-
dstPort: Number(process.env.GO_MONGO_PORT_1),
|
|
124
|
-
srcAddr: 'localhost',
|
|
125
|
-
srcPort: Number(process.env.GO_MONGO_TUNNEL_LOCAL_PORT),
|
|
126
|
-
},
|
|
127
|
-
serverOptions: {
|
|
128
|
-
port: Number(process.env.GO_MONGO_TUNNEL_LOCAL_PORT),
|
|
129
|
-
},
|
|
130
|
-
sshOptions: {
|
|
131
|
-
agent: (process.env.GO_MONGO_TUNNEL_SSH_KEY_PATH || process.env.GO_MONGO_TUNNEL_SSH_KEY) ? undefined : process.env.SSH_AUTH_SOCK,
|
|
132
|
-
host: process.env.GO_MONGO_TUNNEL_SSH_HOST,
|
|
133
|
-
keepaliveCountMax: 3,
|
|
134
|
-
keepaliveInterval: 10_000,
|
|
135
|
-
port: 22,
|
|
136
|
-
privateKey: process.env.GO_MONGO_TUNNEL_SSH_KEY_PATH ? readFileSync(process.env.GO_MONGO_TUNNEL_SSH_KEY_PATH) : process.env.GO_MONGO_TUNNEL_SSH_KEY ? process.env.GO_MONGO_TUNNEL_SSH_KEY : undefined,
|
|
137
|
-
username: process.env.GO_MONGO_TUNNEL_SSH_USERNAME,
|
|
138
|
-
},
|
|
139
|
-
tunnelOptions: {
|
|
140
|
-
autoClose: false,
|
|
141
|
-
reconnectOnError: true,
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
const sshOptions = {
|
|
145
|
-
maxRetries: 3,
|
|
146
|
-
};
|
|
147
|
-
this.tunnel = new SshTunnelService(sshConfig, sshOptions);
|
|
148
110
|
Logger.info({ message: '[GOMongoClient] Setting up SSH Tunnel...' });
|
|
149
111
|
const connection = await this.tunnel.connect();
|
|
150
112
|
const addr = connection.address();
|
package/dist/clients/go-redis.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { Logger } from '@tmlmobilidade/logger';
|
|
3
|
-
import {
|
|
4
|
-
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { goSshTunnel } from '@tmlmobilidade/ssh';
|
|
5
4
|
import { createClient } from 'redis';
|
|
6
5
|
/* * */
|
|
7
6
|
export class GORedisClient {
|
|
@@ -59,50 +58,13 @@ export class GORedisClient {
|
|
|
59
58
|
//
|
|
60
59
|
//
|
|
61
60
|
// Validate required environment variables
|
|
62
|
-
if (process.env.GO_REDIS_TUNNEL_ENABLED !== 'true' && process.env.GO_REDIS_TUNNEL_ENABLED !== 'false') {
|
|
63
|
-
throw new Error('Missing GO_REDIS_TUNNEL_ENABLED. Please indicate whether SSH tunneling is required by setting GO_REDIS_TUNNEL_ENABLED to "true" or "false".');
|
|
64
|
-
}
|
|
65
61
|
if (!process.env.GO_REDIS_HOST || !process.env.GO_REDIS_PORT) {
|
|
66
62
|
throw new Error('Missing GO_REDIS_HOST or GO_REDIS_PORT');
|
|
67
63
|
}
|
|
68
|
-
|
|
64
|
+
this.tunnel = goSshTunnel({ dstAddr: process.env.GO_REDIS_HOST, dstPort: Number(process.env.GO_REDIS_PORT) });
|
|
65
|
+
if (!this.tunnel) {
|
|
69
66
|
return `redis://${process.env.GO_REDIS_HOST}:${process.env.GO_REDIS_PORT}`;
|
|
70
67
|
}
|
|
71
|
-
// SSH required
|
|
72
|
-
if (!process.env.GO_REDIS_TUNNEL_LOCAL_PORT) {
|
|
73
|
-
throw new Error('Missing GO_REDIS_TUNNEL_LOCAL_PORT');
|
|
74
|
-
}
|
|
75
|
-
if (!process.env.GO_REDIS_TUNNEL_SSH_HOST || !process.env.GO_REDIS_TUNNEL_SSH_USERNAME) {
|
|
76
|
-
throw new Error('Missing SSH config');
|
|
77
|
-
}
|
|
78
|
-
const sshConfig = {
|
|
79
|
-
forwardOptions: {
|
|
80
|
-
dstAddr: process.env.GO_REDIS_HOST,
|
|
81
|
-
dstPort: Number(process.env.GO_REDIS_PORT),
|
|
82
|
-
srcAddr: 'localhost',
|
|
83
|
-
srcPort: Number(process.env.GO_REDIS_TUNNEL_LOCAL_PORT),
|
|
84
|
-
},
|
|
85
|
-
serverOptions: {
|
|
86
|
-
port: Number(process.env.GO_REDIS_TUNNEL_LOCAL_PORT),
|
|
87
|
-
},
|
|
88
|
-
sshOptions: {
|
|
89
|
-
agent: (process.env.GO_REDIS_TUNNEL_SSH_KEY_PATH || process.env.GO_REDIS_TUNNEL_SSH_KEY) ? undefined : process.env.SSH_AUTH_SOCK,
|
|
90
|
-
host: process.env.GO_REDIS_TUNNEL_SSH_HOST,
|
|
91
|
-
keepaliveCountMax: 3,
|
|
92
|
-
keepaliveInterval: 10_000,
|
|
93
|
-
port: 22,
|
|
94
|
-
privateKey: process.env.GO_REDIS_TUNNEL_SSH_KEY_PATH ? readFileSync(process.env.GO_REDIS_TUNNEL_SSH_KEY_PATH) : process.env.GO_REDIS_TUNNEL_SSH_KEY ? process.env.GO_REDIS_TUNNEL_SSH_KEY : undefined,
|
|
95
|
-
username: process.env.GO_REDIS_TUNNEL_SSH_USERNAME,
|
|
96
|
-
},
|
|
97
|
-
tunnelOptions: {
|
|
98
|
-
autoClose: false,
|
|
99
|
-
reconnectOnError: true,
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
const sshOptions = {
|
|
103
|
-
maxRetries: 3,
|
|
104
|
-
};
|
|
105
|
-
this.tunnel = new SshTunnelService(sshConfig, sshOptions);
|
|
106
68
|
Logger.info({ message: '[GORedisClient] Setting up SSH Tunnel...' });
|
|
107
69
|
const connection = await this.tunnel.connect();
|
|
108
70
|
const addr = connection.address();
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { Logger } from '@tmlmobilidade/logger';
|
|
3
|
-
import {
|
|
3
|
+
import { pcgiSshTunnel } from '@tmlmobilidade/ssh';
|
|
4
4
|
import { MongoClient } from 'mongodb';
|
|
5
|
-
import { readFileSync } from 'node:fs';
|
|
6
5
|
/* * */
|
|
7
6
|
export class PCGIFileManagerClient {
|
|
8
7
|
//
|
|
@@ -45,7 +44,7 @@ export class PCGIFileManagerClient {
|
|
|
45
44
|
const connectionString = await this.getConnectionString();
|
|
46
45
|
this.client = new MongoClient(connectionString, {
|
|
47
46
|
connectTimeoutMS: 10_000,
|
|
48
|
-
directConnection:
|
|
47
|
+
directConnection: this.tunnel ? true : false,
|
|
49
48
|
maxPoolSize: 20,
|
|
50
49
|
minPoolSize: 2,
|
|
51
50
|
readPreference: 'primary',
|
|
@@ -92,9 +91,6 @@ export class PCGIFileManagerClient {
|
|
|
92
91
|
//
|
|
93
92
|
//
|
|
94
93
|
// Validate required environment variables
|
|
95
|
-
if (process.env.PCGI_FILE_MANAGER_TUNNEL_ENABLED !== 'true' && process.env.PCGI_FILE_MANAGER_TUNNEL_ENABLED !== 'false') {
|
|
96
|
-
throw new Error('Missing PCGI_FILE_MANAGER_TUNNEL_ENABLED. Please indicate whether SSH tunneling is required by setting PCGI_FILE_MANAGER_TUNNEL_ENABLED to "true" or "false".');
|
|
97
|
-
}
|
|
98
94
|
if (!process.env.PCGI_FILE_MANAGER_HOST_1 || !process.env.PCGI_FILE_MANAGER_PORT_1) {
|
|
99
95
|
throw new Error('Missing PCGI_FILE_MANAGER_HOST_1 or PCGI_FILE_MANAGER_PORT_1');
|
|
100
96
|
}
|
|
@@ -107,44 +103,12 @@ export class PCGIFileManagerClient {
|
|
|
107
103
|
if (!process.env.PCGI_FILE_MANAGER_RS_NAME) {
|
|
108
104
|
throw new Error('Missing PCGI_FILE_MANAGER_RS_NAME');
|
|
109
105
|
}
|
|
110
|
-
|
|
106
|
+
//
|
|
107
|
+
// Setup SSH Tunnel
|
|
108
|
+
this.tunnel = pcgiSshTunnel({ dstAddr: process.env.PCGI_FILE_MANAGER_HOST_1, dstPort: Number(process.env.PCGI_FILE_MANAGER_PORT_1) });
|
|
109
|
+
if (!this.tunnel) {
|
|
111
110
|
return `mongodb://${process.env.PCGI_FILE_MANAGER_USER}:${process.env.PCGI_FILE_MANAGER_PASSWORD}@${process.env.PCGI_FILE_MANAGER_HOST_1}:${process.env.PCGI_FILE_MANAGER_PORT_1},${process.env.PCGI_FILE_MANAGER_HOST_2}:${process.env.PCGI_FILE_MANAGER_PORT_2},${process.env.PCGI_FILE_MANAGER_HOST_3}:${process.env.PCGI_FILE_MANAGER_PORT_3}/`;
|
|
112
111
|
}
|
|
113
|
-
// SSH required
|
|
114
|
-
if (!process.env.PCGI_FILE_MANAGER_TUNNEL_LOCAL_PORT) {
|
|
115
|
-
throw new Error('Missing PCGI_FILE_MANAGER_TUNNEL_LOCAL_PORT');
|
|
116
|
-
}
|
|
117
|
-
if (!process.env.PCGI_FILE_MANAGER_TUNNEL_SSH_HOST || !process.env.PCGI_FILE_MANAGER_TUNNEL_SSH_USERNAME) {
|
|
118
|
-
throw new Error('Missing SSH config');
|
|
119
|
-
}
|
|
120
|
-
const sshConfig = {
|
|
121
|
-
forwardOptions: {
|
|
122
|
-
dstAddr: process.env.PCGI_FILE_MANAGER_HOST_1,
|
|
123
|
-
dstPort: Number(process.env.PCGI_FILE_MANAGER_PORT_1),
|
|
124
|
-
srcAddr: 'localhost',
|
|
125
|
-
srcPort: Number(process.env.PCGI_FILE_MANAGER_TUNNEL_LOCAL_PORT),
|
|
126
|
-
},
|
|
127
|
-
serverOptions: {
|
|
128
|
-
port: Number(process.env.PCGI_FILE_MANAGER_TUNNEL_LOCAL_PORT),
|
|
129
|
-
},
|
|
130
|
-
sshOptions: {
|
|
131
|
-
agent: (process.env.PCGI_FILE_MANAGER_TUNNEL_SSH_KEY_PATH || process.env.PCGI_FILE_MANAGER_TUNNEL_SSH_KEY) ? undefined : process.env.SSH_AUTH_SOCK,
|
|
132
|
-
host: process.env.PCGI_FILE_MANAGER_TUNNEL_SSH_HOST,
|
|
133
|
-
keepaliveCountMax: 3,
|
|
134
|
-
keepaliveInterval: 10_000,
|
|
135
|
-
port: 22,
|
|
136
|
-
privateKey: process.env.PCGI_FILE_MANAGER_TUNNEL_SSH_KEY_PATH ? readFileSync(process.env.PCGI_FILE_MANAGER_TUNNEL_SSH_KEY_PATH) : process.env.PCGI_FILE_MANAGER_TUNNEL_SSH_KEY ? process.env.PCGI_FILE_MANAGER_TUNNEL_SSH_KEY : undefined,
|
|
137
|
-
username: process.env.PCGI_FILE_MANAGER_TUNNEL_SSH_USERNAME,
|
|
138
|
-
},
|
|
139
|
-
tunnelOptions: {
|
|
140
|
-
autoClose: false,
|
|
141
|
-
reconnectOnError: true,
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
const sshOptions = {
|
|
145
|
-
maxRetries: 3,
|
|
146
|
-
};
|
|
147
|
-
this.tunnel = new SshTunnelService(sshConfig, sshOptions);
|
|
148
112
|
Logger.info({ message: '[PCGIFileManagerClient] Setting up SSH Tunnel...' });
|
|
149
113
|
const connection = await this.tunnel.connect();
|
|
150
114
|
const addr = connection.address();
|
package/dist/clients/pcgi-raw.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { Logger } from '@tmlmobilidade/logger';
|
|
3
|
-
import {
|
|
3
|
+
import { pcgiSshTunnel } from '@tmlmobilidade/ssh';
|
|
4
4
|
import { MongoClient } from 'mongodb';
|
|
5
|
-
import { readFileSync } from 'node:fs';
|
|
6
5
|
/* * */
|
|
7
6
|
export class PCGIRawClient {
|
|
8
7
|
//
|
|
@@ -45,7 +44,7 @@ export class PCGIRawClient {
|
|
|
45
44
|
const connectionString = await this.getConnectionString();
|
|
46
45
|
this.client = new MongoClient(connectionString, {
|
|
47
46
|
connectTimeoutMS: 10_000,
|
|
48
|
-
directConnection:
|
|
47
|
+
directConnection: this.tunnel ? true : false,
|
|
49
48
|
maxPoolSize: 20,
|
|
50
49
|
minPoolSize: 2,
|
|
51
50
|
readPreference: 'primary',
|
|
@@ -92,9 +91,6 @@ export class PCGIRawClient {
|
|
|
92
91
|
//
|
|
93
92
|
//
|
|
94
93
|
// Validate required environment variables
|
|
95
|
-
if (process.env.PCGI_RAW_TUNNEL_ENABLED !== 'true' && process.env.PCGI_RAW_TUNNEL_ENABLED !== 'false') {
|
|
96
|
-
throw new Error('Missing PCGI_RAW_TUNNEL_ENABLED. Please indicate whether SSH tunneling is required by setting PCGI_RAW_TUNNEL_ENABLED to "true" or "false".');
|
|
97
|
-
}
|
|
98
94
|
if (!process.env.PCGI_RAW_HOST_1 || !process.env.PCGI_RAW_PORT_1) {
|
|
99
95
|
throw new Error('Missing PCGI_RAW_HOST_1 or PCGI_RAW_PORT_1');
|
|
100
96
|
}
|
|
@@ -107,44 +103,12 @@ export class PCGIRawClient {
|
|
|
107
103
|
if (!process.env.PCGI_RAW_RS_NAME) {
|
|
108
104
|
throw new Error('Missing PCGI_RAW_RS_NAME');
|
|
109
105
|
}
|
|
110
|
-
|
|
106
|
+
//
|
|
107
|
+
// Setup SSH Tunnel
|
|
108
|
+
this.tunnel = pcgiSshTunnel({ dstAddr: process.env.PCGI_RAW_HOST_1, dstPort: Number(process.env.PCGI_RAW_PORT_1) });
|
|
109
|
+
if (!this.tunnel) {
|
|
111
110
|
return `mongodb://${process.env.PCGI_RAW_USER}:${process.env.PCGI_RAW_PASSWORD}@${process.env.PCGI_RAW_HOST_1}:${process.env.PCGI_RAW_PORT_1},${process.env.PCGI_RAW_HOST_2}:${process.env.PCGI_RAW_PORT_2},${process.env.PCGI_RAW_HOST_3}:${process.env.PCGI_RAW_PORT_3}/`;
|
|
112
111
|
}
|
|
113
|
-
// SSH required
|
|
114
|
-
if (!process.env.PCGI_RAW_TUNNEL_LOCAL_PORT) {
|
|
115
|
-
throw new Error('Missing PCGI_RAW_TUNNEL_LOCAL_PORT');
|
|
116
|
-
}
|
|
117
|
-
if (!process.env.PCGI_RAW_TUNNEL_SSH_HOST || !process.env.PCGI_RAW_TUNNEL_SSH_USERNAME) {
|
|
118
|
-
throw new Error('Missing SSH config');
|
|
119
|
-
}
|
|
120
|
-
const sshConfig = {
|
|
121
|
-
forwardOptions: {
|
|
122
|
-
dstAddr: process.env.PCGI_RAW_HOST_1,
|
|
123
|
-
dstPort: Number(process.env.PCGI_RAW_PORT_1),
|
|
124
|
-
srcAddr: 'localhost',
|
|
125
|
-
srcPort: Number(process.env.PCGI_RAW_TUNNEL_LOCAL_PORT),
|
|
126
|
-
},
|
|
127
|
-
serverOptions: {
|
|
128
|
-
port: Number(process.env.PCGI_RAW_TUNNEL_LOCAL_PORT),
|
|
129
|
-
},
|
|
130
|
-
sshOptions: {
|
|
131
|
-
agent: (process.env.PCGI_RAW_TUNNEL_SSH_KEY_PATH || process.env.PCGI_RAW_TUNNEL_SSH_KEY) ? undefined : process.env.SSH_AUTH_SOCK,
|
|
132
|
-
host: process.env.PCGI_RAW_TUNNEL_SSH_HOST,
|
|
133
|
-
keepaliveCountMax: 3,
|
|
134
|
-
keepaliveInterval: 10_000,
|
|
135
|
-
port: 22,
|
|
136
|
-
privateKey: process.env.PCGI_RAW_TUNNEL_SSH_KEY_PATH ? readFileSync(process.env.PCGI_RAW_TUNNEL_SSH_KEY_PATH) : process.env.PCGI_RAW_TUNNEL_SSH_KEY ? process.env.PCGI_RAW_TUNNEL_SSH_KEY : undefined,
|
|
137
|
-
username: process.env.PCGI_RAW_TUNNEL_SSH_USERNAME,
|
|
138
|
-
},
|
|
139
|
-
tunnelOptions: {
|
|
140
|
-
autoClose: false,
|
|
141
|
-
reconnectOnError: true,
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
const sshOptions = {
|
|
145
|
-
maxRetries: 3,
|
|
146
|
-
};
|
|
147
|
-
this.tunnel = new SshTunnelService(sshConfig, sshOptions);
|
|
148
112
|
Logger.info({ message: '[PCGIRawClient] Setting up SSH Tunnel...' });
|
|
149
113
|
const connection = await this.tunnel.connect();
|
|
150
114
|
const addr = connection.address();
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { Logger } from '@tmlmobilidade/logger';
|
|
3
|
-
import {
|
|
3
|
+
import { pcgiSshTunnel } from '@tmlmobilidade/ssh';
|
|
4
4
|
import { MongoClient } from 'mongodb';
|
|
5
|
-
import { readFileSync } from 'node:fs';
|
|
6
5
|
/* * */
|
|
7
6
|
export class PCGITicketingClient {
|
|
8
7
|
//
|
|
@@ -45,7 +44,7 @@ export class PCGITicketingClient {
|
|
|
45
44
|
const connectionString = await this.getConnectionString();
|
|
46
45
|
this.client = new MongoClient(connectionString, {
|
|
47
46
|
connectTimeoutMS: 10_000,
|
|
48
|
-
directConnection:
|
|
47
|
+
directConnection: this.tunnel ? true : false,
|
|
49
48
|
maxPoolSize: 20,
|
|
50
49
|
minPoolSize: 2,
|
|
51
50
|
readPreference: 'primary',
|
|
@@ -92,9 +91,6 @@ export class PCGITicketingClient {
|
|
|
92
91
|
//
|
|
93
92
|
//
|
|
94
93
|
// Validate required environment variables
|
|
95
|
-
if (process.env.PCGI_TICKETING_TUNNEL_ENABLED !== 'true' && process.env.PCGI_TICKETING_TUNNEL_ENABLED !== 'false') {
|
|
96
|
-
throw new Error('Missing PCGI_TICKETING_TUNNEL_ENABLED. Please indicate whether SSH tunneling is required by setting PCGI_TICKETING_TUNNEL_ENABLED to "true" or "false".');
|
|
97
|
-
}
|
|
98
94
|
if (!process.env.PCGI_TICKETING_HOST_1 || !process.env.PCGI_TICKETING_PORT_1) {
|
|
99
95
|
throw new Error('Missing PCGI_TICKETING_HOST_1 or PCGI_TICKETING_PORT_1');
|
|
100
96
|
}
|
|
@@ -107,44 +103,10 @@ export class PCGITicketingClient {
|
|
|
107
103
|
if (!process.env.PCGI_TICKETING_RS_NAME) {
|
|
108
104
|
throw new Error('Missing PCGI_TICKETING_RS_NAME');
|
|
109
105
|
}
|
|
110
|
-
|
|
106
|
+
this.tunnel = pcgiSshTunnel({ dstAddr: process.env.PCGI_TICKETING_HOST_1, dstPort: Number(process.env.PCGI_TICKETING_PORT_1) });
|
|
107
|
+
if (!this.tunnel) {
|
|
111
108
|
return `mongodb://${process.env.PCGI_TICKETING_USER}:${process.env.PCGI_TICKETING_PASSWORD}@${process.env.PCGI_TICKETING_HOST_1}:${process.env.PCGI_TICKETING_PORT_1},${process.env.PCGI_TICKETING_HOST_2}:${process.env.PCGI_TICKETING_PORT_2},${process.env.PCGI_TICKETING_HOST_3}:${process.env.PCGI_TICKETING_PORT_3}/`;
|
|
112
109
|
}
|
|
113
|
-
// SSH required
|
|
114
|
-
if (!process.env.PCGI_TICKETING_TUNNEL_LOCAL_PORT) {
|
|
115
|
-
throw new Error('Missing PCGI_TICKETING_TUNNEL_LOCAL_PORT');
|
|
116
|
-
}
|
|
117
|
-
if (!process.env.PCGI_TICKETING_TUNNEL_SSH_HOST || !process.env.PCGI_TICKETING_TUNNEL_SSH_USERNAME) {
|
|
118
|
-
throw new Error('Missing SSH config');
|
|
119
|
-
}
|
|
120
|
-
const sshConfig = {
|
|
121
|
-
forwardOptions: {
|
|
122
|
-
dstAddr: process.env.PCGI_TICKETING_HOST_1,
|
|
123
|
-
dstPort: Number(process.env.PCGI_TICKETING_PORT_1),
|
|
124
|
-
srcAddr: 'localhost',
|
|
125
|
-
srcPort: Number(process.env.PCGI_TICKETING_TUNNEL_LOCAL_PORT),
|
|
126
|
-
},
|
|
127
|
-
serverOptions: {
|
|
128
|
-
port: Number(process.env.PCGI_TICKETING_TUNNEL_LOCAL_PORT),
|
|
129
|
-
},
|
|
130
|
-
sshOptions: {
|
|
131
|
-
agent: (process.env.PCGI_TICKETING_TUNNEL_SSH_KEY_PATH || process.env.PCGI_TICKETING_TUNNEL_SSH_KEY) ? undefined : process.env.SSH_AUTH_SOCK,
|
|
132
|
-
host: process.env.PCGI_TICKETING_TUNNEL_SSH_HOST,
|
|
133
|
-
keepaliveCountMax: 3,
|
|
134
|
-
keepaliveInterval: 10_000,
|
|
135
|
-
port: 22,
|
|
136
|
-
privateKey: process.env.PCGI_TICKETING_TUNNEL_SSH_KEY_PATH ? readFileSync(process.env.PCGI_TICKETING_TUNNEL_SSH_KEY_PATH) : process.env.PCGI_TICKETING_TUNNEL_SSH_KEY ? process.env.PCGI_TICKETING_TUNNEL_SSH_KEY : undefined,
|
|
137
|
-
username: process.env.PCGI_TICKETING_TUNNEL_SSH_USERNAME,
|
|
138
|
-
},
|
|
139
|
-
tunnelOptions: {
|
|
140
|
-
autoClose: false,
|
|
141
|
-
reconnectOnError: true,
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
const sshOptions = {
|
|
145
|
-
maxRetries: 3,
|
|
146
|
-
};
|
|
147
|
-
this.tunnel = new SshTunnelService(sshConfig, sshOptions);
|
|
148
110
|
Logger.info({ message: '[PCGITicketingClient] Setting up SSH Tunnel...' });
|
|
149
111
|
const connection = await this.tunnel.connect();
|
|
150
112
|
const addr = connection.address();
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { Logger } from '@tmlmobilidade/logger';
|
|
3
|
-
import {
|
|
3
|
+
import { pcgiSshTunnel } from '@tmlmobilidade/ssh';
|
|
4
4
|
import { MongoClient } from 'mongodb';
|
|
5
|
-
import { readFileSync } from 'node:fs';
|
|
6
5
|
/* * */
|
|
7
6
|
export class PCGIValidationsClient {
|
|
8
7
|
//
|
|
@@ -45,7 +44,7 @@ export class PCGIValidationsClient {
|
|
|
45
44
|
const connectionString = await this.getConnectionString();
|
|
46
45
|
this.client = new MongoClient(connectionString, {
|
|
47
46
|
connectTimeoutMS: 10_000,
|
|
48
|
-
directConnection:
|
|
47
|
+
directConnection: this.tunnel ? true : false,
|
|
49
48
|
maxPoolSize: 20,
|
|
50
49
|
minPoolSize: 2,
|
|
51
50
|
readPreference: 'primary',
|
|
@@ -92,9 +91,6 @@ export class PCGIValidationsClient {
|
|
|
92
91
|
//
|
|
93
92
|
//
|
|
94
93
|
// Validate required environment variables
|
|
95
|
-
if (process.env.PCGI_VALIDATIONS_TUNNEL_ENABLED !== 'true' && process.env.PCGI_VALIDATIONS_TUNNEL_ENABLED !== 'false') {
|
|
96
|
-
throw new Error('Missing PCGI_VALIDATIONS_TUNNEL_ENABLED. Please indicate whether SSH tunneling is required by setting PCGI_VALIDATIONS_TUNNEL_ENABLED to "true" or "false".');
|
|
97
|
-
}
|
|
98
94
|
if (!process.env.PCGI_VALIDATIONS_HOST_1 || !process.env.PCGI_VALIDATIONS_PORT_1) {
|
|
99
95
|
throw new Error('Missing PCGI_VALIDATIONS_HOST_1 or PCGI_VALIDATIONS_PORT_1');
|
|
100
96
|
}
|
|
@@ -107,44 +103,10 @@ export class PCGIValidationsClient {
|
|
|
107
103
|
if (!process.env.PCGI_VALIDATIONS_RS_NAME) {
|
|
108
104
|
throw new Error('Missing PCGI_VALIDATIONS_RS_NAME');
|
|
109
105
|
}
|
|
110
|
-
|
|
106
|
+
this.tunnel = pcgiSshTunnel({ dstAddr: process.env.PCGI_VALIDATIONS_HOST_1, dstPort: Number(process.env.PCGI_VALIDATIONS_PORT_1) });
|
|
107
|
+
if (!this.tunnel) {
|
|
111
108
|
return `mongodb://${process.env.PCGI_VALIDATIONS_USER}:${process.env.PCGI_VALIDATIONS_PASSWORD}@${process.env.PCGI_VALIDATIONS_HOST_1}:${process.env.PCGI_VALIDATIONS_PORT_1},${process.env.PCGI_VALIDATIONS_HOST_2}:${process.env.PCGI_VALIDATIONS_PORT_2},${process.env.PCGI_VALIDATIONS_HOST_3}:${process.env.PCGI_VALIDATIONS_PORT_3}/`;
|
|
112
109
|
}
|
|
113
|
-
// SSH required
|
|
114
|
-
if (!process.env.PCGI_VALIDATIONS_TUNNEL_LOCAL_PORT) {
|
|
115
|
-
throw new Error('Missing PCGI_VALIDATIONS_TUNNEL_LOCAL_PORT');
|
|
116
|
-
}
|
|
117
|
-
if (!process.env.PCGI_VALIDATIONS_TUNNEL_SSH_HOST || !process.env.PCGI_VALIDATIONS_TUNNEL_SSH_USERNAME) {
|
|
118
|
-
throw new Error('Missing SSH config');
|
|
119
|
-
}
|
|
120
|
-
const sshConfig = {
|
|
121
|
-
forwardOptions: {
|
|
122
|
-
dstAddr: process.env.PCGI_VALIDATIONS_HOST_1,
|
|
123
|
-
dstPort: Number(process.env.PCGI_VALIDATIONS_PORT_1),
|
|
124
|
-
srcAddr: 'localhost',
|
|
125
|
-
srcPort: Number(process.env.PCGI_VALIDATIONS_TUNNEL_LOCAL_PORT),
|
|
126
|
-
},
|
|
127
|
-
serverOptions: {
|
|
128
|
-
port: Number(process.env.PCGI_VALIDATIONS_TUNNEL_LOCAL_PORT),
|
|
129
|
-
},
|
|
130
|
-
sshOptions: {
|
|
131
|
-
agent: (process.env.PCGI_VALIDATIONS_TUNNEL_SSH_KEY_PATH || process.env.PCGI_VALIDATIONS_TUNNEL_SSH_KEY) ? undefined : process.env.SSH_AUTH_SOCK,
|
|
132
|
-
host: process.env.PCGI_VALIDATIONS_TUNNEL_SSH_HOST,
|
|
133
|
-
keepaliveCountMax: 3,
|
|
134
|
-
keepaliveInterval: 10_000,
|
|
135
|
-
port: 22,
|
|
136
|
-
privateKey: process.env.PCGI_VALIDATIONS_TUNNEL_SSH_KEY_PATH ? readFileSync(process.env.PCGI_VALIDATIONS_TUNNEL_SSH_KEY_PATH) : process.env.PCGI_VALIDATIONS_TUNNEL_SSH_KEY ? process.env.PCGI_VALIDATIONS_TUNNEL_SSH_KEY : undefined,
|
|
137
|
-
username: process.env.PCGI_VALIDATIONS_TUNNEL_SSH_USERNAME,
|
|
138
|
-
},
|
|
139
|
-
tunnelOptions: {
|
|
140
|
-
autoClose: false,
|
|
141
|
-
reconnectOnError: true,
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
const sshOptions = {
|
|
145
|
-
maxRetries: 3,
|
|
146
|
-
};
|
|
147
|
-
this.tunnel = new SshTunnelService(sshConfig, sshOptions);
|
|
148
110
|
Logger.info({ message: '[PCGIValidationsClient] Setting up SSH Tunnel...' });
|
|
149
111
|
const connection = await this.tunnel.connect();
|
|
150
112
|
const addr = connection.address();
|