-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathconnection.ts
38 lines (29 loc) · 1.36 KB
/
connection.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
/*--------------------------------------------------------------------------
* Copyright (c) 2019-2021, Postgres.ai, Nikolay Samokhvalov nik@postgres.ai
* All Rights Reserved. Proprietary and confidential.
* Unauthorized copying of this file, via any medium is strictly prohibited
*--------------------------------------------------------------------------
*/
import { Instance } from '@postgres.ai/shared/types/api/entities/instance'
import { Clone } from '@postgres.ai/shared/types/api/entities/clone'
const isEmptyDbData = (clone: Clone) => {
const { host, port, username } = clone.db
// 'host', 'port' or 'username' can be empty string.
return !host || !port || !username
}
export const getSshPortForwardingCommand = (
instance: Instance,
clone: Clone,
) => {
if (!instance.sshServerUrl) return null
if (isEmptyDbData(clone)) return null
return `ssh -NTML ${clone.db.port}:localhost:${clone.db.port} ${instance.sshServerUrl} -i ~/.ssh/id_rsa`
}
export const getPsqlConnectionStr = (clone: Clone) => {
if (isEmptyDbData(clone)) return null
return `"host=${clone.db.host} port=${clone.db.port} user=${clone.db.username} dbname=DBNAME"`
}
export const getJdbcConnectionStr = (clone: Clone) => {
if (isEmptyDbData(clone)) return null
return `jdbc:postgresql://${clone.db.host}:${clone.db.port}/DBNAME?user=${clone.db.username}&password=DBPASSWORD`
}