Skip to content

Commit b6d022b

Browse files
authored
fix: --connection-token-file not functional in "code serve-web" (microsoft#223524)
Fixes microsoft#215537
1 parent 3873c58 commit b6d022b

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

cli/src/commands/serve_web.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,19 @@ pub async fn serve_web(ctx: CommandContext, mut args: ServeWebArgs) -> Result<i3
7171

7272
let platform: crate::update_service::Platform = PreReqChecker::new().verify().await?;
7373
if !args.without_connection_token {
74-
// Ensure there's a defined connection token, since if multiple server versions
75-
// are excuted, they will need to have a single shared token.
76-
let token_path = ctx.paths.root().join("serve-web-token");
77-
let token = mint_connection_token(&token_path, args.connection_token.clone())
78-
.map_err(CodeError::CouldNotCreateConnectionTokenFile)?;
79-
args.connection_token = Some(token);
80-
args.connection_token_file = Some(token_path.to_string_lossy().to_string());
74+
if let Some(p) = args.connection_token_file.as_deref() {
75+
let token = fs::read_to_string(PathBuf::from(p))
76+
.map_err(CodeError::CouldNotReadConnectionTokenFile)?;
77+
args.connection_token = Some(token.trim().to_string());
78+
} else {
79+
// Ensure there's a defined connection token, since if multiple server versions
80+
// are executed, they will need to have a single shared token.
81+
let token_path = ctx.paths.root().join("serve-web-token");
82+
let token = mint_connection_token(&token_path, args.connection_token.clone())
83+
.map_err(CodeError::CouldNotCreateConnectionTokenFile)?;
84+
args.connection_token = Some(token);
85+
args.connection_token_file = Some(token_path.to_string_lossy().to_string());
86+
}
8187
}
8288

8389
let cm = ConnectionManager::new(&ctx, platform, args.clone());

cli/src/util/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ pub enum CodeError {
512512
// todo: can be specialized when update service is moved to CodeErrors
513513
#[error("Could not check for update: {0}")]
514514
UpdateCheckFailed(String),
515+
#[error("Could not read connection token file: {0}")]
516+
CouldNotReadConnectionTokenFile(std::io::Error),
515517
#[error("Could not write connection token file: {0}")]
516518
CouldNotCreateConnectionTokenFile(std::io::Error),
517519
#[error("A tunnel with the name {0} exists and is in-use. Please pick a different name or stop the existing tunnel.")]

0 commit comments

Comments
 (0)