@tmlmobilidade/interfaces 20260709.1326.35 → 20260710.2205.51

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.
@@ -1,7 +1,7 @@
1
1
  /* * */
2
2
  import { Logger } from '@tmlmobilidade/logger';
3
3
  import { MongoConnector } from '@tmlmobilidade/mongo';
4
- import { SshTunnelService } from '@tmlmobilidade/ssh';
4
+ import { pcgiSshTunnel } from '@tmlmobilidade/ssh';
5
5
  /* * */
6
6
  let GLOBAL_PCGIDB_TUNNEL_INSTANCE;
7
7
  /* * */
@@ -57,57 +57,10 @@ class PCGIDBLegacyClass {
57
57
  throw new Error('Missing PCGIDB_LEGACY_ADDRESS_1, PCGIDB_LEGACY_ADDRESS_2, PCGIDB_LEGACY_ADDRESS_3 or PCGIDB_LEGACY_PORT environment variable.');
58
58
  }
59
59
  //
60
- // Check if the SSH Tunnel is required based on the environment.
61
- // In 'production' and 'staging', we assume direct connection is used.
62
- if (process.env.ENVIRONMENT === 'production' || process.env.ENVIRONMENT === 'staging') {
63
- return `mongodb://${process.env.PCGIDB_LEGACY_USER}:${process.env.PCGIDB_LEGACY_PASSWORD}@${process.env.PCGIDB_LEGACY_ADDRESS_1}:${process.env.PCGIDB_LEGACY_PORT},${process.env.PCGIDB_LEGACY_ADDRESS_2}:${process.env.PCGIDB_LEGACY_PORT},${process.env.PCGIDB_LEGACY_ADDRESS_3}:${process.env.PCGIDB_LEGACY_PORT}/`;
64
- }
65
- //
66
- // If we're here, then the SSH Tunnel is to be used.
67
- // Check if the required SSH Tunnel environment variables are set.
68
- if (!process.env.PCGIDB_TUNNEL_LOCAL_PORT) {
69
- throw new Error('Missing PCGIDB_TUNNEL_LOCAL_PORT environment variable.');
70
- }
71
- if (!process.env.PCGIDB_TUNNEL_SSH_HOST || !process.env.PCGIDB_TUNNEL_SSH_USERNAME) {
72
- throw new Error('Missing PCGIDB_TUNNEL_SSH_HOST or PCGIDB_TUNNEL_SSH_USERNAME environment variable.');
73
- }
74
- //
75
60
  // Setup the SSH Tunnel connection configuration
76
- const sshConfig = {
77
- forwardOptions: {
78
- dstAddr: process.env.PCGIDB_LEGACY_ADDRESS_1,
79
- dstPort: Number(process.env.PCGIDB_LEGACY_PORT),
80
- srcAddr: 'localhost',
81
- srcPort: Number(process.env.PCGIDB_TUNNEL_LOCAL_PORT),
82
- },
83
- serverOptions: {
84
- port: Number(process.env.PCGIDB_TUNNEL_LOCAL_PORT),
85
- },
86
- sshOptions: {
87
- /**
88
- * Using SSH Agent for authentication.
89
- * Ensure that your SSH key is added to the SSH agent beforehand.
90
- * @see https://developer.1password.com/docs/ssh/agent/compatibility/#ssh-auth-sock
91
- */
92
- agent: process.env.SSH_AUTH_SOCK,
93
- host: process.env.PCGIDB_TUNNEL_SSH_HOST,
94
- keepaliveCountMax: 3, // Retry 3 times before closing the connection
95
- keepaliveInterval: 10_000, // Send keep-alive every 10 seconds
96
- port: 22,
97
- username: process.env.PCGIDB_TUNNEL_SSH_USERNAME,
98
- },
99
- tunnelOptions: {
100
- autoClose: false,
101
- reconnectOnError: true,
102
- },
103
- };
104
- const sshOptions = {
105
- maxRetries: 3,
106
- };
107
- //
108
- // Actually create the SSH Tunnel connection
61
+ GLOBAL_PCGIDB_TUNNEL_INSTANCE = pcgiSshTunnel({ dstAddr: process.env.PCGIDB_LEGACY_ADDRESS_1, dstPort: Number(process.env.PCGIDB_LEGACY_PORT) });
109
62
  if (!GLOBAL_PCGIDB_TUNNEL_INSTANCE) {
110
- GLOBAL_PCGIDB_TUNNEL_INSTANCE = new SshTunnelService(sshConfig, sshOptions);
63
+ return `mongodb://${process.env.PCGIDB_LEGACY_USER}:${process.env.PCGIDB_LEGACY_PASSWORD}@${process.env.PCGIDB_LEGACY_ADDRESS_1}:${process.env.PCGIDB_LEGACY_PORT},${process.env.PCGIDB_LEGACY_ADDRESS_2}:${process.env.PCGIDB_LEGACY_PORT},${process.env.PCGIDB_LEGACY_ADDRESS_3}:${process.env.PCGIDB_LEGACY_PORT}/`;
111
64
  }
