11import * as os from "os" ;
2+ import * as path from "path" ;
23
34import { validatePaths } from "vs/code/node/paths" ;
45import { parseMainProcessArgv } from "vs/platform/environment/node/argvHelper" ;
@@ -9,16 +10,16 @@ import pkg from "vs/platform/product/node/package";
910
1011import { MainServer , WebviewServer } from "vs/server/src/server" ;
1112import "vs/server/src/tar" ;
12- import { generateCertificate } from "vs/server/src/util" ;
13+ import { generateCertificate , generatePassword } from "vs/server/src/util" ;
1314
1415interface Args extends ParsedArgs {
1516 "allow-http" ?: boolean ;
17+ auth ?: boolean ;
1618 cert ?: string ;
1719 "cert-key" ?: string ;
1820 "extra-builtin-extensions-dir" ?: string ;
1921 "extra-extensions-dir" ?: string ;
2022 host ?: string ;
21- "no-auth" ?: boolean ;
2223 open ?: string ;
2324 port ?: string ;
2425 socket ?: string ;
@@ -58,7 +59,7 @@ options.push({ id: "cert-key", type: "string", cat: "o", description: "Path to c
5859options . push ( { id : "extra-builtin-extensions-dir" , type : "string" , cat : "o" , description : "Path to extra builtin extension directory." } ) ;
5960options . push ( { id : "extra-extensions-dir" , type : "string" , cat : "o" , description : "Path to extra user extension directory." } ) ;
6061options . push ( { id : "host" , type : "string" , cat : "o" , description : "Host for the main and webview servers." } ) ;
61- options . push ( { id : "no-auth" , type : "string " , cat : "o" , description : "Disable password authentication." } ) ;
62+ options . push ( { id : "no-auth" , type : "boolean " , cat : "o" , description : "Disable password authentication." } ) ;
6263options . push ( { id : "open" , type : "boolean" , cat : "o" , description : "Open in the browser on startup." } ) ;
6364options . push ( { id : "port" , type : "string" , cat : "o" , description : "Port for the main server." } ) ;
6465options . push ( { id : "socket" , type : "string" , cat : "o" , description : "Listen on a socket instead of host:port." } ) ;
@@ -115,17 +116,32 @@ const main = async (): Promise<void> => {
115116 }
116117
117118 const options = {
118- host : args [ "host" ]
119- || ( args [ "no-auth" ] || args [ "allow-http" ] ? "localhost" : "0.0.0.0" ) ,
119+ host : args . host ,
120120 allowHttp : args [ "allow-http" ] ,
121- cert : args [ "cert" ] ,
122- certKey : args [ "cert" ] ,
121+ cert : args . cert ,
122+ certKey : args [ "cert-key" ] ,
123+ auth : typeof args . auth !== "undefined" ? args . auth : true ,
124+ password : process . env . PASSWORD ,
123125 } ;
124126
127+ if ( ! options . host ) {
128+ options . host = ! options . auth || options . allowHttp
129+ ? "localhost"
130+ : "0.0.0.0" ;
131+ }
132+
133+ let usingGeneratedCert = false ;
125134 if ( ! options . allowHttp && ( ! options . cert || ! options . certKey ) ) {
126135 const { cert, certKey } = await generateCertificate ( ) ;
127136 options . cert = cert ;
128137 options . certKey = certKey ;
138+ usingGeneratedCert = true ;
139+ }
140+
141+ let usingGeneratedPassword = false ;
142+ if ( options . auth && ! options . password ) {
143+ options . password = await generatePassword ( ) ;
144+ usingGeneratedPassword = true ;
129145 }
130146
131147 const webviewPort = typeof args [ "webview-port" ] !== "undefined"
@@ -149,6 +165,25 @@ const main = async (): Promise<void> => {
149165 ] ) ;
150166 console . log ( `Main server listening on ${ serverAddress } ` ) ;
151167 console . log ( `Webview server listening on ${ webviewAddress } ` ) ;
168+
169+ if ( usingGeneratedPassword ) {
170+ console . log ( " - Password is" , options . password ) ;
171+ console . log ( " - To use your own password, set the PASSWORD environment variable" ) ;
172+ } else if ( options . auth ) {
173+ console . log ( " - Using custom password for authentication" ) ;
174+ } else {
175+ console . log ( " - No authentication" ) ;
176+ }
177+
178+ if ( ! options . allowHttp && options . cert && options . certKey ) {
179+ console . log (
180+ usingGeneratedCert
181+ ? ` - Using generated certificate and key in ${ path . dirname ( options . cert ) } for HTTPS`
182+ : " - Using provided certificate and key for HTTPS" ,
183+ ) ;
184+ } else {
185+ console . log ( " - Not serving HTTPS" ) ;
186+ }
152187} ;
153188
154189main ( ) . catch ( ( error ) => {
0 commit comments