mirror of
https://github.com/logto-io/logto.git
synced 2025-02-24 22:05:56 -05:00
refactor(core): allow read private key from env (#629)
This commit is contained in:
parent
ef60a474f6
commit
61d1964506
1 changed files with 18 additions and 1 deletions
|
@ -6,7 +6,24 @@ import inquirer from 'inquirer';
|
|||
|
||||
import { noInquiry } from './parameters';
|
||||
|
||||
/**
|
||||
* Try to read private key with the following order:
|
||||
*
|
||||
* 1. From `process.env.OIDC_PRIVATE_KEY`.
|
||||
* 2. Fetch path from `process.env.OIDC_PRIVATE_KEY_PATH` then read from that path.
|
||||
*
|
||||
* If none of above succeed, then inquire user to generate a new key if no `--no-inquiry` presents in argv.
|
||||
*
|
||||
* @returns The private key for OIDC provider.
|
||||
* @throws An error when failed to read a private key.
|
||||
*/
|
||||
const readPrivateKey = async (): Promise<string> => {
|
||||
const privateKey = getEnv('OIDC_PRIVATE_KEY');
|
||||
|
||||
if (privateKey) {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
const privateKeyPath = getEnv('OIDC_PRIVATE_KEY_PATH', 'oidc-private-key.pem');
|
||||
|
||||
try {
|
||||
|
@ -19,7 +36,7 @@ const readPrivateKey = async (): Promise<string> => {
|
|||
const answer = await inquirer.prompt({
|
||||
type: 'confirm',
|
||||
name: 'confirm',
|
||||
message: `No private key found in \`${privateKeyPath}\`, would you like to generate a new one?`,
|
||||
message: `No private key found in env \`OIDC_PRIVATE_KEY\` nor \`${privateKeyPath}\`, would you like to generate a new one?`,
|
||||
});
|
||||
|
||||
if (!answer.confirm) {
|
||||
|
|
Loading…
Add table
Reference in a new issue