From 3fbdb2e46c4f38268df42a03835b43151f9e55b2 Mon Sep 17 00:00:00 2001 From: Icebob Date: Wed, 6 Mar 2019 09:08:43 +0100 Subject: [PATCH] Implement #4 - fix password via CLI (#5) --- doc/self-hosted/index.md | 1 + packages/server/src/cli.ts | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/doc/self-hosted/index.md b/doc/self-hosted/index.md index 2a37c226..970f4774 100644 --- a/doc/self-hosted/index.md +++ b/doc/self-hosted/index.md @@ -48,6 +48,7 @@ OPTIONS -v, --version show CLI version --cert=cert --cert-key=cert-key + --password=password --help show CLI help ``` diff --git a/packages/server/src/cli.ts b/packages/server/src/cli.ts index 0024380e..7bedae71 100644 --- a/packages/server/src/cli.ts +++ b/packages/server/src/cli.ts @@ -26,6 +26,7 @@ export class Entry extends Command { version: flags.version({ char: "v" }), "no-auth": flags.boolean({ default: false }), "allow-http": flags.boolean({ default: false }), + password: flags.string(), // Dev flags "bootstrap-fork": flags.string({ hidden: true }), @@ -132,13 +133,17 @@ export class Entry extends Command { } }); - const passwordLength = 12; - const possible = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - const chars = []; - for (let i = 0; i < passwordLength; i++) { - chars.push(possible[Math.floor(Math.random() * possible.length)]); + let password = flags["password"]; + if (!password) { + // Generate a random password + const passwordLength = 12; + const possible = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + const chars = []; + for (let i = 0; i < passwordLength; i++) { + chars.push(possible[Math.floor(Math.random() * possible.length)]); + } + password = chars.join(""); } - const password = chars.join(""); const hasCustomHttps = certData && certKeyData; const app = await createApp({