112
65
  Logger.info({ message: 'Setting up SSH Tunnel for PCGIDB Legacy...' });
113
66
  const sshTunnelConnection = await GLOBAL_PCGIDB_TUNNEL_INSTANCE.connect();
@@ -1,7 +1,7 @@
1
1
  /* * */
2
2
  import { Logger } from '@tmlmobilidade/logger';
3
3
  import { MongoConnector } from '@tmlmobilidade/mongo';
4
- import { SshTunnelService } from '@tmlmobilidade/ssh';
4
+ import { pcgiSshTunnel } from '@tmlmobilidade/ssh';
5
5
  /* * */
6
6
  let GLOBAL_PCGIDB_TUNNEL_INSTANCE;
7
7
  /* * */
@@ -56,57 +56,10 @@ class PCGIDBTicketingClass {
56
56
  throw new Error('Missing PCGIDB_TICKETING_ADDRESS_1, PCGIDB_TICKETING_ADDRESS_2, PCGIDB_TICKETING_ADDRESS_3 or PCGIDB_TICKETING_PORT environment variable.');
57
57
  }
58
58
  //
59
- // Check if the SSH Tunnel is required based on the environment.
60
- // In 'production' and 'staging', we assume direct connection is used.
61
- if (process.env.ENVIRONMENT === 'production' || process.env.ENVIRONMENT === 'staging') {
62
- return `mongodb://${process.env.PCGIDB_TICKETING_USER}:${process.env.PCGIDB_TICKETING_PASSWORD}@${process.env.PCGIDB_TICKETING_ADDRESS_1}:${process.env.PCGIDB_TICKETING_PORT},${process.env.PCGIDB_TICKETING_ADDRESS_2}:${process.env.PCGIDB_TICKETING_PORT},${process.env.PCGIDB_TICKETING_ADDRESS_3}:${process.env.PCGIDB_TICKETING_PORT}/`;
63
- }
64
- //
65
- // If we're here, then the SSH Tunnel is to be used.
66
- // Check if the required SSH Tunnel environment variables are set.
67
- if (!process.env.PCGIDB_TUNNEL_LOCAL_PORT) {
68
- throw new Error('Missing PCGIDB_TUNNEL_LOCAL_PORT environment variable.');
69
- }
70
- if (!process.env.PCGIDB_TUNNEL_SSH_HOST || !process.env.PCGIDB_TUNNEL_SSH_USERNAME) {
71
- throw new Error('Missing PCGIDB_TUNNEL_SSH_HOST or PCGIDB_TUNNEL_SSH_USERNAME environment variable.');
72
- }
73
- //
74
- // Setup the SSH Tunnel connection configuration
75
- const sshConfig = {
76
- forwardOptions: {
77
- dstAddr: process.env.PCGIDB_TICKETING_ADDRESS_1,
78
- dstPort: Number(process.env.PCGIDB_TICKETING_PORT),
79
- srcAddr: 'localhost',
80
- srcPort: Number(process.env.PCGIDB_TUNNEL_LOCAL_PORT),
81
- },
82
- serverOptions: {
83
- port: Number(process.env.PCGIDB_TUNNEL_LOCAL_PORT),
84
- },
85
- sshOptions: {
86
- /**
87
- * Using SSH Agent for authentication.
88
- * Ensure that your SSH key is added to the SSH agent beforehand.
89
- * @see https://developer.1password.com/docs/ssh/agent/compatibility/#ssh-auth-sock
90
- */
91
- agent: process.env.SSH_AUTH_SOCK,
92
- host: process.env.PCGIDB_TUNNEL_SSH_HOST,
93
- keepaliveCountMax: 3, // Retry 3 times before closing the connection
94
- keepaliveInterval: 10_000, // Send keep-alive every 10 seconds
95
- port: 22,
96
- username: process.env.PCGIDB_TUNNEL_SSH_USERNAME,
97
- },
98
- tunnelOptions: {
99
- autoClose: false,
100
- reconnectOnError: true,
101
- },
102
- };
103
- const sshOptions = {
104
- maxRetries: 3,
105
- };
106
- //
107
- // Actually create the SSH Tunnel connection
59
+ // Setup the SSH Tunnel
60
+ GLOBAL_PCGIDB_TUNNEL_INSTANCE = pcgiSshTunnel({ dstAddr: process.env.PCGIDB_TICKETING_ADDRESS_1, dstPort: Number(process.env.PCGIDB_TICKETING_PORT) });
108
61
  if (!GLOBAL_PCGIDB_TUNNEL_INSTANCE) {
109
- GLOBAL_PCGIDB_TUNNEL_INSTANCE = new SshTunnelService(sshConfig, sshOptions);
62
+ return `mongodb://${process.env.PCGIDB_TICKETING_USER}:${process.env.PCGIDB_TICKETING_PASSWORD}@${process.env.PCGIDB_TICKETING_ADDRESS_1}:${process.env.PCGIDB_TICKETING_PORT},${process.env.PCGIDB_TICKETING_ADDRESS_2}:${process.env.PCGIDB_TICKETING_PORT},${process.env.PCGIDB_TICKETING_ADDRESS_3}:${process.env.PCGIDB_TICKETING_PORT}/`;
110
63
  }
