cli.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. diff --git a/cli/src/commands/serve_web.rs b/cli/src/commands/serve_web.rs
  2. index 2ddefe1..ab9c658 100644
  3. --- a/cli/src/commands/serve_web.rs
  4. +++ b/cli/src/commands/serve_web.rs
  5. @@ -730,3 +730,3 @@ impl ConnectionManager {
  6. let dir_fut = cache.create(&args.release.commit, |target_dir| async move {
  7. - info!(log_for_fut, "Downloading server {}", release_for_fut.commit);
  8. + info!(log_for_fut, "Downloading server {}/{}", release_for_fut.commit, release_for_fut.name);
  9. let tmpdir = tempfile::tempdir().unwrap();
  10. @@ -758,3 +758,3 @@ impl ConnectionManager {
  11. .join("bin")
  12. - .join(args.release.quality.server_entrypoint());
  13. + .join(args.release.quality.server_entrypoint().unwrap());
  14. diff --git a/cli/src/constants.rs b/cli/src/constants.rs
  15. index 1e277a8..97f17d3 100644
  16. --- a/cli/src/constants.rs
  17. +++ b/cli/src/constants.rs
  18. @@ -35,3 +35,6 @@ pub const DOCUMENTATION_URL: Option<&'static str> = option_env!("VSCODE_CLI_DOCU
  19. pub const VSCODE_CLI_COMMIT: Option<&'static str> = option_env!("VSCODE_CLI_COMMIT");
  20. -pub const VSCODE_CLI_UPDATE_ENDPOINT: Option<&'static str> = option_env!("VSCODE_CLI_UPDATE_URL");
  21. +pub const VSCODE_CLI_UPDATE_ENDPOINT: Option<&'static str> = option_env!("VSCODE_CLI_UPDATE_ENDPOINT");
  22. +pub const VSCODE_CLI_DOWNLOAD_ENDPOINT: Option<&'static str> = option_env!("VSCODE_CLI_DOWNLOAD_ENDPOINT");
  23. +pub const VSCODE_CLI_APP_NAME: Option<&'static str> = option_env!("VSCODE_CLI_APP_NAME");
  24. +pub const VSCODE_CLI_BINARY_NAME: Option<&'static str> = option_env!("VSCODE_CLI_BINARY_NAME");
  25. diff --git a/cli/src/options.rs b/cli/src/options.rs
  26. index 7d152c0..c0f2fb2 100644
  27. --- a/cli/src/options.rs
  28. +++ b/cli/src/options.rs
  29. @@ -9,3 +9,3 @@ use serde::{Deserialize, Serialize};
  30. -use crate::constants::SERVER_NAME_MAP;
  31. +use crate::{constants::VSCODE_CLI_BINARY_NAME, util::errors::CodeError};
  32. @@ -21,2 +21,6 @@ pub enum Quality {
  33. +fn get_binary_name() -> Result<&'static str, CodeError> {
  34. + VSCODE_CLI_BINARY_NAME.ok_or_else(|| CodeError::UpdatesNotConfigured("no binary name"))
  35. +}
  36. +
  37. impl Quality {
  38. @@ -41,9 +45,4 @@ impl Quality {
  39. /// Server application name
  40. - pub fn server_entrypoint(&self) -> String {
  41. - let mut server_name = SERVER_NAME_MAP
  42. - .as_ref()
  43. - .and_then(|m| m.get(self))
  44. - .map(|s| s.server_application_name.as_str())
  45. - .unwrap_or("code-server-oss")
  46. - .to_string();
  47. + pub fn server_entrypoint(&self) -> Result<String, CodeError> {
  48. + let mut server_name = get_binary_name()?.to_string();
  49. @@ -53,3 +52,3 @@ impl Quality {
  50. - server_name
  51. + Ok(server_name)
  52. }
  53. diff --git a/cli/src/tunnels/code_server.rs b/cli/src/tunnels/code_server.rs
  54. index cf00bc4..b564330 100644
  55. --- a/cli/src/tunnels/code_server.rs
  56. +++ b/cli/src/tunnels/code_server.rs
  57. @@ -457,3 +457,3 @@ impl<'a> ServerBuilder<'a> {
  58. .join("bin")
  59. - .join(self.server_params.release.quality.server_entrypoint()),
  60. + .join(self.server_params.release.quality.server_entrypoint().unwrap()),
  61. &["--version"],
  62. diff --git a/cli/src/tunnels/paths.rs b/cli/src/tunnels/paths.rs
  63. index 3d7d718..98529bc 100644
  64. --- a/cli/src/tunnels/paths.rs
  65. +++ b/cli/src/tunnels/paths.rs
  66. @@ -100,3 +100,3 @@ impl InstalledServer {
  67. .join("bin")
  68. - .join(self.quality.server_entrypoint())
  69. + .join(self.quality.server_entrypoint().unwrap())
  70. },
  71. diff --git a/cli/src/update_service.rs b/cli/src/update_service.rs
  72. index 9033914..a39bbf7 100644
  73. --- a/cli/src/update_service.rs
  74. +++ b/cli/src/update_service.rs
  75. @@ -10,3 +10,3 @@ use serde::{Deserialize, Serialize};
  76. use crate::{
  77. - constants::VSCODE_CLI_UPDATE_ENDPOINT,
  78. + constants::{VSCODE_CLI_APP_NAME, VSCODE_CLI_DOWNLOAD_ENDPOINT, VSCODE_CLI_UPDATE_ENDPOINT},
  79. debug, log, options, spanf,
  80. @@ -18,3 +18,3 @@ use crate::{
  81. zipper,
  82. - },
  83. + }
  84. };
  85. @@ -58,4 +58,12 @@ fn quality_download_segment(quality: options::Quality) -> &'static str {
  86. +fn get_app_name() -> Result<&'static str, CodeError> {
  87. + VSCODE_CLI_APP_NAME.ok_or_else(|| CodeError::UpdatesNotConfigured("no app name"))
  88. +}
  89. +
  90. +fn get_download_endpoint() -> Result<&'static str, CodeError> {
  91. + VSCODE_CLI_DOWNLOAD_ENDPOINT.ok_or_else(|| CodeError::UpdatesNotConfigured("no download url"))
  92. +}
  93. +
  94. fn get_update_endpoint() -> Result<&'static str, CodeError> {
  95. - VSCODE_CLI_UPDATE_ENDPOINT.ok_or_else(|| CodeError::UpdatesNotConfigured("no service url"))
  96. + VSCODE_CLI_UPDATE_ENDPOINT.ok_or_else(|| CodeError::UpdatesNotConfigured("no update url"))
  97. }
  98. @@ -67,3 +75,4 @@ impl UpdateService {
  99. - pub async fn get_release_by_semver_version(
  100. + /// Gets the latest commit for the target of the given quality.
  101. + pub async fn get_latest_commit(
  102. &self,
  103. @@ -72,14 +81,10 @@ impl UpdateService {
  104. quality: options::Quality,
  105. - version: &str,
  106. ) -> Result<Release, AnyError> {
  107. let update_endpoint = get_update_endpoint()?;
  108. - let download_segment = target
  109. - .download_segment(platform)
  110. - .ok_or_else(|| CodeError::UnsupportedPlatform(platform.to_string()))?;
  111. let download_url = format!(
  112. - "{}/api/versions/{}/{}/{}",
  113. + "{}/{}/{}/{}/latest.json",
  114. update_endpoint,
  115. - version,
  116. - download_segment,
  117. quality_download_segment(quality),
  118. + platform.os(),
  119. + platform.arch(),
  120. );
  121. @@ -97,3 +102,3 @@ impl UpdateService {
  122. let res = response.json::<UpdateServerVersion>().await?;
  123. - debug!(self.log, "Resolved version {} to {}", version, res.version);
  124. + debug!(self.log, "Resolved quality {} to {}", quality, res.version);
  125. @@ -108,40 +113,17 @@ impl UpdateService {
  126. - /// Gets the latest commit for the target of the given quality.
  127. - pub async fn get_latest_commit(
  128. - &self,
  129. - platform: Platform,
  130. - target: TargetKind,
  131. - quality: options::Quality,
  132. - ) -> Result<Release, AnyError> {
  133. - let update_endpoint = get_update_endpoint()?;
  134. - let download_segment = target
  135. - .download_segment(platform)
  136. - .ok_or_else(|| CodeError::UnsupportedPlatform(platform.to_string()))?;
  137. + pub fn get_download_url(&self, release: &Release) -> Result<String, AnyError> {
  138. + let app_name = get_app_name()?;
  139. + let download_endpoint = get_download_endpoint()?;
  140. +
  141. let download_url = format!(
  142. - "{}/api/latest/{}/{}",
  143. - update_endpoint,
  144. - download_segment,
  145. - quality_download_segment(quality),
  146. + "{}/download/{}/{}-reh-web-{}-{}-{}.tar.gz",
  147. + download_endpoint,
  148. + release.name,
  149. + app_name,
  150. + release.platform.os(),
  151. + release.platform.arch(),
  152. + release.name,
  153. );
  154. - let mut response = spanf!(
  155. - self.log,
  156. - self.log.span("server.version.resolve"),
  157. - self.client.make_request("GET", download_url)
  158. - )?;
  159. -
  160. - if !response.status_code.is_success() {
  161. - return Err(response.into_err().await.into());
  162. - }
  163. -
  164. - let res = response.json::<UpdateServerVersion>().await?;
  165. - debug!(self.log, "Resolved quality {} to {}", quality, res.version);
  166. -
  167. - Ok(Release {
  168. - target,
  169. - platform,
  170. - quality,
  171. - name: res.name,
  172. - commit: res.version,
  173. - })
  174. + Ok(download_url)
  175. }
  176. @@ -150,15 +132,3 @@ impl UpdateService {
  177. pub async fn get_download_stream(&self, release: &Release) -> Result<SimpleResponse, AnyError> {
  178. - let update_endpoint = get_update_endpoint()?;
  179. - let download_segment = release
  180. - .target
  181. - .download_segment(release.platform)
  182. - .ok_or_else(|| CodeError::UnsupportedPlatform(release.platform.to_string()))?;
  183. -
  184. - let download_url = format!(
  185. - "{}/commit:{}/{}/{}",
  186. - update_endpoint,
  187. - release.commit,
  188. - download_segment,
  189. - quality_download_segment(release.quality),
  190. - );
  191. + let download_url = self.get_download_url(release)?;
  192. @@ -196,13 +166,2 @@ pub enum TargetKind {
  193. -impl TargetKind {
  194. - fn download_segment(&self, platform: Platform) -> Option<String> {
  195. - match *self {
  196. - TargetKind::Server => Some(platform.headless()),
  197. - TargetKind::Archive => platform.archive(),
  198. - TargetKind::Web => Some(platform.web()),
  199. - TargetKind::Cli => Some(platform.cli()),
  200. - }
  201. - }
  202. -}
  203. -
  204. #[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
  205. @@ -225,30 +184,17 @@ pub enum Platform {
  206. impl Platform {
  207. - pub fn archive(&self) -> Option<String> {
  208. - match self {
  209. - Platform::LinuxX64 => Some("linux-x64".to_owned()),
  210. - Platform::LinuxARM64 => Some("linux-arm64".to_owned()),
  211. - Platform::LinuxARM32 => Some("linux-armhf".to_owned()),
  212. - Platform::DarwinX64 => Some("darwin".to_owned()),
  213. - Platform::DarwinARM64 => Some("darwin-arm64".to_owned()),
  214. - Platform::WindowsX64 => Some("win32-x64-archive".to_owned()),
  215. - Platform::WindowsX86 => Some("win32-archive".to_owned()),
  216. - Platform::WindowsARM64 => Some("win32-arm64-archive".to_owned()),
  217. - _ => None,
  218. - }
  219. - }
  220. - pub fn headless(&self) -> String {
  221. + pub fn arch(&self) -> String {
  222. match self {
  223. - Platform::LinuxAlpineARM64 => "server-alpine-arm64",
  224. - Platform::LinuxAlpineX64 => "server-linux-alpine",
  225. - Platform::LinuxX64 => "server-linux-x64",
  226. - Platform::LinuxX64Legacy => "server-linux-legacy-x64",
  227. - Platform::LinuxARM64 => "server-linux-arm64",
  228. - Platform::LinuxARM64Legacy => "server-linux-legacy-arm64",
  229. - Platform::LinuxARM32 => "server-linux-armhf",
  230. - Platform::LinuxARM32Legacy => "server-linux-legacy-armhf",
  231. - Platform::DarwinX64 => "server-darwin",
  232. - Platform::DarwinARM64 => "server-darwin-arm64",
  233. - Platform::WindowsX64 => "server-win32-x64",
  234. - Platform::WindowsX86 => "server-win32",
  235. - Platform::WindowsARM64 => "server-win32-arm64",
  236. + Platform::LinuxAlpineARM64 => "arm64",
  237. + Platform::LinuxAlpineX64 => "x64",
  238. + Platform::LinuxX64 => "x64",
  239. + Platform::LinuxX64Legacy => "x64",
  240. + Platform::LinuxARM64 => "arm64",
  241. + Platform::LinuxARM64Legacy => "arm64",
  242. + Platform::LinuxARM32 => "armhf",
  243. + Platform::LinuxARM32Legacy => "armhf",
  244. + Platform::DarwinX64 => "x64",
  245. + Platform::DarwinARM64 => "arm64",
  246. + Platform::WindowsX64 => "x64",
  247. + Platform::WindowsX86 => "ia42",
  248. + Platform::WindowsARM64 => "arm64",
  249. }
  250. @@ -257,17 +203,17 @@ impl Platform {
  251. - pub fn cli(&self) -> String {
  252. + pub fn os(&self) -> String {
  253. match self {
  254. - Platform::LinuxAlpineARM64 => "cli-alpine-arm64",
  255. - Platform::LinuxAlpineX64 => "cli-alpine-x64",
  256. - Platform::LinuxX64 => "cli-linux-x64",
  257. - Platform::LinuxX64Legacy => "cli-linux-x64",
  258. - Platform::LinuxARM64 => "cli-linux-arm64",
  259. - Platform::LinuxARM64Legacy => "cli-linux-arm64",
  260. - Platform::LinuxARM32 => "cli-linux-armhf",
  261. - Platform::LinuxARM32Legacy => "cli-linux-armhf",
  262. - Platform::DarwinX64 => "cli-darwin-x64",
  263. - Platform::DarwinARM64 => "cli-darwin-arm64",
  264. - Platform::WindowsARM64 => "cli-win32-arm64",
  265. - Platform::WindowsX64 => "cli-win32-x64",
  266. - Platform::WindowsX86 => "cli-win32",
  267. + Platform::LinuxAlpineARM64 => "alpine",
  268. + Platform::LinuxAlpineX64 => "alpine",
  269. + Platform::LinuxX64 => "linux",
  270. + Platform::LinuxX64Legacy => "linux",
  271. + Platform::LinuxARM64 => "linux",
  272. + Platform::LinuxARM64Legacy => "linux",
  273. + Platform::LinuxARM32 => "linux",
  274. + Platform::LinuxARM32Legacy => "linux",
  275. + Platform::DarwinX64 => "darwin",
  276. + Platform::DarwinARM64 => "darwin",
  277. + Platform::WindowsX64 => "win32",
  278. + Platform::WindowsX86 => "win32",
  279. + Platform::WindowsARM64 => "win32",
  280. }
  281. @@ -276,6 +222,2 @@ impl Platform {
  282. - pub fn web(&self) -> String {
  283. - format!("{}-web", self.headless())
  284. - }
  285. -
  286. pub fn env_default() -> Option<Platform> {