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

Loading…
Cancel
Save