cli.patch 11 KB

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