Skip to content

Commit d79974f

Browse files
authored
Merge branch 'main' into fix/175397
2 parents a323ac9 + 4789314 commit d79974f

File tree

188 files changed

+5647
-3645
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+5647
-3645
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"files.readonlyInclude": {
3737
"**/node_modules/**": true,
3838
"**/yarn.lock": true,
39+
"**/Cargo.lock": true,
3940
"src/vs/workbench/workbench.web.main.css": true,
4041
"src/vs/workbench/workbench.desktop.main.css": true,
4142
"src/vs/workbench/workbench.desktop.main.nls.js": true,

build/lib/stylelint/vscode-known-variables.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@
316316
"--vscode-inlineChatInput-border",
317317
"--vscode-inlineChatInput-focusBorder",
318318
"--vscode-inlineChatInput-placeholderForeground",
319-
"--vscode-inlineChatrDiff-removed",
320319
"--vscode-input-background",
321320
"--vscode-input-border",
322321
"--vscode-input-foreground",

cli/src/bin/code/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ async fn main() -> Result<(), std::convert::Infallible> {
9595
args::VersionSubcommand::Show => version::show(context!()).await,
9696
},
9797

98-
Some(args::Commands::CommandShell) => tunnels::command_shell(context!()).await,
98+
Some(args::Commands::CommandShell(cs_args)) => {
99+
tunnels::command_shell(context!(), cs_args).await
100+
}
99101

100102
Some(args::Commands::Tunnel(tunnel_args)) => match tunnel_args.subcommand {
101103
Some(args::TunnelSubcommand::Prune) => tunnels::prune(context!()).await,

cli/src/commands/args.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,14 @@ pub enum Commands {
174174

175175
/// Runs the control server on process stdin/stdout
176176
#[clap(hide = true)]
177-
CommandShell,
177+
CommandShell(CommandShellArgs),
178+
}
179+
180+
#[derive(Args, Debug, Clone)]
181+
pub struct CommandShellArgs {
182+
/// Listen on a socket instead of stdin/stdout.
183+
#[clap(long)]
184+
pub on_socket: bool,
178185
}
179186

180187
#[derive(Args, Debug, Clone)]
@@ -548,6 +555,7 @@ pub enum OutputFormat {
548555
#[derive(Args, Clone, Debug, Default)]
549556
pub struct ExistingTunnelArgs {
550557
/// Name you'd like to assign preexisting tunnel to use to connect the tunnel
558+
/// Old option, new code sohuld just use `--name`.
551559
#[clap(long, hide = true)]
552560
pub tunnel_name: Option<String>,
553561

cli/src/commands/tunnels.rs

Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55

66
use async_trait::async_trait;
77
use base64::{engine::general_purpose as b64, Engine as _};
8+
use futures::{stream::FuturesUnordered, StreamExt};
89
use serde::Serialize;
910
use sha2::{Digest, Sha256};
1011
use std::{str::FromStr, time::Duration};
1112
use sysinfo::Pid;
1213

1314
use super::{
1415
args::{
15-
AuthProvider, CliCore, ExistingTunnelArgs, TunnelRenameArgs, TunnelServeArgs,
16-
TunnelServiceSubCommands, TunnelUserSubCommands,
16+
AuthProvider, CliCore, CommandShellArgs, ExistingTunnelArgs, TunnelRenameArgs,
17+
TunnelServeArgs, TunnelServiceSubCommands, TunnelUserSubCommands,
1718
},
1819
CommandContext,
1920
};
2021

2122
use crate::{
23+
async_pipe::{get_socket_name, listen_socket_rw_stream, socket_stream_split},
2224
auth::Auth,
2325
constants::{APPLICATION_NAME, TUNNEL_CLI_LOCK_NAME, TUNNEL_SERVICE_LOCK_NAME},
2426
log,
@@ -59,20 +61,31 @@ impl From<AuthProvider> for crate::auth::AuthProvider {
5961
}
6062
}
6163

62-
impl From<ExistingTunnelArgs> for Option<dev_tunnels::ExistingTunnel> {
63-
fn from(d: ExistingTunnelArgs) -> Option<dev_tunnels::ExistingTunnel> {
64-
if let (Some(tunnel_id), Some(tunnel_name), Some(cluster), Some(host_token)) =
65-
(d.tunnel_id, d.tunnel_name, d.cluster, d.host_token)
66-
{
64+
fn fulfill_existing_tunnel_args(
65+
d: ExistingTunnelArgs,
66+
name_arg: &Option<String>,
67+
) -> Option<dev_tunnels::ExistingTunnel> {
68+
let tunnel_name = d.tunnel_name.or_else(|| name_arg.clone());
69+
70+
match (d.tunnel_id, d.cluster, d.host_token) {
71+
(Some(tunnel_id), None, Some(host_token)) => {
72+
let i = tunnel_id.find('.')?;
6773
Some(dev_tunnels::ExistingTunnel {
68-
tunnel_id,
74+
tunnel_id: tunnel_id[..i].to_string(),
75+
cluster: tunnel_id[i + 1..].to_string(),
6976
tunnel_name,
7077
host_token,
71-
cluster,
7278
})
73-
} else {
74-
None
7579
}
80+
81+
(Some(tunnel_id), Some(cluster), Some(host_token)) => Some(dev_tunnels::ExistingTunnel {
82+
tunnel_id,
83+
tunnel_name,
84+
host_token,
85+
cluster,
86+
}),
87+
88+
_ => None,
7689
}
7790
}
7891

@@ -109,23 +122,55 @@ impl ServiceContainer for TunnelServiceContainer {
109122
}
110123
}
111124

112-
pub async fn command_shell(ctx: CommandContext) -> Result<i32, AnyError> {
125+
pub async fn command_shell(ctx: CommandContext, args: CommandShellArgs) -> Result<i32, AnyError> {
113126
let platform = PreReqChecker::new().verify().await?;
114-
serve_stream(
115-
tokio::io::stdin(),
116-
tokio::io::stderr(),
117-
ServeStreamParams {
118-
log: ctx.log,
119-
launcher_paths: ctx.paths,
120-
platform,
121-
requires_auth: true,
122-
exit_barrier: ShutdownRequest::create_rx([ShutdownRequest::CtrlC]),
123-
code_server_args: (&ctx.args).into(),
124-
},
125-
)
126-
.await;
127+
let mut params = ServeStreamParams {
128+
log: ctx.log,
129+
launcher_paths: ctx.paths,
130+
platform,
131+
requires_auth: true,
132+
exit_barrier: ShutdownRequest::create_rx([ShutdownRequest::CtrlC]),
133+
code_server_args: (&ctx.args).into(),
134+
};
127135

128-
Ok(0)
136+
if !args.on_socket {
137+
serve_stream(tokio::io::stdin(), tokio::io::stderr(), params).await;
138+
return Ok(0);
139+
}
140+
141+
let socket = get_socket_name();
142+
let mut listener = listen_socket_rw_stream(&socket)
143+
.await
144+
.map_err(|e| wrap(e, "error listening on socket"))?;
145+
146+
params
147+
.log
148+
.result(format!("Listening on {}", socket.display()));
149+
150+
let mut servers = FuturesUnordered::new();
151+
152+
loop {
153+
tokio::select! {
154+
Some(_) = servers.next() => {},
155+
socket = listener.accept() => {
156+
match socket {
157+
Ok(s) => {
158+
let (read, write) = socket_stream_split(s);
159+
servers.push(serve_stream(read, write, params.clone()));
160+
},
161+
Err(e) => {
162+
error!(params.log, &format!("Error accepting connection: {}", e));
163+
return Ok(1);
164+
}
165+
}
166+
},
167+
_ = params.exit_barrier.wait() => {
168+
// wait for all servers to finish up:
169+
while (servers.next().await).is_some() { }
170+
return Ok(0);
171+
}
172+
}
173+
}
129174
}
130175

131176
pub async fn service(
@@ -412,8 +457,10 @@ async fn serve_with_csa(
412457
let auth = Auth::new(&paths, log.clone());
413458
let mut dt = dev_tunnels::DevTunnels::new(&log, auth, &paths);
414459
loop {
415-
let tunnel = if let Some(d) = gateway_args.tunnel.clone().into() {
416-
dt.start_existing_tunnel(d).await
460+
let tunnel = if let Some(t) =
461+
fulfill_existing_tunnel_args(gateway_args.tunnel.clone(), &gateway_args.name)
462+
{
463+
dt.start_existing_tunnel(t).await
417464
} else {
418465
dt.start_new_launcher_tunnel(gateway_args.name.as_deref(), gateway_args.random_name)
419466
.await

cli/src/tunnels/control_server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ pub async fn serve(
233233
}
234234
}
235235

236+
#[derive(Clone)]
236237
pub struct ServeStreamParams {
237238
pub log: log::Logger,
238239
pub launcher_paths: LauncherPaths,

cli/src/tunnels/dev_tunnels.rs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ lazy_static! {
229229
#[derive(Clone, Debug)]
230230
pub struct ExistingTunnel {
231231
/// Name you'd like to assign preexisting tunnel to use to connect to the VS Code Server
232-
pub tunnel_name: String,
232+
pub tunnel_name: Option<String>,
233233

234234
/// Token to authenticate and use preexisting tunnel
235235
pub host_token: String,
@@ -393,7 +393,12 @@ impl DevTunnels {
393393
};
394394

395395
tunnel = self
396-
.sync_tunnel_tags(&persisted.name, tunnel, &HOST_TUNNEL_REQUEST_OPTIONS)
396+
.sync_tunnel_tags(
397+
&self.client,
398+
&persisted.name,
399+
tunnel,
400+
&HOST_TUNNEL_REQUEST_OPTIONS,
401+
)
397402
.await?;
398403

399404
let locator = TunnelLocator::try_from(&tunnel).unwrap();
@@ -532,6 +537,7 @@ impl DevTunnels {
532537
/// other version tags.
533538
async fn sync_tunnel_tags(
534539
&self,
540+
client: &TunnelManagementClient,
535541
name: &str,
536542
tunnel: Tunnel,
537543
options: &TunnelRequestOptions,
@@ -558,7 +564,7 @@ impl DevTunnels {
558564
let result = spanf!(
559565
self.log,
560566
self.log.span("dev-tunnel.protocol-tag-update"),
561-
self.client.update_tunnel(&tunnel_update, options)
567+
client.update_tunnel(&tunnel_update, options)
562568
);
563569

564570
result.map_err(|e| wrap(e, "tunnel tag update failed").into())
@@ -639,6 +645,12 @@ impl DevTunnels {
639645
Ok(())
640646
}
641647

648+
fn get_placeholder_name() -> String {
649+
let mut n = clean_hostname_for_tunnel(&gethostname::gethostname().to_string_lossy());
650+
n.make_ascii_lowercase();
651+
n
652+
}
653+
642654
async fn get_name_for_tunnel(
643655
&mut self,
644656
preferred_name: Option<&str>,
@@ -670,10 +682,7 @@ impl DevTunnels {
670682
use_random_name = true;
671683
}
672684

673-
let mut placeholder_name =
674-
clean_hostname_for_tunnel(&gethostname::gethostname().to_string_lossy());
675-
placeholder_name.make_ascii_lowercase();
676-
685+
let mut placeholder_name = Self::get_placeholder_name();
677686
if !is_name_free(&placeholder_name) {
678687
for i in 2.. {
679688
let fixed_name = format!("{}{}", placeholder_name, i);
@@ -715,7 +724,10 @@ impl DevTunnels {
715724
tunnel: ExistingTunnel,
716725
) -> Result<ActiveTunnel, AnyError> {
717726
let tunnel_details = PersistedTunnel {
718-
name: tunnel.tunnel_name,
727+
name: match tunnel.tunnel_name {
728+
Some(n) => n,
729+
None => Self::get_placeholder_name(),
730+
},
719731
id: tunnel.tunnel_id,
720732
cluster: tunnel.cluster,
721733
};
@@ -725,10 +737,23 @@ impl DevTunnels {
725737
tunnel.host_token.clone(),
726738
));
727739

740+
let client = mgmt.into();
741+
self.sync_tunnel_tags(
742+
&client,
743+
&tunnel_details.name,
744+
Tunnel {
745+
cluster_id: Some(tunnel_details.cluster.clone()),
746+
tunnel_id: Some(tunnel_details.id.clone()),
747+
..Default::default()
748+
},
749+
&HOST_TUNNEL_REQUEST_OPTIONS,
750+
)
751+
.await?;
752+
728753
self.start_tunnel(
729754
tunnel_details.locator(),
730755
&tunnel_details,
731-
mgmt.into(),
756+
client,
732757
StaticAccessTokenProvider::new(tunnel.host_token),
733758
)
734759
.await

extensions/github-authentication/extension-browser.webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ module.exports = withBrowserDefaults({
2121
'uuid': path.resolve(__dirname, 'node_modules/uuid/dist/esm-browser/index.js'),
2222
'./node/authServer': path.resolve(__dirname, 'src/browser/authServer'),
2323
'./node/crypto': path.resolve(__dirname, 'src/browser/crypto'),
24-
'./node/fetch': path.resolve(__dirname, 'src/browser/fetch')
24+
'./node/fetch': path.resolve(__dirname, 'src/browser/fetch'),
25+
'./node/buffer': path.resolve(__dirname, 'src/browser/buffer'),
2526
}
2627
}
2728
});

src/vscode-dts/vscode.proposed.quickPickItemIcon.d.ts renamed to extensions/github-authentication/src/browser/buffer.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
declare module 'vscode' {
7-
/**
8-
* Represents an item that can be selected from
9-
* a list of items.
10-
*/
11-
export interface QuickPickItem {
12-
/**
13-
* The icon path or {@link ThemeIcon} for the QuickPickItem.
14-
*/
15-
iconPath?: Uri | { light: Uri; dark: Uri } | ThemeIcon;
16-
}
6+
export function base64Encode(text: string): string {
7+
return btoa(text);
178
}

extensions/github-authentication/src/common/logger.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ export class Log {
2626
this.output.error(message);
2727
}
2828

29+
public warn(message: string): void {
30+
this.output.warn(message);
31+
}
2932
}

0 commit comments

Comments
 (0)