fix(striker-ui-api): write .pgpass with nodejs 'fs' module

main
Tsu-ba-me 1 year ago
parent 1987fc7c2c
commit a5fc7d499e
  1. 19
      striker-ui-api/src/lib/request_handlers/host/createHostConnection.ts

@ -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}`);

Loading…
Cancel
Save