Allow password authentication in the config file
This commit is contained in:
parent
4f67f4e096
commit
e02d94ad2f
@ -23,6 +23,7 @@ export class OptionalString extends Optional<string> {}
|
|||||||
export interface Args extends VsArgs {
|
export interface Args extends VsArgs {
|
||||||
readonly config?: string
|
readonly config?: string
|
||||||
readonly auth?: AuthType
|
readonly auth?: AuthType
|
||||||
|
readonly password?: string
|
||||||
readonly cert?: OptionalString
|
readonly cert?: OptionalString
|
||||||
readonly "cert-key"?: string
|
readonly "cert-key"?: string
|
||||||
readonly "disable-telemetry"?: boolean
|
readonly "disable-telemetry"?: boolean
|
||||||
@ -83,6 +84,7 @@ type Options<T> = {
|
|||||||
|
|
||||||
const options: Options<Required<Args>> = {
|
const options: Options<Required<Args>> = {
|
||||||
auth: { type: AuthType, description: "The type of authentication to use." },
|
auth: { type: AuthType, description: "The type of authentication to use." },
|
||||||
|
password: { type: "string", description: "The password for password authentication." },
|
||||||
cert: {
|
cert: {
|
||||||
type: OptionalString,
|
type: OptionalString,
|
||||||
path: true,
|
path: true,
|
||||||
@ -96,7 +98,10 @@ const options: Options<Required<Args>> = {
|
|||||||
|
|
||||||
"bind-addr": { type: "string", description: "Address to bind to in host:port." },
|
"bind-addr": { type: "string", description: "Address to bind to in host:port." },
|
||||||
|
|
||||||
config: { type: "string", description: "Path to yaml config file." },
|
config: {
|
||||||
|
type: "string",
|
||||||
|
description: "Path to yaml config file. Every flag maps directory to a key in the config file.",
|
||||||
|
},
|
||||||
|
|
||||||
// These two have been deprecated by bindAddr.
|
// These two have been deprecated by bindAddr.
|
||||||
host: { type: "string", description: "" },
|
host: { type: "string", description: "" },
|
||||||
|
@ -40,7 +40,8 @@ const main = async (args: Args): Promise<void> => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auth = args.auth || AuthType.Password
|
const auth = args.auth || AuthType.Password
|
||||||
const originalPassword = auth === AuthType.Password && (process.env.PASSWORD || (await generatePassword()))
|
const generatedPassword = (args.password || process.env.PASSWORD) !== ""
|
||||||
|
const password = auth === AuthType.Password && (args.password || process.env.PASSWORD || (await generatePassword()))
|
||||||
|
|
||||||
let host = args.host
|
let host = args.host
|
||||||
let port = args.port
|
let port = args.port
|
||||||
@ -55,7 +56,7 @@ const main = async (args: Args): Promise<void> => {
|
|||||||
auth,
|
auth,
|
||||||
commit,
|
commit,
|
||||||
host: host || (args.auth === AuthType.Password && args.cert !== undefined ? "0.0.0.0" : "localhost"),
|
host: host || (args.auth === AuthType.Password && args.cert !== undefined ? "0.0.0.0" : "localhost"),
|
||||||
password: originalPassword ? hash(originalPassword) : undefined,
|
password: password ? hash(password) : undefined,
|
||||||
port: port !== undefined ? port : process.env.PORT ? parseInt(process.env.PORT, 10) : 8080,
|
port: port !== undefined ? port : process.env.PORT ? parseInt(process.env.PORT, 10) : 8080,
|
||||||
proxyDomains: args["proxy-domain"],
|
proxyDomains: args["proxy-domain"],
|
||||||
socket: args.socket,
|
socket: args.socket,
|
||||||
@ -86,9 +87,9 @@ const main = async (args: Args): Promise<void> => {
|
|||||||
const serverAddress = await httpServer.listen()
|
const serverAddress = await httpServer.listen()
|
||||||
logger.info(`HTTP server listening on ${serverAddress}`)
|
logger.info(`HTTP server listening on ${serverAddress}`)
|
||||||
|
|
||||||
if (auth === AuthType.Password && !process.env.PASSWORD) {
|
if (auth === AuthType.Password && generatedPassword) {
|
||||||
logger.info(` - Password is ${originalPassword}`)
|
logger.info(` - Password is ${password}`)
|
||||||
logger.info(" - To use your own password set the PASSWORD environment variable")
|
logger.info(" - To use your own password set it in the config file with the password key or use $PASSWORD")
|
||||||
if (!args.auth) {
|
if (!args.auth) {
|
||||||
logger.info(" - To disable use `--auth none`")
|
logger.info(" - To disable use `--auth none`")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user