111
64
  Logger.info({ message: 'Setting up SSH Tunnel for PCGIDB Ticketing...' });
112
65
  const sshTunnelConnection = await GLOBAL_PCGIDB_TUNNEL_INSTANCE.connect();
@@ -1,7 +1,7 @@
1
1
  /* * */
2
2
  import { Logger } from '@tmlmobilidade/logger';
3
3
  import { MongoConnector } from '@tmlmobilidade/mongo';
4
- import { SshTunnelService } from '@tmlmobilidade/ssh';
4
+ import { pcgiSshTunnel } from '@tmlmobilidade/ssh';
5
5
  /* * */
6
6
  let GLOBAL_PCGIDB_TUNNEL_INSTANCE;
7
7
  /* * */
@@ -58,58 +58,12 @@ class PCGIDBValidationsClass {
58
58
  throw new Error('Missing PCGIDB_VALIDATIONS_ADDRESS_1, PCGIDB_VALIDATIONS_ADDRESS_2, PCGIDB_VALIDATIONS_ADDRESS_3 or PCGIDB_VALIDATIONS_PORT environment variable.');
59
59
  }
60
60
  //
61
- // Check if the SSH Tunnel is required based on the environment.
62
- // In 'production' and 'staging', we assume direct connection is used.
63
- if (process.env.ENVIRONMENT === 'production' || process.env.ENVIRONMENT === 'staging') {
61
+ // Setup the SSH Tunnel
62
+ GLOBAL_PCGIDB_TUNNEL_INSTANCE = pcgiSshTunnel({ dstAddr: process.env.PCGIDB_VALIDATIONS_ADDRESS_1, dstPort: Number(process.env.PCGIDB_VALIDATIONS_PORT) });
63
+ if (!GLOBAL_PCGIDB_TUNNEL_INSTANCE) {
64
64
  return `mongodb://${process.env.PCGIDB_VALIDATIONS_USER}:${process.env.PCGIDB_VALIDATIONS_PASSWORD}@${process.env.PCGIDB_VALIDATIONS_ADDRESS_1}:${process.env.PCGIDB_VALIDATIONS_PORT},${process.env.PCGIDB_VALIDATIONS_ADDRESS_2}:${process.env.PCGIDB_VALIDATIONS_PORT},${process.env.PCGIDB_VALIDATIONS_ADDRESS_3}:${process.env.PCGIDB_VALIDATIONS_PORT}/`;
65
65
  }
66
66
  //
67
- // If we're here, then the SSH Tunnel is to be used.
68
- // Check if the required SSH Tunnel environment variables are set.
69
- if (!process.env.PCGIDB_TUNNEL_LOCAL_PORT) {
70
- throw new Error('Missing PCGIDB_TUNNEL_LOCAL_PORT environment variable.');
71
- }
72
- if (!process.env.PCGIDB_TUNNEL_SSH_HOST || !process.env.PCGIDB_TUNNEL_SSH_USERNAME) {
73
- throw new Error('Missing PCGIDB_TUNNEL_SSH_HOST or PCGIDB_TUNNEL_SSH_USERNAME environment variable.');
74
- }
75
- //
76
- // Setup the SSH Tunnel connection configuration
77
- const sshConfig = {
78
- forwardOptions: {
79
- dstAddr: process.env.PCGIDB_VALIDATIONS_ADDRESS_1,
80
- dstPort: Number(process.env.PCGIDB_VALIDATIONS_PORT),
81
- srcAddr: 'localhost',
82
- srcPort: Number(process.env.PCGIDB_TUNNEL_LOCAL_PORT),
83
- },
84
- serverOptions: {
85
- port: Number(process.env.PCGIDB_TUNNEL_LOCAL_PORT),
86
- },
87
- sshOptions: {
88
- /**
89
- * Using SSH Agent for authentication.
90
- * Ensure that your SSH key is added to the SSH agent beforehand.
91
- * @see https://developer.1password.com/docs/ssh/agent/compatibility/#ssh-auth-sock
92
- */
93
- agent: process.env.SSH_AUTH_SOCK,
94
- host: process.env.PCGIDB_TUNNEL_SSH_HOST,
95
- keepaliveCountMax: 3, // Retry 3 times before closing the connection
96
- keepaliveInterval: 10_000, // Send keep-alive every 10 seconds
97
- port: 22,
98
- username: process.env.PCGIDB_TUNNEL_SSH_USERNAME,
99
- },
100
- tunnelOptions: {
101
- autoClose: false,
102
- reconnectOnError: true,
103
- },
104
- };
105
- const sshOptions = {
106
- maxRetries: 3,
107
- };
108
- //
109
- // Actually create the SSH Tunnel connection
110
- if (!GLOBAL_PCGIDB_TUNNEL_INSTANCE) {
111
- GLOBAL_PCGIDB_TUNNEL_INSTANCE = new SshTunnelService(sshConfig, sshOptions);
112
- }
113
67
  Logger.info({ message: 'Setting up SSH Tunnel for PCGIDB Validations...' });
114
68
  const sshTunnelConnection = await GLOBAL_PCGIDB_TUNNEL_INSTANCE.connect();
115
69
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/interfaces",
3
- "version": "20260709.1326.35",
3
+ "version": "20260710.2205.51",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"