1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-05 05:40:06 +00:00

fix: refactored + removed unused package

This commit is contained in:
Saad Jutt
2022-02-15 04:04:38 +05:00
parent de47d78a00
commit d7e1aca7e3
6 changed files with 109 additions and 8570 deletions

View File

@@ -0,0 +1,33 @@
import path from 'path'
import { fileExists, getString, readFile } from '@sasjs/utils'
export const getCertificates = async () => {
const { PRIVATE_KEY, FULL_CHAIN } = process.env
const keyPath = PRIVATE_KEY ?? (await getFileInput('Private Key (PEM)'))
const certPath = FULL_CHAIN ?? (await getFileInput('Full Chain (PEM)'))
const key = await readFile(keyPath)
const cert = await readFile(certPath)
return { key, cert }
}
const getFileInput = async (filename: string): Promise<string> => {
const validator = async (filePath: string) => {
if (!filePath) return `Path to ${filename} is required.`
if (!(await fileExists(path.join(process.cwd(), filePath)))) {
return 'No file found at provided path.'
}
return true
}
const targetName = await getString(
`Please enter path to ${filename} (relative path): `,
validator
)
return targetName
}