|
|
@ -1,4 +1,5 @@ |
|
|
|
import { RequestHandler } from 'express'; |
|
|
|
import { RequestHandler } from 'express'; |
|
|
|
|
|
|
|
import { writeFileSync } from 'fs'; |
|
|
|
|
|
|
|
|
|
|
|
import SERVER_PATHS from '../../consts/SERVER_PATHS'; |
|
|
|
import SERVER_PATHS from '../../consts/SERVER_PATHS'; |
|
|
|
|
|
|
|
|
|
|
@ -10,7 +11,7 @@ import { |
|
|
|
sub, |
|
|
|
sub, |
|
|
|
} from '../../accessModule'; |
|
|
|
} from '../../accessModule'; |
|
|
|
import { sanitize } from '../../sanitize'; |
|
|
|
import { sanitize } from '../../sanitize'; |
|
|
|
import { rm, stderr, stdoutVar, systemCall } from '../../shell'; |
|
|
|
import { rm, stderr, stdoutVar, systemCall, uuid } from '../../shell'; |
|
|
|
|
|
|
|
|
|
|
|
export const createHostConnection: RequestHandler< |
|
|
|
export const createHostConnection: RequestHandler< |
|
|
|
unknown, |
|
|
|
unknown, |
|
|
@ -72,7 +73,7 @@ export const createHostConnection: RequestHandler< |
|
|
|
|
|
|
|
|
|
|
|
stdoutVar({ localIPAddress }); |
|
|
|
stdoutVar({ localIPAddress }); |
|
|
|
|
|
|
|
|
|
|
|
const pgpassFilePath = '/tmp/.pgpass'; |
|
|
|
const pgpassFilePath = `/tmp/.pgpass-${uuid()}`; |
|
|
|
const pgpassFileBody = `${peerIPAddress}:${commonDBPort}:${commonDBName}:${commonDBUser}:${commonPassword.replace( |
|
|
|
const pgpassFileBody = `${peerIPAddress}:${commonDBPort}:${commonDBName}:${commonDBUser}:${commonPassword.replace( |
|
|
|
/:/g, |
|
|
|
/:/g, |
|
|
|
'\\:', |
|
|
|
'\\:', |
|
|
@ -81,17 +82,9 @@ export const createHostConnection: RequestHandler< |
|
|
|
stdoutVar({ pgpassFilePath, pgpassFileBody }); |
|
|
|
stdoutVar({ pgpassFilePath, pgpassFileBody }); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
await sub('write_file', { |
|
|
|
writeFileSync(pgpassFilePath, pgpassFileBody, { |
|
|
|
params: [ |
|
|
|
encoding: 'utf-8', |
|
|
|
{ |
|
|
|
mode: 0o600, |
|
|
|
body: pgpassFileBody, |
|
|
|
|
|
|
|
file: pgpassFilePath, |
|
|
|
|
|
|
|
mode: '0600', |
|
|
|
|
|
|
|
overwrite: 1, |
|
|
|
|
|
|
|
secure: 1, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
pre: ['Storage'], |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} catch (subError) { |
|
|
|
} catch (subError) { |
|
|
|
stderr(`Failed to write ${pgpassFilePath}; CAUSE: ${subError}`); |
|
|
|
stderr(`Failed to write ${pgpassFilePath}; CAUSE: ${subError}`); |
|
|
|