From 2de0e45287baf650425b9b10e6d23096f4a18c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Dec 2022 16:50:39 +0100 Subject: [PATCH 01/32] Initial implementation for new wasmer config --- lib/cli/src/cli.rs | 1 + lib/cli/src/commands/config.rs | 150 ++++++++++++++++++++------------- 2 files changed, 93 insertions(+), 58 deletions(-) diff --git a/lib/cli/src/cli.rs b/lib/cli/src/cli.rs index 3b9b8cea6f3..304fcb25858 100644 --- a/lib/cli/src/cli.rs +++ b/lib/cli/src/cli.rs @@ -126,6 +126,7 @@ enum WasmerCLIOptions { /// Get various configuration information needed /// to compile programs which use Wasmer + #[clap(subcommand)] Config(Config), /// Update wasmer to the latest version diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index 2137f6e0caa..9652bac55b0 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -3,38 +3,52 @@ use anyhow::{Context, Result}; use clap::Parser; use std::env; use std::path::PathBuf; +use wasmer_registry::PartialWapmConfig; #[derive(Debug, Parser)] -/// The options for the `wasmer config` subcommand -pub struct Config { - /// Print the installation prefix. - #[clap(long, conflicts_with = "pkg-config")] - prefix: bool, - - /// Directory containing Wasmer executables. - #[clap(long, conflicts_with = "pkg-config")] - bindir: bool, - - /// Directory containing Wasmer headers. - #[clap(long, conflicts_with = "pkg-config")] - includedir: bool, - - /// Directory containing Wasmer libraries. - #[clap(long, conflicts_with = "pkg-config")] - libdir: bool, +/// The options for the `wasmer config` subcommand: `wasmer config get prefix` +pub enum Config { + /// Get a value from the current wasmer config + #[clap(subcommand)] + Get(RetrievableConfigField), + /// Set a value in the current wasmer config + #[clap(subcommand)] + Set(StorableConfigField), +} - /// Libraries needed to link against Wasmer components. - #[clap(long, conflicts_with = "pkg-config")] - libs: bool, +/// Value that can be queried from the wasmer config +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, clap::Subcommand)] +pub enum RetrievableConfigField { + /// `prefix` + Prefix, + /// `bin-dir` + Bindir, + /// `includedir` + Includedir, + /// `libdir` + Libdir, + /// `libs` + Libs, + /// `cflags` + Cflags, + /// `pkg-config` + PkgConfig, +} - /// C compiler flags for files that include Wasmer headers. - #[clap(long, conflicts_with = "pkg-config")] - cflags: bool, +/// Setting that can be stored in the wasmer config +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, clap::Subcommand)] +pub enum StorableConfigField { + /// `registry.url` + #[clap(name = "registry.url")] + RegistryUrl(SetRegistryUrl), +} - /// It outputs the necessary details for compiling - /// and linking a program to Wasmer, using the `pkg-config` format. - #[clap(long)] - pkg_config: bool, +/// Set a new registry URL +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] +pub struct SetRegistryUrl { + /// Url of the registry + #[clap(name = "URL")] + pub url: String, } impl Config { @@ -44,6 +58,8 @@ impl Config { .context("failed to retrieve the wasmer config".to_string()) } fn inner_execute(&self) -> Result<()> { + use self::Config::{Get, Set}; + let key = "WASMER_DIR"; let wasmer_dir = env::var(key) .or_else(|e| { @@ -65,37 +81,55 @@ impl Config { let cflags = format!("-I{}", includedir); let libs = format!("-L{} -lwasmer", libdir); - if self.pkg_config { - println!("prefix={}", prefixdir); - println!("exec_prefix={}", bindir); - println!("includedir={}", includedir); - println!("libdir={}", libdir); - println!(); - println!("Name: wasmer"); - println!("Description: The Wasmer library for running WebAssembly"); - println!("Version: {}", VERSION); - println!("Cflags: {}", cflags); - println!("Libs: {}", libs); - return Ok(()); - } - - if self.prefix { - println!("{}", prefixdir); - } - if self.bindir { - println!("{}", bindir); - } - if self.includedir { - println!("{}", includedir); - } - if self.libdir { - println!("{}", libdir); - } - if self.libs { - println!("{}", libs); - } - if self.cflags { - println!("{}", cflags); + match self { + Get(g) => match g { + RetrievableConfigField::PkgConfig => { + println!("prefix={}", prefixdir); + println!("exec_prefix={}", bindir); + println!("includedir={}", includedir); + println!("libdir={}", libdir); + println!(); + println!("Name: wasmer"); + println!("Description: The Wasmer library for running WebAssembly"); + println!("Version: {}", VERSION); + println!("Cflags: {}", cflags); + println!("Libs: {}", libs); + } + RetrievableConfigField::Prefix => { + println!("{}", prefixdir); + } + RetrievableConfigField::Bindir => { + println!("{}", bindir); + } + RetrievableConfigField::Includedir => { + println!("{}", includedir); + } + RetrievableConfigField::Libdir => { + println!("{}", libdir); + } + RetrievableConfigField::Libs => { + println!("{}", libs); + } + RetrievableConfigField::Cflags => { + println!("{}", cflags); + } + }, + Set(s) => match s { + StorableConfigField::RegistryUrl(s) => { + let config_file = PartialWapmConfig::get_file_location() + .map_err(|e| anyhow::anyhow!("could not find config file {e}"))?; + let mut config = PartialWapmConfig::from_file() + .map_err(|e| anyhow::anyhow!("could not find config file {e}"))?; + config.registry.set_current_registry(&s.url); + config + .save(config_file) + .with_context(|| anyhow::anyhow!("could not save config file"))?; + println!( + "set current registry to {}", + config.registry.get_current_registry() + ); + } + }, } Ok(()) } From 2923147e411c58098d9c2b763a13bc98e808c3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Dec 2022 20:38:35 +0100 Subject: [PATCH 02/32] Finish porting wapm config --- lib/cli/src/commands/config.rs | 101 +++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 16 deletions(-) diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index 9652bac55b0..d272f539191 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -41,9 +41,21 @@ pub enum StorableConfigField { /// `registry.url` #[clap(name = "registry.url")] RegistryUrl(SetRegistryUrl), + /// `registry.token` + #[clap(name = "registry.token")] + RegistryToken(SetRegistryToken), + /// `telemetry.enabled` + #[clap(name = "telemetry.enabled")] + TelemetryEnabled(SetTelemetryEnabled), + /// `update-notifications.url` + #[clap(name = "update-notifications.enabled")] + UpdateNotificationsEnabled(SetUpdateNotificationsEnabled), + /// `proxy.url` + #[clap(name = "proxy.url")] + ProxyUrl(SetProxyUrl), } -/// Set a new registry URL +/// Set the current active registry URL #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] pub struct SetRegistryUrl { /// Url of the registry @@ -51,6 +63,38 @@ pub struct SetRegistryUrl { pub url: String, } +/// Set or change the token for the current active registry +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] +pub struct SetRegistryToken { + /// Token to set + #[clap(name = "TOKEN")] + pub token: String, +} + +/// Set if update notifications are enabled +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] +pub struct SetUpdateNotificationsEnabled { + /// Whether to enable update notifications + #[clap(name = "ENABLED", possible_values = ["true", "false"])] + pub enabled: String, +} + +/// Set if telemetry is enabled +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] +pub struct SetTelemetryEnabled { + /// Whether to enable telemetry + #[clap(name = "ENABLED", possible_values = ["true", "false"])] + pub enabled: String, +} + +/// Set if a proxy URL should be used +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] +pub struct SetProxyUrl { + /// Set if a proxy URL should be used (empty = unset proxy) + #[clap(name = "URL")] + pub url: Option, +} + impl Config { /// Runs logic for the `config` subcommand pub fn execute(&self) -> Result<()> { @@ -114,22 +158,47 @@ impl Config { println!("{}", cflags); } }, - Set(s) => match s { - StorableConfigField::RegistryUrl(s) => { - let config_file = PartialWapmConfig::get_file_location() - .map_err(|e| anyhow::anyhow!("could not find config file {e}"))?; - let mut config = PartialWapmConfig::from_file() - .map_err(|e| anyhow::anyhow!("could not find config file {e}"))?; - config.registry.set_current_registry(&s.url); - config - .save(config_file) - .with_context(|| anyhow::anyhow!("could not save config file"))?; - println!( - "set current registry to {}", - config.registry.get_current_registry() - ); + Set(s) => { + let config_file = PartialWapmConfig::get_file_location() + .map_err(|e| anyhow::anyhow!("could not find config file {e}"))?; + let mut config = PartialWapmConfig::from_file().map_err(|e| { + anyhow::anyhow!( + "could not find config file {e} at {}", + config_file.display() + ) + })?; + + match s { + StorableConfigField::RegistryUrl(s) => { + config.registry.set_current_registry(&s.url); + let current_registry = config.registry.get_current_registry(); + if let Some(u) = wasmer_registry::utils::get_username().ok().and_then(|o| o) + { + println!("Successfully logged into registry {current_registry:?} as user {u:?}"); + } + } + StorableConfigField::RegistryToken(t) => { + config.registry.set_login_token_for_registry( + &config.registry.get_current_registry(), + &t.token, + wasmer_registry::config::UpdateRegistry::LeaveAsIs, + ); + } + StorableConfigField::TelemetryEnabled(t) => { + config.telemetry.enabled = format!("{:?}", t.enabled); + } + StorableConfigField::ProxyUrl(p) => { + config.proxy.url = p.url.clone(); + } + StorableConfigField::UpdateNotificationsEnabled(u) => { + config.update_notifications.enabled = format!("{:?}", u.enabled); + } } - }, + + config + .save(config_file) + .with_context(|| anyhow::anyhow!("could not save config file"))?; + } } Ok(()) } From 11f6c430cb5163af2a6801e8ad233f3aca703e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Dec 2022 20:41:15 +0100 Subject: [PATCH 03/32] PartialWapmConfig -> WasmerConfig --- lib/cli/src/commands/add.rs | 4 ++-- lib/cli/src/commands/config.rs | 6 +++--- lib/registry/src/config.rs | 4 ++-- lib/registry/src/lib.rs | 14 +++++++------- lib/registry/src/login.rs | 10 +++++----- lib/registry/src/package.rs | 6 +++--- lib/registry/src/utils.rs | 6 +++--- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/cli/src/commands/add.rs b/lib/cli/src/commands/add.rs index fc1395c5ca5..b8899341782 100644 --- a/lib/cli/src/commands/add.rs +++ b/lib/cli/src/commands/add.rs @@ -2,7 +2,7 @@ use std::process::{Command, Stdio}; use anyhow::{Context, Error}; use clap::Parser; -use wasmer_registry::{Bindings, PartialWapmConfig, ProgrammingLanguage}; +use wasmer_registry::{Bindings, WasmerConfig, ProgrammingLanguage}; /// Add a WAPM package's bindings to your application. #[derive(Debug, Parser)] @@ -76,7 +76,7 @@ impl Add { match &self.registry { Some(r) => Ok(r.clone()), None => { - let cfg = PartialWapmConfig::from_file() + let cfg = WasmerConfig::from_file() .map_err(Error::msg) .context("Unable to load WAPM's config file")?; Ok(cfg.registry.get_current_registry()) diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index d272f539191..c1db15b0a3d 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -3,7 +3,7 @@ use anyhow::{Context, Result}; use clap::Parser; use std::env; use std::path::PathBuf; -use wasmer_registry::PartialWapmConfig; +use wasmer_registry::WasmerConfig; #[derive(Debug, Parser)] /// The options for the `wasmer config` subcommand: `wasmer config get prefix` @@ -159,9 +159,9 @@ impl Config { } }, Set(s) => { - let config_file = PartialWapmConfig::get_file_location() + let config_file = WasmerConfig::get_file_location() .map_err(|e| anyhow::anyhow!("could not find config file {e}"))?; - let mut config = PartialWapmConfig::from_file().map_err(|e| { + let mut config = WasmerConfig::from_file().map_err(|e| { anyhow::anyhow!( "could not find config file {e} at {}", config_file.display() diff --git a/lib/registry/src/config.rs b/lib/registry/src/config.rs index 422da94b4e4..89440cf6bbd 100644 --- a/lib/registry/src/config.rs +++ b/lib/registry/src/config.rs @@ -5,7 +5,7 @@ use std::collections::BTreeMap; use std::path::{Path, PathBuf}; #[derive(Deserialize, Default, Serialize, Debug, PartialEq, Eq)] -pub struct PartialWapmConfig { +pub struct WasmerConfig { /// The number of seconds to wait before checking the registry for a new /// version of the package. #[serde(default = "wax_default_cooldown")] @@ -235,7 +235,7 @@ impl Registries { } } -impl PartialWapmConfig { +impl WasmerConfig { /// Save the config to a file pub fn save>(&self, to: P) -> anyhow::Result<()> { use std::{fs::File, io::Write}; diff --git a/lib/registry/src/lib.rs b/lib/registry/src/lib.rs index 4a7c18a2fe0..be71c1fb364 100644 --- a/lib/registry/src/lib.rs +++ b/lib/registry/src/lib.rs @@ -26,7 +26,7 @@ pub mod queries; pub mod utils; pub use crate::{ - config::{format_graphql, PartialWapmConfig}, + config::{format_graphql, WasmerConfig}, package::Package, queries::get_bindings_query::ProgrammingLanguage, }; @@ -395,11 +395,11 @@ pub fn query_package_from_registry( pub fn get_wasmer_root_dir(#[cfg(test)] test_name: &str) -> Option { #[cfg(test)] { - PartialWapmConfig::get_folder(test_name).ok() + WasmerConfig::get_folder(test_name).ok() } #[cfg(not(test))] { - PartialWapmConfig::get_folder().ok() + WasmerConfig::get_folder().ok() } } @@ -607,9 +607,9 @@ pub fn whoami( use graphql_client::GraphQLQuery; #[cfg(test)] - let config = PartialWapmConfig::from_file(test_name); + let config = WasmerConfig::from_file(test_name); #[cfg(not(test))] - let config = PartialWapmConfig::from_file(); + let config = WasmerConfig::from_file(); let config = config .map_err(|e| anyhow::anyhow!("{e}")) @@ -659,9 +659,9 @@ pub fn test_if_registry_present(registry: &str) -> Result { pub fn get_all_available_registries(#[cfg(test)] test_name: &str) -> Result, String> { #[cfg(test)] - let config = PartialWapmConfig::from_file(test_name)?; + let config = WasmerConfig::from_file(test_name)?; #[cfg(not(test))] - let config = PartialWapmConfig::from_file()?; + let config = WasmerConfig::from_file()?; let mut registries = Vec::new(); match config.registry { diff --git a/lib/registry/src/login.rs b/lib/registry/src/login.rs index f5df8d82c69..e5a9486008e 100644 --- a/lib/registry/src/login.rs +++ b/lib/registry/src/login.rs @@ -1,5 +1,5 @@ use crate::config::{format_graphql, UpdateRegistry}; -use crate::PartialWapmConfig; +use crate::WasmerConfig; /// Login to a registry and save the token associated with it. /// @@ -11,11 +11,11 @@ pub fn login_and_save_token( ) -> Result, anyhow::Error> { let registry = format_graphql(registry); #[cfg(test)] - let mut config = PartialWapmConfig::from_file(test_name) + let mut config = WasmerConfig::from_file(test_name) .map_err(|e| anyhow::anyhow!("config from file: {e}"))?; #[cfg(not(test))] let mut config = - PartialWapmConfig::from_file().map_err(|e| anyhow::anyhow!("config from file: {e}"))?; + WasmerConfig::from_file().map_err(|e| anyhow::anyhow!("config from file: {e}"))?; config.registry.set_current_registry(®istry); config.registry.set_login_token_for_registry( &config.registry.get_current_registry(), @@ -23,10 +23,10 @@ pub fn login_and_save_token( UpdateRegistry::Update, ); #[cfg(test)] - let path = PartialWapmConfig::get_file_location(test_name) + let path = WasmerConfig::get_file_location(test_name) .map_err(|e| anyhow::anyhow!("get file location: {e}"))?; #[cfg(not(test))] - let path = PartialWapmConfig::get_file_location() + let path = WasmerConfig::get_file_location() .map_err(|e| anyhow::anyhow!("get file location: {e}"))?; config.save(&path)?; crate::utils::get_username_registry_token(®istry, token) diff --git a/lib/registry/src/package.rs b/lib/registry/src/package.rs index d73007bed25..e7c51a15efa 100644 --- a/lib/registry/src/package.rs +++ b/lib/registry/src/package.rs @@ -1,4 +1,4 @@ -use crate::PartialWapmConfig; +use crate::WasmerConfig; use std::path::PathBuf; use std::{fmt, str::FromStr}; use url::Url; @@ -118,10 +118,10 @@ impl Package { /// Returns the full URL including the version for this package pub fn url(&self, #[cfg(test)] test_name: &str) -> Result { #[cfg(test)] - let config = PartialWapmConfig::from_file(test_name) + let config = WasmerConfig::from_file(test_name) .map_err(|e| anyhow::anyhow!("could not read wapm config: {e}"))?; #[cfg(not(test))] - let config = PartialWapmConfig::from_file() + let config = WasmerConfig::from_file() .map_err(|e| anyhow::anyhow!("could not read wapm config: {e}"))?; let registry = config.registry.get_current_registry(); let registry_tld = tldextract::TldExtractor::new(tldextract::TldOption::default()) diff --git a/lib/registry/src/utils.rs b/lib/registry/src/utils.rs index e6185a32641..7b2ec5e5efc 100644 --- a/lib/registry/src/utils.rs +++ b/lib/registry/src/utils.rs @@ -1,4 +1,4 @@ -use crate::{graphql::execute_query, PartialWapmConfig}; +use crate::{graphql::execute_query, WasmerConfig}; use graphql_client::GraphQLQuery; #[derive(GraphQLQuery)] @@ -11,9 +11,9 @@ struct WhoAmIQuery; pub fn get_username(#[cfg(test)] test_name: &str) -> anyhow::Result> { #[cfg(test)] - let config = PartialWapmConfig::from_file(test_name).map_err(|e| anyhow::anyhow!("{e}"))?; + let config = WasmerConfig::from_file(test_name).map_err(|e| anyhow::anyhow!("{e}"))?; #[cfg(not(test))] - let config = PartialWapmConfig::from_file().map_err(|e| anyhow::anyhow!("{e}"))?; + let config = WasmerConfig::from_file().map_err(|e| anyhow::anyhow!("{e}"))?; let registry = &config.registry.get_current_registry(); let q = WhoAmIQuery::build_query(who_am_i_query::Variables {}); let response: who_am_i_query::ResponseData = execute_query(registry, "", &q)?; From 1076ff25b6894ef0c6f75a43ea9f3d1a69ba74a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Dec 2022 21:53:34 +0100 Subject: [PATCH 04/32] Add integration tests --- lib/cli/src/commands/add.rs | 2 +- lib/cli/src/commands/config.rs | 50 +++++++++++++++++++ lib/registry/src/login.rs | 8 +-- tests/integration/cli/tests/config.rs | 72 +++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 tests/integration/cli/tests/config.rs diff --git a/lib/cli/src/commands/add.rs b/lib/cli/src/commands/add.rs index b8899341782..dce5191a6cf 100644 --- a/lib/cli/src/commands/add.rs +++ b/lib/cli/src/commands/add.rs @@ -2,7 +2,7 @@ use std::process::{Command, Stdio}; use anyhow::{Context, Error}; use clap::Parser; -use wasmer_registry::{Bindings, WasmerConfig, ProgrammingLanguage}; +use wasmer_registry::{Bindings, ProgrammingLanguage, WasmerConfig}; /// Add a WAPM package's bindings to your application. #[derive(Debug, Parser)] diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index c1db15b0a3d..c8a049519c5 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -33,6 +33,21 @@ pub enum RetrievableConfigField { Cflags, /// `pkg-config` PkgConfig, + /// `registry.url` + #[clap(name = "registry.url")] + RegistryUrl, + /// `registry.token` + #[clap(name = "registry.token")] + RegistryToken, + /// `telemetry.enabled` + #[clap(name = "telemetry.enabled")] + TelemetryEnabled, + /// `update-notifications.url` + #[clap(name = "update-notifications.enabled")] + UpdateNotificationsEnabled, + /// `proxy.url` + #[clap(name = "proxy.url")] + ProxyUrl, } /// Setting that can be stored in the wasmer config @@ -157,6 +172,41 @@ impl Config { RetrievableConfigField::Cflags => { println!("{}", cflags); } + other => { + let config = WasmerConfig::from_file() + .map_err(|e| anyhow::anyhow!("could not find config file: {e}"))?; + match other { + RetrievableConfigField::RegistryUrl => { + println!("{}", config.registry.get_current_registry()); + } + RetrievableConfigField::RegistryToken => { + if let Some(s) = config.registry.get_login_token_for_registry( + &config.registry.get_current_registry(), + ) { + println!("{s}"); + } + } + RetrievableConfigField::ProxyUrl => { + if let Some(s) = config.proxy.url.as_ref() { + println!("{s}"); + } + } + RetrievableConfigField::TelemetryEnabled => { + println!("{}", config.telemetry.enabled.to_string().replace('\"', "")); + } + RetrievableConfigField::UpdateNotificationsEnabled => { + println!( + "{}", + config + .update_notifications + .enabled + .to_string() + .replace('\"', "") + ); + } + _ => {} + } + } }, Set(s) => { let config_file = WasmerConfig::get_file_location() diff --git a/lib/registry/src/login.rs b/lib/registry/src/login.rs index e5a9486008e..35964b20bb5 100644 --- a/lib/registry/src/login.rs +++ b/lib/registry/src/login.rs @@ -11,8 +11,8 @@ pub fn login_and_save_token( ) -> Result, anyhow::Error> { let registry = format_graphql(registry); #[cfg(test)] - let mut config = WasmerConfig::from_file(test_name) - .map_err(|e| anyhow::anyhow!("config from file: {e}"))?; + let mut config = + WasmerConfig::from_file(test_name).map_err(|e| anyhow::anyhow!("config from file: {e}"))?; #[cfg(not(test))] let mut config = WasmerConfig::from_file().map_err(|e| anyhow::anyhow!("config from file: {e}"))?; @@ -26,8 +26,8 @@ pub fn login_and_save_token( let path = WasmerConfig::get_file_location(test_name) .map_err(|e| anyhow::anyhow!("get file location: {e}"))?; #[cfg(not(test))] - let path = WasmerConfig::get_file_location() - .map_err(|e| anyhow::anyhow!("get file location: {e}"))?; + let path = + WasmerConfig::get_file_location().map_err(|e| anyhow::anyhow!("get file location: {e}"))?; config.save(&path)?; crate::utils::get_username_registry_token(®istry, token) } diff --git a/tests/integration/cli/tests/config.rs b/tests/integration/cli/tests/config.rs new file mode 100644 index 00000000000..9d65efde89a --- /dev/null +++ b/tests/integration/cli/tests/config.rs @@ -0,0 +1,72 @@ +use anyhow::bail; +use std::path::PathBuf; +use std::process::Command; +use wasmer_integration_tests_cli::get_wasmer_path; + +#[test] +fn config_works() -> anyhow::Result<()> { + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("registry.url") + .output()?; + + assert!(output.status.success()); + + let registry_url = std::str::from_utf8(&output.stdout) + .expect("stdout is not utf8! need to handle arbitrary bytes"); + + println!("registry url {}", registry_url); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("set") + .arg("registry.url") + .arg("wapm.io") + .output()?; + + assert!(output.status.success()); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("set") + .arg("registry.url") + .arg(registry_url) + .output()?; + + assert!(output.status.success()); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("telemetry.enabled") + .output()?; + + assert!(output.status.success()); + + let telemetry_enabled = std::str::from_utf8(&output.stdout) + .expect("stdout is not utf8! need to handle arbitrary bytes") + .trim(); + + println!("telemetry enabled {}", telemetry_enabled); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("set") + .arg("telemetry.enabled") + .arg("false") + .output()?; + + assert!(output.status.success()); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("set") + .arg("telemetry.enabled") + .arg(telemetry_enabled) + .output()?; + + assert!(output.status.success()); + + Ok(()) +} From 1013fe6a69532c46b0f761fe4e89a482a0a8352b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Dec 2022 21:57:42 +0100 Subject: [PATCH 05/32] Fix make lint --- lib/cli/src/commands/config.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index c8a049519c5..0d786655530 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -192,17 +192,10 @@ impl Config { } } RetrievableConfigField::TelemetryEnabled => { - println!("{}", config.telemetry.enabled.to_string().replace('\"', "")); + println!("{}", config.telemetry.enabled.replace('\"', "")); } RetrievableConfigField::UpdateNotificationsEnabled => { - println!( - "{}", - config - .update_notifications - .enabled - .to_string() - .replace('\"', "") - ); + println!("{}", config.update_notifications.enabled.replace('\"', "")); } _ => {} } From 43cde31978ecd770e622a29086277098f699a475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Dec 2022 06:31:55 +0100 Subject: [PATCH 06/32] Add proper defaults for Telemetry and UpdateNotifications --- lib/registry/src/config.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/registry/src/config.rs b/lib/registry/src/config.rs index 89440cf6bbd..54712c32183 100644 --- a/lib/registry/src/config.rs +++ b/lib/registry/src/config.rs @@ -36,16 +36,32 @@ pub struct Proxy { pub url: Option, } -#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Default)] +#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)] pub struct UpdateNotifications { pub enabled: String, } -#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Default)] +impl Default for UpdateNotifications { + fn default() -> Self { + UpdateNotifications { + enabled: "false".to_string(), + } + } +} + +#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)] pub struct Telemetry { pub enabled: String, } +impl Default for Telemetry { + fn default() -> Self { + Telemetry { + enabled: "false".to_string(), + } + } +} + #[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)] #[serde(untagged)] pub enum Registries { From 344d541d0274a3ffb9d3a15e8df1fd080f5fb807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Dec 2022 06:35:20 +0100 Subject: [PATCH 07/32] Fix make lint --- lib/registry/src/config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/registry/src/config.rs b/lib/registry/src/config.rs index 54712c32183..e43b6fb9b6f 100644 --- a/lib/registry/src/config.rs +++ b/lib/registry/src/config.rs @@ -45,7 +45,7 @@ impl Default for UpdateNotifications { fn default() -> Self { UpdateNotifications { enabled: "false".to_string(), - } + } } } @@ -58,7 +58,7 @@ impl Default for Telemetry { fn default() -> Self { Telemetry { enabled: "false".to_string(), - } + } } } From d311e272958ff81159d980072d98898254c83844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Dec 2022 09:36:13 +0100 Subject: [PATCH 08/32] Update bash scripts for new "config get" change --- Makefile | 2 +- lib/c-api/README.md | 20 ++++++++++---------- lib/c-api/examples/Makefile | 10 +++++----- lib/c-api/tests/Makefile | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 0123ebf7c97..15058ce36c5 100644 --- a/Makefile +++ b/Makefile @@ -749,7 +749,7 @@ install-capi-pkgconfig: install-pkgconfig: # Make sure WASMER_INSTALL_PREFIX is set during build unset WASMER_DIR; \ - if pc="$$(target/release/wasmer config --pkg-config 2>/dev/null)"; then \ + if pc="$$(target/release/wasmer config get pkg-config 2>/dev/null)"; then \ echo "$$pc" | install -Dm644 /dev/stdin "$(DESTDIR)"/lib/pkgconfig/wasmer.pc; \ else \ echo 1>&2 "WASMER_INSTALL_PREFIX was not set during build, not installing wasmer.pc"; \ diff --git a/lib/c-api/README.md b/lib/c-api/README.md index 2651ddbb1d5..bd63e1ba27b 100644 --- a/lib/c-api/README.md +++ b/lib/c-api/README.md @@ -148,48 +148,48 @@ $ make test-capi `wasmer config` output various configuration information needed to compile programs which use Wasmer. -### `wasmer config --pkg-config` +### `wasmer config get pkg-config` It outputs the necessary details for compiling and linking a program to Wasmer, using the `pkg-config` format: ```bash -$ wasmer config --pkg-config > $PKG_CONFIG_PATH/wasmer.pc +$ wasmer config get pkg-config > $PKG_CONFIG_PATH/wasmer.pc ``` -### `wasmer config --includedir` +### `wasmer config get includedir` Directory containing Wasmer headers: ```bash -$ wasmer config --includedir +$ wasmer config get includedir /users/myuser/.wasmer/include ``` -### `wasmer config --libdir` +### `wasmer config get libdir` Directory containing Wasmer libraries: ```bash -$ wasmer config --libdir +$ wasmer config get libdir /users/myuser/.wasmer/lib ``` -### `wasmer config --libs` +### `wasmer config get libs` Libraries needed to link against Wasmer components: ```bash -$ wasmer config --libs +$ wasmer config get libs -L/Users/myuser/.wasmer/lib -lwasmer ``` -### `wasmer config --cflags` +### `wasmer config get cflags` Headers needed to build against Wasmer components: ```bash -$ wasmer config --cflags +$ wasmer config get cflags -I/Users/myuser/.wasmer/include/wasmer ``` diff --git a/lib/c-api/examples/Makefile b/lib/c-api/examples/Makefile index 9bea95c12fc..506844f4b63 100644 --- a/lib/c-api/examples/Makefile +++ b/lib/c-api/examples/Makefile @@ -18,13 +18,13 @@ ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer)) MSVC_LDFLAGS:= "" MSVC_LDLIBS:= /LIBPATH:$(WASMER_DIR)/lib wasmer.dll.lib else - CFLAGS = -g -I $(ROOT_DIR)/ -I $(shell $(WASMER_DIR)/bin/wasmer config --includedir) - LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config --libdir) - LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config --libs) + CFLAGS = -g -I $(ROOT_DIR)/ -I $(shell $(WASMER_DIR)/bin/wasmer config get includedir) + LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config get libdir) + LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config get libs) - MSVC_CFLAGS:= /DEBUG /I $(ROOT_DIR)/ /I $(shell $(WASMER_DIR)/bin/wasmer config --includedir) + MSVC_CFLAGS:= /DEBUG /I $(ROOT_DIR)/ /I $(shell $(WASMER_DIR)/bin/wasmer config get includedir) MSVC_LDFLAGS:= "" - MSVC_LDLIBS:= /LIBPATH:$(shell $(WASMER_DIR)/bin/wasmer config --libs) wasmer.dll.lib + MSVC_LDLIBS:= /LIBPATH:$(shell $(WASMER_DIR)/bin/wasmer config get libs) wasmer.dll.lib endif $(info * CFLAGS: $(CFLAGS)) diff --git a/lib/c-api/tests/Makefile b/lib/c-api/tests/Makefile index 05c01037923..1b93fffa275 100644 --- a/lib/c-api/tests/Makefile +++ b/lib/c-api/tests/Makefile @@ -10,9 +10,9 @@ ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer)) LDFLAGS = -Wl,-rpath,$(WASMER_DIR)/lib LDLIBS = -L $(WASMER_DIR)/lib -lwasmer else - CFLAGS = -g -I $(ROOT_DIR)/wasm-c-api/include/ -I $(shell $(WASMER_DIR)/bin/wasmer config --includedir) - LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config --libdir) - LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config --libs) + CFLAGS = -g -I $(ROOT_DIR)/wasm-c-api/include/ -I $(shell $(WASMER_DIR)/bin/wasmer config get includedir) + LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config get libdir) + LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config get libs) endif From bd0db36ab733fa854decda595170e566ccfa7072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Dec 2022 19:15:30 +0100 Subject: [PATCH 09/32] Migrate from enabled: String to enabled: bool --- lib/cli/src/commands/config.rs | 48 +++++++++++++++++++++------------- lib/registry/src/config.rs | 24 +++-------------- 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index 0d786655530..6631f8bc486 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -3,6 +3,7 @@ use anyhow::{Context, Result}; use clap::Parser; use std::env; use std::path::PathBuf; +use std::str::ParseBoolError; use wasmer_registry::WasmerConfig; #[derive(Debug, Parser)] @@ -19,33 +20,33 @@ pub enum Config { /// Value that can be queried from the wasmer config #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, clap::Subcommand)] pub enum RetrievableConfigField { - /// `prefix` + /// Print the wasmer installation path (WASMER_DIR) Prefix, - /// `bin-dir` + /// Print the /bin directory where wasmer is installed Bindir, - /// `includedir` + /// Print the /include dir Includedir, - /// `libdir` + /// Print the /lib dir Libdir, - /// `libs` + /// Print the linker flags for linking to libwasmer Libs, - /// `cflags` + /// Print the compiler flags for linking to libwasmer Cflags, - /// `pkg-config` + /// Print the pkg-config configuration PkgConfig, - /// `registry.url` + /// Print the registry URL of the currently active registry #[clap(name = "registry.url")] RegistryUrl, - /// `registry.token` + /// Print the token for the currently active registry or nothing if not logged in #[clap(name = "registry.token")] RegistryToken, - /// `telemetry.enabled` + /// Print whether telemetry is currently enabled #[clap(name = "telemetry.enabled")] TelemetryEnabled, - /// `update-notifications.url` + /// Print whether update notifications are enabled #[clap(name = "update-notifications.enabled")] UpdateNotificationsEnabled, - /// `proxy.url` + /// Print the proxy URL #[clap(name = "proxy.url")] ProxyUrl, } @@ -91,7 +92,18 @@ pub struct SetRegistryToken { pub struct SetUpdateNotificationsEnabled { /// Whether to enable update notifications #[clap(name = "ENABLED", possible_values = ["true", "false"])] - pub enabled: String, + pub enabled: BoolString, +} + +/// "true" or "false" for handling input in the CLI +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub struct BoolString(pub bool); + +impl std::str::FromStr for BoolString { + type Err = ParseBoolError; + fn from_str(s: &str) -> Result { + Ok(Self(bool::from_str(s)?)) + } } /// Set if telemetry is enabled @@ -99,7 +111,7 @@ pub struct SetUpdateNotificationsEnabled { pub struct SetTelemetryEnabled { /// Whether to enable telemetry #[clap(name = "ENABLED", possible_values = ["true", "false"])] - pub enabled: String, + pub enabled: BoolString, } /// Set if a proxy URL should be used @@ -192,10 +204,10 @@ impl Config { } } RetrievableConfigField::TelemetryEnabled => { - println!("{}", config.telemetry.enabled.replace('\"', "")); + println!("{:?}", config.telemetry.enabled); } RetrievableConfigField::UpdateNotificationsEnabled => { - println!("{}", config.update_notifications.enabled.replace('\"', "")); + println!("{:?}", config.update_notifications.enabled); } _ => {} } @@ -228,13 +240,13 @@ impl Config { ); } StorableConfigField::TelemetryEnabled(t) => { - config.telemetry.enabled = format!("{:?}", t.enabled); + config.telemetry.enabled = t.enabled.0; } StorableConfigField::ProxyUrl(p) => { config.proxy.url = p.url.clone(); } StorableConfigField::UpdateNotificationsEnabled(u) => { - config.update_notifications.enabled = format!("{:?}", u.enabled); + config.update_notifications.enabled = u.enabled.0; } } diff --git a/lib/registry/src/config.rs b/lib/registry/src/config.rs index e43b6fb9b6f..c2dd781bc34 100644 --- a/lib/registry/src/config.rs +++ b/lib/registry/src/config.rs @@ -36,30 +36,14 @@ pub struct Proxy { pub url: Option, } -#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)] +#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Default)] pub struct UpdateNotifications { - pub enabled: String, -} - -impl Default for UpdateNotifications { - fn default() -> Self { - UpdateNotifications { - enabled: "false".to_string(), - } - } + pub enabled: bool, } -#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)] +#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Default)] pub struct Telemetry { - pub enabled: String, -} - -impl Default for Telemetry { - fn default() -> Self { - Telemetry { - enabled: "false".to_string(), - } - } + pub enabled: bool, } #[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)] From 32d04e8ddfd76e0f3cdafb88dcaa874c96b1b249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Dec 2022 19:37:49 +0100 Subject: [PATCH 10/32] Use BoolString for handling CLI flags --- lib/cli/src/commands/config.rs | 16 ++++++++++++---- lib/registry/src/config.rs | 23 ++++++----------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index 6631f8bc486..10bec63378f 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -34,6 +34,9 @@ pub enum RetrievableConfigField { Cflags, /// Print the pkg-config configuration PkgConfig, + /// Print the path to the configuration file + #[clap(name = "config.path")] + ConfigPath, /// Print the registry URL of the currently active registry #[clap(name = "registry.url")] RegistryUrl, @@ -184,6 +187,11 @@ impl Config { RetrievableConfigField::Cflags => { println!("{}", cflags); } + RetrievableConfigField::ConfigPath => { + let path = WasmerConfig::get_file_location() + .map_err(|e| anyhow::anyhow!("could not find config file: {e}"))?; + println!("{}", path.display()); + } other => { let config = WasmerConfig::from_file() .map_err(|e| anyhow::anyhow!("could not find config file: {e}"))?; @@ -204,10 +212,10 @@ impl Config { } } RetrievableConfigField::TelemetryEnabled => { - println!("{:?}", config.telemetry.enabled); + println!("{:?}", config.telemetry_enabled); } RetrievableConfigField::UpdateNotificationsEnabled => { - println!("{:?}", config.update_notifications.enabled); + println!("{:?}", config.update_notifications_enabled); } _ => {} } @@ -240,13 +248,13 @@ impl Config { ); } StorableConfigField::TelemetryEnabled(t) => { - config.telemetry.enabled = t.enabled.0; + config.telemetry_enabled = t.enabled.0; } StorableConfigField::ProxyUrl(p) => { config.proxy.url = p.url.clone(); } StorableConfigField::UpdateNotificationsEnabled(u) => { - config.update_notifications.enabled = u.enabled.0; + config.update_notifications_enabled = u.enabled.0; } } diff --git a/lib/registry/src/config.rs b/lib/registry/src/config.rs index c2dd781bc34..faff2d4c90a 100644 --- a/lib/registry/src/config.rs +++ b/lib/registry/src/config.rs @@ -1,6 +1,5 @@ use graphql_client::GraphQLQuery; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::path::{Path, PathBuf}; @@ -11,16 +10,16 @@ pub struct WasmerConfig { #[serde(default = "wax_default_cooldown")] pub wax_cooldown: i32, - /// The registry that wapm will connect to. - pub registry: Registries, - /// Whether or not telemetry is enabled. #[serde(default)] - pub telemetry: Telemetry, + pub telemetry_enabled: bool, /// Whether or not updated notifications are enabled. #[serde(default)] - pub update_notifications: UpdateNotifications, + pub update_notifications_enabled: bool, + + /// The registry that wapm will connect to. + pub registry: Registries, /// The proxy to use when connecting to the Internet. #[serde(default)] @@ -36,16 +35,6 @@ pub struct Proxy { pub url: Option, } -#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Default)] -pub struct UpdateNotifications { - pub enabled: bool, -} - -#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Default)] -pub struct Telemetry { - pub enabled: bool, -} - #[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)] #[serde(untagged)] pub enum Registries { From 0bdf5c62b13870bfb2334a5ef65afd20491a5b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Dec 2022 23:25:56 +0100 Subject: [PATCH 11/32] Implement wasmer config CLI handling properly Now supports --prefix and [get | set] subcommands --- lib/cli/src/cli.rs | 1 - lib/cli/src/commands/config.rs | 139 +++++++++++++++++++++----------- lib/cli/src/commands/publish.rs | 5 +- lib/registry/src/publish.rs | 10 +-- 4 files changed, 98 insertions(+), 57 deletions(-) diff --git a/lib/cli/src/cli.rs b/lib/cli/src/cli.rs index c3c918a010c..b9f6a55ab51 100644 --- a/lib/cli/src/cli.rs +++ b/lib/cli/src/cli.rs @@ -130,7 +130,6 @@ enum WasmerCLIOptions { /// Get various configuration information needed /// to compile programs which use Wasmer - #[clap(subcommand)] Config(Config), /// Update wasmer to the latest version diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index 10bec63378f..5429e9e8a90 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -8,7 +8,50 @@ use wasmer_registry::WasmerConfig; #[derive(Debug, Parser)] /// The options for the `wasmer config` subcommand: `wasmer config get prefix` -pub enum Config { +pub struct Config { + #[clap(flatten)] + flags: Flags, + /// Subcommand for `wasmer config get | set` + #[clap(subcommand)] + get_or_set: Option, +} + +/// Normal configuration +#[derive(Debug, Parser)] +pub struct Flags { + /// Print the installation prefix. + #[clap(long, conflicts_with = "pkg-config")] + prefix: bool, + + /// Directory containing Wasmer executables. + #[clap(long, conflicts_with = "pkg-config")] + bindir: bool, + + /// Directory containing Wasmer headers. + #[clap(long, conflicts_with = "pkg-config")] + includedir: bool, + + /// Directory containing Wasmer libraries. + #[clap(long, conflicts_with = "pkg-config")] + libdir: bool, + + /// Libraries needed to link against Wasmer components. + #[clap(long, conflicts_with = "pkg-config")] + libs: bool, + + /// C compiler flags for files that include Wasmer headers. + #[clap(long, conflicts_with = "pkg-config")] + cflags: bool, + + /// It outputs the necessary details for compiling + /// and linking a program to Wasmer, using the `pkg-config` format. + #[clap(long)] + pkg_config: bool, +} + +/// Subcommand for `wasmer config get | set` +#[derive(Debug, Clone, PartialEq, Parser)] +enum GetOrSet { /// Get a value from the current wasmer config #[clap(subcommand)] Get(RetrievableConfigField), @@ -18,22 +61,8 @@ pub enum Config { } /// Value that can be queried from the wasmer config -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, clap::Subcommand)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] pub enum RetrievableConfigField { - /// Print the wasmer installation path (WASMER_DIR) - Prefix, - /// Print the /bin directory where wasmer is installed - Bindir, - /// Print the /include dir - Includedir, - /// Print the /lib dir - Libdir, - /// Print the linker flags for linking to libwasmer - Libs, - /// Print the compiler flags for linking to libwasmer - Cflags, - /// Print the pkg-config configuration - PkgConfig, /// Print the path to the configuration file #[clap(name = "config.path")] ConfigPath, @@ -55,7 +84,7 @@ pub enum RetrievableConfigField { } /// Setting that can be stored in the wasmer config -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, clap::Subcommand)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] pub enum StorableConfigField { /// `registry.url` #[clap(name = "registry.url")] @@ -132,7 +161,11 @@ impl Config { .context("failed to retrieve the wasmer config".to_string()) } fn inner_execute(&self) -> Result<()> { - use self::Config::{Get, Set}; + if let Some(gs) = self.get_or_set.as_ref() { + return gs.execute(); + } + + let flags = &self.flags; let key = "WASMER_DIR"; let wasmer_dir = env::var(key) @@ -155,38 +188,47 @@ impl Config { let cflags = format!("-I{}", includedir); let libs = format!("-L{} -lwasmer", libdir); + if flags.pkg_config { + println!("prefix={}", prefixdir); + println!("exec_prefix={}", bindir); + println!("includedir={}", includedir); + println!("libdir={}", libdir); + println!(); + println!("Name: wasmer"); + println!("Description: The Wasmer library for running WebAssembly"); + println!("Version: {}", VERSION); + println!("Cflags: {}", cflags); + println!("Libs: {}", libs); + return Ok(()); + } + if flags.prefix { + println!("{}", prefixdir); + } + if flags.bindir { + println!("{}", bindir); + } + if flags.includedir { + println!("{}", includedir); + } + if flags.libdir { + println!("{}", libdir); + } + if flags.libs { + println!("{}", libs); + } + if flags.cflags { + println!("{}", cflags); + } + + Ok(()) + } +} + +impl GetOrSet { + fn execute(&self) -> Result<()> { + use self::GetOrSet::{Get, Set}; match self { Get(g) => match g { - RetrievableConfigField::PkgConfig => { - println!("prefix={}", prefixdir); - println!("exec_prefix={}", bindir); - println!("includedir={}", includedir); - println!("libdir={}", libdir); - println!(); - println!("Name: wasmer"); - println!("Description: The Wasmer library for running WebAssembly"); - println!("Version: {}", VERSION); - println!("Cflags: {}", cflags); - println!("Libs: {}", libs); - } - RetrievableConfigField::Prefix => { - println!("{}", prefixdir); - } - RetrievableConfigField::Bindir => { - println!("{}", bindir); - } - RetrievableConfigField::Includedir => { - println!("{}", includedir); - } - RetrievableConfigField::Libdir => { - println!("{}", libdir); - } - RetrievableConfigField::Libs => { - println!("{}", libs); - } - RetrievableConfigField::Cflags => { - println!("{}", cflags); - } RetrievableConfigField::ConfigPath => { let path = WasmerConfig::get_file_location() .map_err(|e| anyhow::anyhow!("could not find config file: {e}"))?; @@ -263,6 +305,7 @@ impl Config { .with_context(|| anyhow::anyhow!("could not save config file"))?; } } + Ok(()) } } diff --git a/lib/cli/src/commands/publish.rs b/lib/cli/src/commands/publish.rs index cc72be9edc1..a73c46efd35 100644 --- a/lib/cli/src/commands/publish.rs +++ b/lib/cli/src/commands/publish.rs @@ -10,7 +10,7 @@ use thiserror::Error; use time::{self, OffsetDateTime}; use wasmer_registry::publish::SignArchiveResult; use wasmer_registry::Package; -use wasmer_registry::PartialWapmConfig; +use wasmer_registry::WasmerConfig; const CURRENT_DATA_VERSION: i32 = 3; @@ -342,8 +342,7 @@ pub fn sign_compressed_archive( /// Opens an exclusive read/write connection to the database, creating it if it does not exist pub fn open_db() -> anyhow::Result { - let db_path = - PartialWapmConfig::get_database_file_path().map_err(|e| anyhow::anyhow!("{e}"))?; + let db_path = WasmerConfig::get_database_file_path().map_err(|e| anyhow::anyhow!("{e}"))?; let mut conn = Connection::open_with_flags( db_path, OpenFlags::SQLITE_OPEN_CREATE diff --git a/lib/registry/src/publish.rs b/lib/registry/src/publish.rs index 6c67405ec12..2ac8b68ba0c 100644 --- a/lib/registry/src/publish.rs +++ b/lib/registry/src/publish.rs @@ -1,6 +1,6 @@ use crate::graphql::{execute_query_modifier_inner, get_signed_url, GetSignedUrl}; use crate::graphql::{publish_package_mutation_chunked, PublishPackageMutationChunked}; -use crate::{format_graphql, PartialWapmConfig}; +use crate::{format_graphql, WasmerConfig}; use console::{style, Emoji}; use graphql_client::GraphQLQuery; use indicatif::{ProgressBar, ProgressState, ProgressStyle}; @@ -40,9 +40,9 @@ pub fn try_chunked_uploading( Some(s) => format_graphql(s), None => { #[cfg(not(test))] - let config = PartialWapmConfig::from_file(); + let config = WasmerConfig::from_file(); #[cfg(test)] - let config = PartialWapmConfig::from_file("publish"); + let config = WasmerConfig::from_file("publish"); config .map_err(|e| anyhow::anyhow!("{e}"))? @@ -55,9 +55,9 @@ pub fn try_chunked_uploading( Some(s) => s.to_string(), None => { #[cfg(not(test))] - let config = PartialWapmConfig::from_file(); + let config = WasmerConfig::from_file(); #[cfg(test)] - let config = PartialWapmConfig::from_file("publish"); + let config = WasmerConfig::from_file("publish"); config .map_err(|e| anyhow::anyhow!("{e}"))? From 710b8242f1f770271c5ab0a132f2e152047cb7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Sun, 18 Dec 2022 15:20:55 +0100 Subject: [PATCH 12/32] Revert "Update bash scripts for new "config get" change" This reverts commit d311e272958ff81159d980072d98898254c83844. --- Makefile | 2 +- lib/c-api/README.md | 20 ++++++++++---------- lib/c-api/examples/Makefile | 10 +++++----- lib/c-api/tests/Makefile | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index ca639b3b2da..55a2bc43234 100644 --- a/Makefile +++ b/Makefile @@ -750,7 +750,7 @@ install-capi-pkgconfig: install-pkgconfig: # Make sure WASMER_INSTALL_PREFIX is set during build unset WASMER_DIR; \ - if pc="$$(target/release/wasmer config get pkg-config 2>/dev/null)"; then \ + if pc="$$(target/release/wasmer config --pkg-config 2>/dev/null)"; then \ echo "$$pc" | install -Dm644 /dev/stdin "$(DESTDIR)"/lib/pkgconfig/wasmer.pc; \ else \ echo 1>&2 "WASMER_INSTALL_PREFIX was not set during build, not installing wasmer.pc"; \ diff --git a/lib/c-api/README.md b/lib/c-api/README.md index bd63e1ba27b..2651ddbb1d5 100644 --- a/lib/c-api/README.md +++ b/lib/c-api/README.md @@ -148,48 +148,48 @@ $ make test-capi `wasmer config` output various configuration information needed to compile programs which use Wasmer. -### `wasmer config get pkg-config` +### `wasmer config --pkg-config` It outputs the necessary details for compiling and linking a program to Wasmer, using the `pkg-config` format: ```bash -$ wasmer config get pkg-config > $PKG_CONFIG_PATH/wasmer.pc +$ wasmer config --pkg-config > $PKG_CONFIG_PATH/wasmer.pc ``` -### `wasmer config get includedir` +### `wasmer config --includedir` Directory containing Wasmer headers: ```bash -$ wasmer config get includedir +$ wasmer config --includedir /users/myuser/.wasmer/include ``` -### `wasmer config get libdir` +### `wasmer config --libdir` Directory containing Wasmer libraries: ```bash -$ wasmer config get libdir +$ wasmer config --libdir /users/myuser/.wasmer/lib ``` -### `wasmer config get libs` +### `wasmer config --libs` Libraries needed to link against Wasmer components: ```bash -$ wasmer config get libs +$ wasmer config --libs -L/Users/myuser/.wasmer/lib -lwasmer ``` -### `wasmer config get cflags` +### `wasmer config --cflags` Headers needed to build against Wasmer components: ```bash -$ wasmer config get cflags +$ wasmer config --cflags -I/Users/myuser/.wasmer/include/wasmer ``` diff --git a/lib/c-api/examples/Makefile b/lib/c-api/examples/Makefile index 506844f4b63..9bea95c12fc 100644 --- a/lib/c-api/examples/Makefile +++ b/lib/c-api/examples/Makefile @@ -18,13 +18,13 @@ ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer)) MSVC_LDFLAGS:= "" MSVC_LDLIBS:= /LIBPATH:$(WASMER_DIR)/lib wasmer.dll.lib else - CFLAGS = -g -I $(ROOT_DIR)/ -I $(shell $(WASMER_DIR)/bin/wasmer config get includedir) - LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config get libdir) - LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config get libs) + CFLAGS = -g -I $(ROOT_DIR)/ -I $(shell $(WASMER_DIR)/bin/wasmer config --includedir) + LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config --libdir) + LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config --libs) - MSVC_CFLAGS:= /DEBUG /I $(ROOT_DIR)/ /I $(shell $(WASMER_DIR)/bin/wasmer config get includedir) + MSVC_CFLAGS:= /DEBUG /I $(ROOT_DIR)/ /I $(shell $(WASMER_DIR)/bin/wasmer config --includedir) MSVC_LDFLAGS:= "" - MSVC_LDLIBS:= /LIBPATH:$(shell $(WASMER_DIR)/bin/wasmer config get libs) wasmer.dll.lib + MSVC_LDLIBS:= /LIBPATH:$(shell $(WASMER_DIR)/bin/wasmer config --libs) wasmer.dll.lib endif $(info * CFLAGS: $(CFLAGS)) diff --git a/lib/c-api/tests/Makefile b/lib/c-api/tests/Makefile index 1b93fffa275..05c01037923 100644 --- a/lib/c-api/tests/Makefile +++ b/lib/c-api/tests/Makefile @@ -10,9 +10,9 @@ ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer)) LDFLAGS = -Wl,-rpath,$(WASMER_DIR)/lib LDLIBS = -L $(WASMER_DIR)/lib -lwasmer else - CFLAGS = -g -I $(ROOT_DIR)/wasm-c-api/include/ -I $(shell $(WASMER_DIR)/bin/wasmer config get includedir) - LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config get libdir) - LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config get libs) + CFLAGS = -g -I $(ROOT_DIR)/wasm-c-api/include/ -I $(shell $(WASMER_DIR)/bin/wasmer config --includedir) + LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config --libdir) + LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config --libs) endif From a058f8e105f078fa888ef180a210b160cf2228b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Sun, 18 Dec 2022 15:44:31 +0100 Subject: [PATCH 13/32] Delete publish.rs file --- lib/cli/src/commands/publish.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lib/cli/src/commands/publish.rs diff --git a/lib/cli/src/commands/publish.rs b/lib/cli/src/commands/publish.rs deleted file mode 100644 index e69de29bb2d..00000000000 From 88d4f1f0b85a770c8e768070afa1e7cf74d35398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Sun, 18 Dec 2022 16:40:13 +0100 Subject: [PATCH 14/32] Add more integration tests --- tests/integration/cli/tests/config.rs | 126 +++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 1 deletion(-) diff --git a/tests/integration/cli/tests/config.rs b/tests/integration/cli/tests/config.rs index 9d65efde89a..5f4b5ca5b4a 100644 --- a/tests/integration/cli/tests/config.rs +++ b/tests/integration/cli/tests/config.rs @@ -1,10 +1,134 @@ use anyhow::bail; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::Command; use wasmer_integration_tests_cli::get_wasmer_path; #[test] fn config_works() -> anyhow::Result<()> { + let bindir = Command::new(get_wasmer_path()) + .arg("config") + .arg("--bindir") + .output()?; + + let bin_path = Path::new(env!("WASMER_DIR")).join("bin"); + assert_eq!( + String::from_utf8(bindir.stdout).unwrap(), + format!("{}\n", bin_path.display()) + ); + + let bindir = Command::new(get_wasmer_path()) + .arg("config") + .arg("--cflags") + .output()?; + + let include_path = Path::new(env!("WASMER_DIR")).join("include"); + assert_eq!( + String::from_utf8(bindir.stdout).unwrap(), + format!("-I{}\n", include_path.display()) + ); + + let bindir = Command::new(get_wasmer_path()) + .arg("config") + .arg("--includedir") + .output()?; + + let include_path = Path::new(env!("WASMER_DIR")).join("include"); + assert_eq!( + String::from_utf8(bindir.stdout).unwrap(), + format!("{}\n", include_path.display()) + ); + + let bindir = Command::new(get_wasmer_path()) + .arg("config") + .arg("--libdir") + .output()?; + + let lib_path = Path::new(env!("WASMER_DIR")).join("lib"); + assert_eq!( + String::from_utf8(bindir.stdout).unwrap(), + format!("{}\n", lib_path.display()) + ); + + let bindir = Command::new(get_wasmer_path()) + .arg("config") + .arg("--libs") + .output()?; + + let lib_path = Path::new(env!("WASMER_DIR")).join("lib"); + assert_eq!( + String::from_utf8(bindir.stdout).unwrap(), + format!("-L{} -lwasmer\n", lib_path.display()) + ); + + let bindir = Command::new(get_wasmer_path()) + .arg("config") + .arg("--prefix") + .output()?; + + let wasmer_dir = Path::new(env!("WASMER_DIR")); + assert_eq!( + String::from_utf8(bindir.stdout).unwrap(), + format!("{}\n", wasmer_dir.display()) + ); + + let bindir = Command::new(get_wasmer_path()) + .arg("config") + .arg("--pkg-config") + .output()?; + + let bin_path = format!("{}", bin_path.display()); + let include_path = format!("{}", include_path.display()); + let lib_path = format!("{}", lib_path.display()); + let wasmer_dir = format!("{}", wasmer_dir.display()); + + let args = vec![ + format!("prefix={wasmer_dir}"), + format!("exec_prefix={bin_path}"), + format!("includedir={include_path}"), + format!("libdir={lib_path}"), + format!(""), + format!("Name: wasmer"), + format!("Description: The Wasmer library for running WebAssembly"), + format!("Version: {}", env!("CARGO_PKG_VERSION")), + format!("Cflags: -I{include_path}"), + format!("Libs: -L{lib_path} -lwasmer"), + ]; + + let wasmer_dir = Path::new(env!("WASMER_DIR")); + let lines = String::from_utf8(bindir.stdout) + .unwrap() + .lines() + .map(|s| s.trim().to_string()) + .collect::>(); + + assert_eq!(lines, args); + + // ---- config get + + /* + config get + + config.path Print the path to the configuration file + proxy.url Print the proxy URL + registry.token Print the token for the currently active registry or nothing + if not logged in + registry.url Print the registry URL of the currently active registry + telemetry.enabled Print whether telemetry is currently enabled + update-notifications.enabled Print whether update notifications are enabled + */ + + // ---- config set + + /* + config set + + proxy.url `proxy.url` + registry.token `registry.token` + registry.url `registry.url` + telemetry.enabled `telemetry.enabled` + update-notifications.enabled `update-notifications.url` + */ + let output = Command::new(get_wasmer_path()) .arg("config") .arg("get") From f1aa1d5f536573cd1ba8c5bc6dcaeeeddae27673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Dec 2022 07:56:45 +0100 Subject: [PATCH 15/32] Add integration tests for all wasmer config flags --- lib/registry/src/lib.rs | 2 +- lib/registry/src/package.rs | 1 - tests/integration/cli/tests/config.rs | 196 +++++++++++++++++++++----- 3 files changed, 158 insertions(+), 41 deletions(-) diff --git a/lib/registry/src/lib.rs b/lib/registry/src/lib.rs index be71c1fb364..07e0a81c354 100644 --- a/lib/registry/src/lib.rs +++ b/lib/registry/src/lib.rs @@ -31,7 +31,7 @@ pub use crate::{ queries::get_bindings_query::ProgrammingLanguage, }; -pub static GLOBAL_CONFIG_FILE_NAME: &str = "wapm.toml"; +pub static GLOBAL_CONFIG_FILE_NAME: &str = "wasmer.toml"; #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord)] pub struct PackageDownloadInfo { diff --git a/lib/registry/src/package.rs b/lib/registry/src/package.rs index 569199c03a4..e7c51a15efa 100644 --- a/lib/registry/src/package.rs +++ b/lib/registry/src/package.rs @@ -1,5 +1,4 @@ use crate::WasmerConfig; -use regex::Regex; use std::path::PathBuf; use std::{fmt, str::FromStr}; use url::Url; diff --git a/tests/integration/cli/tests/config.rs b/tests/integration/cli/tests/config.rs index 5f4b5ca5b4a..aaefdab4e9d 100644 --- a/tests/integration/cli/tests/config.rs +++ b/tests/integration/cli/tests/config.rs @@ -94,7 +94,6 @@ fn config_works() -> anyhow::Result<()> { format!("Libs: -L{lib_path} -lwasmer"), ]; - let wasmer_dir = Path::new(env!("WASMER_DIR")); let lines = String::from_utf8(bindir.stdout) .unwrap() .lines() @@ -105,92 +104,211 @@ fn config_works() -> anyhow::Result<()> { // ---- config get - /* - config get + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("config.path") + .output()?; - config.path Print the path to the configuration file - proxy.url Print the proxy URL - registry.token Print the token for the currently active registry or nothing - if not logged in - registry.url Print the registry URL of the currently active registry - telemetry.enabled Print whether telemetry is currently enabled - update-notifications.enabled Print whether update notifications are enabled - */ + let config_path = Path::new(env!("WASMER_DIR")).join("wasmer.toml"); + assert_eq!( + String::from_utf8_lossy(&output.stdout), + format!("{}\n", config_path.display()) + ); - // ---- config set + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("registry.token") + .output()?; - /* - config set + let original_token = String::from_utf8_lossy(&output.stdout); - proxy.url `proxy.url` - registry.token `registry.token` - registry.url `registry.url` - telemetry.enabled `telemetry.enabled` - update-notifications.enabled `update-notifications.url` - */ + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("set") + .arg("registry.token") + .arg("abc123") + .output()?; + + assert_eq!(String::from_utf8_lossy(&output.stdout), "".to_string()); let output = Command::new(get_wasmer_path()) .arg("config") .arg("get") - .arg("registry.url") + .arg("registry.token") + .output()?; + + assert_eq!( + String::from_utf8_lossy(&output.stdout), + "abc123\n".to_string() + ); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("set") + .arg("registry.token") + .arg(original_token.to_string().trim()) + .output()?; + + assert_eq!(String::from_utf8_lossy(&output.stdout), "".to_string()); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("registry.token") .output()?; - assert!(output.status.success()); + assert_eq!( + String::from_utf8_lossy(&output.stdout), + format!("{}\n", original_token.to_string().trim().to_string()) + ); - let registry_url = std::str::from_utf8(&output.stdout) - .expect("stdout is not utf8! need to handle arbitrary bytes"); + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("registry.url") + .output()?; - println!("registry url {}", registry_url); + let original_url = String::from_utf8_lossy(&output.stdout); let output = Command::new(get_wasmer_path()) .arg("config") .arg("set") .arg("registry.url") - .arg("wapm.io") + .arg("wapm.dev") .output()?; - assert!(output.status.success()); + let output_str = String::from_utf8_lossy(&output.stdout); + + assert_eq!(output_str, "".to_string()); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("registry.url") + .output()?; + + let output_str = String::from_utf8_lossy(&output.stdout); + assert_eq!( + output_str, + "https://registry.wapm.dev/graphql\n".to_string() + ); let output = Command::new(get_wasmer_path()) .arg("config") .arg("set") .arg("registry.url") - .arg(registry_url) + .arg(original_url.to_string().trim()) .output()?; - assert!(output.status.success()); + let output_str = String::from_utf8_lossy(&output.stdout); + assert_eq!(output_str, "".to_string()); let output = Command::new(get_wasmer_path()) .arg("config") .arg("get") - .arg("telemetry.enabled") + .arg("registry.url") .output()?; - assert!(output.status.success()); + let output_str = String::from_utf8_lossy(&output.stdout); + assert_eq!(output_str, original_url.to_string()); - let telemetry_enabled = std::str::from_utf8(&output.stdout) - .expect("stdout is not utf8! need to handle arbitrary bytes") - .trim(); + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("telemetry.enabled") + .output()?; - println!("telemetry enabled {}", telemetry_enabled); + let original_output = String::from_utf8_lossy(&output.stdout); let output = Command::new(get_wasmer_path()) .arg("config") .arg("set") .arg("telemetry.enabled") - .arg("false") + .arg("true") + .output()?; + + assert_eq!(String::from_utf8_lossy(&output.stdout), "".to_string()); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("telemetry.enabled") .output()?; - assert!(output.status.success()); + assert_eq!( + String::from_utf8_lossy(&output.stdout), + "true\n".to_string() + ); let output = Command::new(get_wasmer_path()) .arg("config") .arg("set") .arg("telemetry.enabled") - .arg(telemetry_enabled) + .arg(original_output.to_string().trim()) .output()?; - assert!(output.status.success()); + assert_eq!(String::from_utf8_lossy(&output.stdout), "".to_string()); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("telemetry.enabled") + .output()?; + + assert_eq!( + String::from_utf8_lossy(&output.stdout), + original_output.to_string() + ); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("update-notifications.enabled") + .output()?; + + let original_output = String::from_utf8_lossy(&output.stdout); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("set") + .arg("update-notifications.enabled") + .arg("true") + .output()?; + + assert_eq!(String::from_utf8_lossy(&output.stdout), "".to_string()); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("update-notifications.enabled") + .output()?; + + assert_eq!( + String::from_utf8_lossy(&output.stdout), + "true\n".to_string() + ); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("set") + .arg("update-notifications.enabled") + .arg(original_output.to_string().trim()) + .output()?; + + assert_eq!(String::from_utf8_lossy(&output.stdout), "".to_string()); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("update-notifications.enabled") + .output()?; + + assert_eq!( + String::from_utf8_lossy(&output.stdout), + original_output.to_string() + ); Ok(()) } From ca50d8218c19da7485014544606d187523ac8815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Dec 2022 08:00:41 +0100 Subject: [PATCH 16/32] Add test to check that --pkg-config conflicts with other flags --- tests/integration/cli/tests/config.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/integration/cli/tests/config.rs b/tests/integration/cli/tests/config.rs index aaefdab4e9d..6fb16770494 100644 --- a/tests/integration/cli/tests/config.rs +++ b/tests/integration/cli/tests/config.rs @@ -3,6 +3,32 @@ use std::path::{Path, PathBuf}; use std::process::Command; use wasmer_integration_tests_cli::get_wasmer_path; +#[test] +fn wasmer_config_error() -> anyhow::Result<()> { + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("--bindir") + .arg("--cflags") + .arg("--pkg-config") + .output()?; + + let lines = String::from_utf8_lossy(&output.stderr) + .lines() + .map(|s| s.trim().to_string()) + .collect::>(); + let expected = vec![ + "error: The argument '--bindir' cannot be used with '--pkg-config'", + "", + "USAGE:", + "wasmer config --bindir --cflags", + "", + "For more information try --help", + ]; + + assert_eq!(lines, expected); + + Ok(()) +} #[test] fn config_works() -> anyhow::Result<()> { let bindir = Command::new(get_wasmer_path()) From e96c31318b56f7648271b702fe272da8d3a47327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Dec 2022 08:08:47 +0100 Subject: [PATCH 17/32] Test multi-config wasmer config calls --- tests/integration/cli/tests/config.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/integration/cli/tests/config.rs b/tests/integration/cli/tests/config.rs index 6fb16770494..4f1968cf654 100644 --- a/tests/integration/cli/tests/config.rs +++ b/tests/integration/cli/tests/config.rs @@ -3,6 +3,32 @@ use std::path::{Path, PathBuf}; use std::process::Command; use wasmer_integration_tests_cli::get_wasmer_path; +#[test] +fn wasmer_config_multiget() -> anyhow::Result<()> { + let bin_path = Path::new(env!("WASMER_DIR")).join("bin"); + let include_path = Path::new(env!("WASMER_DIR")).join("include"); + + let bin = format!("{}", bin_path.display()); + let include = format!("-I{}", include_path.display()); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("--bindir") + .arg("--cflags") + .output()?; + + let lines = String::from_utf8_lossy(&output.stdout) + .lines() + .map(|s| s.trim().to_string()) + .collect::>(); + + let expected = vec![bin, include]; + + assert_eq!(lines, expected); + + Ok(()) +} + #[test] fn wasmer_config_error() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) From bc2f445d9dbec8f4d5358235e0c1b9a9a0766195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 20 Dec 2022 10:13:19 +0100 Subject: [PATCH 18/32] Update wasmer config for new --flag getters --- lib/cli/src/commands/config.rs | 220 +++++++++++++++------------------ 1 file changed, 103 insertions(+), 117 deletions(-) diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index 5429e9e8a90..97af94b9c50 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -7,13 +7,13 @@ use std::str::ParseBoolError; use wasmer_registry::WasmerConfig; #[derive(Debug, Parser)] -/// The options for the `wasmer config` subcommand: `wasmer config get prefix` +/// The options for the `wasmer config` subcommand: `wasmer config get --OPTION` or `wasmer config set [FLAG]` pub struct Config { #[clap(flatten)] flags: Flags, /// Subcommand for `wasmer config get | set` #[clap(subcommand)] - get_or_set: Option, + set: Option, } /// Normal configuration @@ -43,62 +43,52 @@ pub struct Flags { #[clap(long, conflicts_with = "pkg-config")] cflags: bool, - /// It outputs the necessary details for compiling - /// and linking a program to Wasmer, using the `pkg-config` format. - #[clap(long)] - pkg_config: bool, -} - -/// Subcommand for `wasmer config get | set` -#[derive(Debug, Clone, PartialEq, Parser)] -enum GetOrSet { - /// Get a value from the current wasmer config - #[clap(subcommand)] - Get(RetrievableConfigField), - /// Set a value in the current wasmer config - #[clap(subcommand)] - Set(StorableConfigField), -} + /// Print the path to the wasmer configuration file where all settings are stored + #[clap(long, conflicts_with = "pkg-config")] + config_path: bool, -/// Value that can be queried from the wasmer config -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] -pub enum RetrievableConfigField { - /// Print the path to the configuration file - #[clap(name = "config.path")] - ConfigPath, /// Print the registry URL of the currently active registry - #[clap(name = "registry.url")] - RegistryUrl, + #[clap(long, conflicts_with = "pkg-config")] + registry_url: bool, + /// Print the token for the currently active registry or nothing if not logged in - #[clap(name = "registry.token")] - RegistryToken, + #[clap(long, conflicts_with = "pkg-config")] + registry_token: bool, + /// Print whether telemetry is currently enabled - #[clap(name = "telemetry.enabled")] - TelemetryEnabled, + #[clap(long, conflicts_with = "pkg-config")] + telemetry_enabled: bool, + /// Print whether update notifications are enabled - #[clap(name = "update-notifications.enabled")] - UpdateNotificationsEnabled, + #[clap(long, conflicts_with = "pkg-config")] + update_notifications_enabled: bool, + /// Print the proxy URL - #[clap(name = "proxy.url")] - ProxyUrl, + #[clap(long, conflicts_with = "pkg-config")] + proxy_url: bool, + + /// Outputs the necessary details for compiling + /// and linking a program to Wasmer, using the `pkg-config` format. + #[clap(long)] + pkg_config: bool, } /// Setting that can be stored in the wasmer config #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] pub enum StorableConfigField { - /// `registry.url` + /// Print the registry URL of the currently active registry #[clap(name = "registry.url")] RegistryUrl(SetRegistryUrl), - /// `registry.token` + /// Print the token for the currently active registry or nothing if not logged in #[clap(name = "registry.token")] RegistryToken(SetRegistryToken), - /// `telemetry.enabled` + /// Print whether telemetry is currently enabled #[clap(name = "telemetry.enabled")] TelemetryEnabled(SetTelemetryEnabled), - /// `update-notifications.url` + /// Print whether update notifications are enabled #[clap(name = "update-notifications.enabled")] UpdateNotificationsEnabled(SetUpdateNotificationsEnabled), - /// `proxy.url` + /// Print the proxy URL #[clap(name = "proxy.url")] ProxyUrl(SetProxyUrl), } @@ -161,8 +151,8 @@ impl Config { .context("failed to retrieve the wasmer config".to_string()) } fn inner_execute(&self) -> Result<()> { - if let Some(gs) = self.get_or_set.as_ref() { - return gs.execute(); + if let Some(s) = self.set.as_ref() { + return s.execute(); } let flags = &self.flags; @@ -201,6 +191,7 @@ impl Config { println!("Libs: {}", libs); return Ok(()); } + if flags.prefix { println!("{}", prefixdir); } @@ -220,91 +211,86 @@ impl Config { println!("{}", cflags); } + if flags.config_path { + let path = WasmerConfig::get_file_location() + .map_err(|e| anyhow::anyhow!("could not find config file: {e}"))?; + println!("{}", path.display()); + } + + let config = WasmerConfig::from_file() + .map_err(|e| anyhow::anyhow!("could not find config file: {e}"))?; + + if flags.registry_url { + println!("{}", config.registry.get_current_registry()); + } + + if flags.registry_token { + if let Some(s) = config + .registry + .get_login_token_for_registry(&config.registry.get_current_registry()) + { + println!("{s}"); + } + } + + if flags.telemetry_enabled { + println!("{:?}", config.telemetry_enabled); + } + + if flags.update_notifications_enabled { + println!("{:?}", config.update_notifications_enabled); + } + + if flags.proxy_url { + if let Some(s) = config.proxy.url.as_ref() { + println!("{s}"); + } + } + Ok(()) } } -impl GetOrSet { +impl StorableConfigField { fn execute(&self) -> Result<()> { - use self::GetOrSet::{Get, Set}; + let config_file = WasmerConfig::get_file_location() + .map_err(|e| anyhow::anyhow!("could not find config file {e}"))?; + let mut config = WasmerConfig::from_file().map_err(|e| { + anyhow::anyhow!( + "could not find config file {e} at {}", + config_file.display() + ) + })?; match self { - Get(g) => match g { - RetrievableConfigField::ConfigPath => { - let path = WasmerConfig::get_file_location() - .map_err(|e| anyhow::anyhow!("could not find config file: {e}"))?; - println!("{}", path.display()); + StorableConfigField::RegistryUrl(s) => { + config.registry.set_current_registry(&s.url); + let current_registry = config.registry.get_current_registry(); + if let Some(u) = wasmer_registry::utils::get_username().ok().and_then(|o| o) { + println!( + "Successfully logged into registry {current_registry:?} as user {u:?}" + ); } - other => { - let config = WasmerConfig::from_file() - .map_err(|e| anyhow::anyhow!("could not find config file: {e}"))?; - match other { - RetrievableConfigField::RegistryUrl => { - println!("{}", config.registry.get_current_registry()); - } - RetrievableConfigField::RegistryToken => { - if let Some(s) = config.registry.get_login_token_for_registry( - &config.registry.get_current_registry(), - ) { - println!("{s}"); - } - } - RetrievableConfigField::ProxyUrl => { - if let Some(s) = config.proxy.url.as_ref() { - println!("{s}"); - } - } - RetrievableConfigField::TelemetryEnabled => { - println!("{:?}", config.telemetry_enabled); - } - RetrievableConfigField::UpdateNotificationsEnabled => { - println!("{:?}", config.update_notifications_enabled); - } - _ => {} - } - } - }, - Set(s) => { - let config_file = WasmerConfig::get_file_location() - .map_err(|e| anyhow::anyhow!("could not find config file {e}"))?; - let mut config = WasmerConfig::from_file().map_err(|e| { - anyhow::anyhow!( - "could not find config file {e} at {}", - config_file.display() - ) - })?; - - match s { - StorableConfigField::RegistryUrl(s) => { - config.registry.set_current_registry(&s.url); - let current_registry = config.registry.get_current_registry(); - if let Some(u) = wasmer_registry::utils::get_username().ok().and_then(|o| o) - { - println!("Successfully logged into registry {current_registry:?} as user {u:?}"); - } - } - StorableConfigField::RegistryToken(t) => { - config.registry.set_login_token_for_registry( - &config.registry.get_current_registry(), - &t.token, - wasmer_registry::config::UpdateRegistry::LeaveAsIs, - ); - } - StorableConfigField::TelemetryEnabled(t) => { - config.telemetry_enabled = t.enabled.0; - } - StorableConfigField::ProxyUrl(p) => { - config.proxy.url = p.url.clone(); - } - StorableConfigField::UpdateNotificationsEnabled(u) => { - config.update_notifications_enabled = u.enabled.0; - } - } - - config - .save(config_file) - .with_context(|| anyhow::anyhow!("could not save config file"))?; + } + StorableConfigField::RegistryToken(t) => { + config.registry.set_login_token_for_registry( + &config.registry.get_current_registry(), + &t.token, + wasmer_registry::config::UpdateRegistry::LeaveAsIs, + ); + } + StorableConfigField::TelemetryEnabled(t) => { + config.telemetry_enabled = t.enabled.0; + } + StorableConfigField::ProxyUrl(p) => { + config.proxy.url = p.url.clone(); + } + StorableConfigField::UpdateNotificationsEnabled(u) => { + config.update_notifications_enabled = u.enabled.0; } } + config + .save(config_file) + .with_context(|| anyhow::anyhow!("could not save config file"))?; Ok(()) } From 769a8c087f87ed1a95b5d4283138d86c5ee2d5a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 20 Dec 2022 10:27:57 +0100 Subject: [PATCH 19/32] Fix integration tests + cargo fmt --- tests/integration/cli/tests/config.rs | 39 +++++++++------------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/tests/integration/cli/tests/config.rs b/tests/integration/cli/tests/config.rs index 4f1968cf654..e677a3dcb35 100644 --- a/tests/integration/cli/tests/config.rs +++ b/tests/integration/cli/tests/config.rs @@ -158,8 +158,7 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("get") - .arg("config.path") + .arg("--config-path") .output()?; let config_path = Path::new(env!("WASMER_DIR")).join("wasmer.toml"); @@ -170,8 +169,7 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("get") - .arg("registry.token") + .arg("--registry-token") .output()?; let original_token = String::from_utf8_lossy(&output.stdout); @@ -187,8 +185,7 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("get") - .arg("registry.token") + .arg("--registry-token") .output()?; assert_eq!( @@ -207,8 +204,7 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("get") - .arg("registry.token") + .arg("--registry-token") .output()?; assert_eq!( @@ -218,8 +214,7 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("get") - .arg("registry.url") + .arg("--registry-url") .output()?; let original_url = String::from_utf8_lossy(&output.stdout); @@ -237,8 +232,7 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("get") - .arg("registry.url") + .arg("--registry-url") .output()?; let output_str = String::from_utf8_lossy(&output.stdout); @@ -259,8 +253,7 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("get") - .arg("registry.url") + .arg("--registry-url") .output()?; let output_str = String::from_utf8_lossy(&output.stdout); @@ -268,8 +261,7 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("get") - .arg("telemetry.enabled") + .arg("--telemetry-enabled") .output()?; let original_output = String::from_utf8_lossy(&output.stdout); @@ -285,8 +277,7 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("get") - .arg("telemetry.enabled") + .arg("--telemetry-enabled") .output()?; assert_eq!( @@ -305,8 +296,7 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("get") - .arg("telemetry.enabled") + .arg("--telemetry-enabled") .output()?; assert_eq!( @@ -316,8 +306,7 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("get") - .arg("update-notifications.enabled") + .arg("--update-notifications-enabled") .output()?; let original_output = String::from_utf8_lossy(&output.stdout); @@ -333,8 +322,7 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("get") - .arg("update-notifications.enabled") + .arg("--update-notifications-enabled") .output()?; assert_eq!( @@ -353,8 +341,7 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("get") - .arg("update-notifications.enabled") + .arg("--update-notifications-enabled") .output()?; assert_eq!( From c7621ffab007fc4d10ff5303f350f333442b332a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 20 Dec 2022 10:57:27 +0100 Subject: [PATCH 20/32] Fix wasmer config set subcommand --- lib/cli/src/commands/config.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index 97af94b9c50..6f4b9e7c554 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -13,7 +13,7 @@ pub struct Config { flags: Flags, /// Subcommand for `wasmer config get | set` #[clap(subcommand)] - set: Option, + set: Option, } /// Normal configuration @@ -73,6 +73,14 @@ pub struct Flags { pkg_config: bool, } +/// Subcommand for `wasmer config set` +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] +pub enum Set { + /// `wasmer config set $KEY $VALUE` + #[clap(subcommand)] + Set(StorableConfigField), +} + /// Setting that can be stored in the wasmer config #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] pub enum StorableConfigField { @@ -151,7 +159,7 @@ impl Config { .context("failed to retrieve the wasmer config".to_string()) } fn inner_execute(&self) -> Result<()> { - if let Some(s) = self.set.as_ref() { + if let Some(Set::Set(s)) = self.set.as_ref() { return s.execute(); } From d2868a1191369cc593637e2fc0c16eb1c722dd12 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Fri, 16 Dec 2022 14:09:55 -0800 Subject: [PATCH 21/32] Undo "merge master into config" --- lib/registry/src/publish.rs | 243 ------------------------------------ 1 file changed, 243 deletions(-) delete mode 100644 lib/registry/src/publish.rs diff --git a/lib/registry/src/publish.rs b/lib/registry/src/publish.rs deleted file mode 100644 index 2ac8b68ba0c..00000000000 --- a/lib/registry/src/publish.rs +++ /dev/null @@ -1,243 +0,0 @@ -use crate::graphql::{execute_query_modifier_inner, get_signed_url, GetSignedUrl}; -use crate::graphql::{publish_package_mutation_chunked, PublishPackageMutationChunked}; -use crate::{format_graphql, WasmerConfig}; -use console::{style, Emoji}; -use graphql_client::GraphQLQuery; -use indicatif::{ProgressBar, ProgressState, ProgressStyle}; - -use std::collections::BTreeMap; -use std::fmt::Write; -use std::io::BufRead; -use std::path::PathBuf; - -static UPLOAD: Emoji<'_, '_> = Emoji("⬆️ ", ""); -static PACKAGE: Emoji<'_, '_> = Emoji("📦 ", ""); - -#[derive(Debug, Clone)] -pub enum SignArchiveResult { - Ok { - public_key_id: String, - signature: String, - }, - NoKeyRegistered, -} - -#[allow(clippy::too_many_arguments)] -pub fn try_chunked_uploading( - registry: Option, - token: Option, - package: &wapm_toml::Package, - manifest_string: &String, - license_file: &Option, - readme: &Option, - archive_name: &String, - archive_path: &PathBuf, - maybe_signature_data: &SignArchiveResult, - archived_data_size: u64, - quiet: bool, -) -> Result<(), anyhow::Error> { - let registry = match registry.as_ref() { - Some(s) => format_graphql(s), - None => { - #[cfg(not(test))] - let config = WasmerConfig::from_file(); - #[cfg(test)] - let config = WasmerConfig::from_file("publish"); - - config - .map_err(|e| anyhow::anyhow!("{e}"))? - .registry - .get_current_registry() - } - }; - - let token = match token.as_ref() { - Some(s) => s.to_string(), - None => { - #[cfg(not(test))] - let config = WasmerConfig::from_file(); - #[cfg(test)] - let config = WasmerConfig::from_file("publish"); - - config - .map_err(|e| anyhow::anyhow!("{e}"))? - .registry - .get_login_token_for_registry(®istry) - .ok_or_else(|| { - anyhow::anyhow!("cannot publish package: not logged into registry {registry:?}") - })? - } - }; - - let maybe_signature_data = match maybe_signature_data { - SignArchiveResult::Ok { - public_key_id, - signature, - } => { - log::info!( - "Package successfully signed with public key: \"{}\"!", - &public_key_id - ); - Some(publish_package_mutation_chunked::InputSignature { - public_key_key_id: public_key_id.to_string(), - data: signature.to_string(), - }) - } - SignArchiveResult::NoKeyRegistered => { - // TODO: uncomment this when we actually want users to start using it - //warn!("Publishing package without a verifying signature. Consider registering a key pair with wapm"); - None - } - }; - - if !quiet { - println!("{} {} Uploading...", style("[1/2]").bold().dim(), UPLOAD); - } - - let get_google_signed_url = GetSignedUrl::build_query(get_signed_url::Variables { - name: package.name.to_string(), - version: package.version.to_string(), - expires_after_seconds: Some(60 * 30), - }); - - let _response: get_signed_url::ResponseData = - execute_query_modifier_inner(®istry, &token, &get_google_signed_url, None, |f| f)?; - - let url = _response.url.ok_or_else(|| { - anyhow::anyhow!( - "could not get signed url for package {}@{}", - package.name, - package.version - ) - })?; - - let signed_url = url.url; - let url = url::Url::parse(&signed_url).unwrap(); - let client = reqwest::blocking::Client::builder() - .default_headers(reqwest::header::HeaderMap::default()) - .build() - .unwrap(); - - let res = client - .post(url) - .header(reqwest::header::CONTENT_LENGTH, "0") - .header(reqwest::header::CONTENT_TYPE, "application/octet-stream") - .header("x-goog-resumable", "start"); - - let result = res.send().unwrap(); - - if result.status() != reqwest::StatusCode::from_u16(201).unwrap() { - return Err(anyhow::anyhow!( - "Uploading package failed: got HTTP {:?} when uploading", - result.status() - )); - } - - let headers = result - .headers() - .into_iter() - .filter_map(|(k, v)| { - let k = k.to_string(); - let v = v.to_str().ok()?.to_string(); - Some((k.to_lowercase(), v)) - }) - .collect::>(); - - let session_uri = headers.get("location").unwrap().clone(); - - let total = archived_data_size; - - // archive_path - let mut file = std::fs::OpenOptions::new() - .read(true) - .open(archive_path) - .map_err(|e| anyhow::anyhow!("cannot open archive {}: {e}", archive_path.display()))?; - - let pb = ProgressBar::new(archived_data_size); - pb.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})") - .unwrap() - .with_key("eta", |state: &ProgressState, w: &mut dyn Write| { - write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap() - }) - .progress_chars("#>-")); - - let chunk_size = 1_048_576; // 1MB - 315s / 100MB - let mut file_pointer = 0; - - let mut reader = std::io::BufReader::with_capacity(chunk_size, &mut file); - - let client = reqwest::blocking::Client::builder() - .default_headers(reqwest::header::HeaderMap::default()) - .build() - .unwrap(); - - while let Some(chunk) = reader.fill_buf().ok().map(|s| s.to_vec()) { - let n = chunk.len(); - - if chunk.is_empty() { - break; - } - - let start = file_pointer; - let end = file_pointer + chunk.len().saturating_sub(1); - let content_range = format!("bytes {start}-{end}/{total}"); - - let res = client - .put(&session_uri) - .header(reqwest::header::CONTENT_TYPE, "application/octet-stream") - .header(reqwest::header::CONTENT_LENGTH, format!("{}", chunk.len())) - .header("Content-Range".to_string(), content_range) - .body(chunk.to_vec()); - - pb.set_position(file_pointer as u64); - - res.send() - .map(|response| response.error_for_status()) - .map_err(|e| { - anyhow::anyhow!( - "cannot send request to {session_uri} (chunk {}..{}): {e}", - file_pointer, - file_pointer + chunk_size - ) - })??; - - if n < chunk_size { - break; - } - - reader.consume(n); - file_pointer += n; - } - - pb.finish_and_clear(); - - if !quiet { - println!("{} {}Publishing...", style("[2/2]").bold().dim(), PACKAGE); - } - - let q = - PublishPackageMutationChunked::build_query(publish_package_mutation_chunked::Variables { - name: package.name.to_string(), - version: package.version.to_string(), - description: package.description.clone(), - manifest: manifest_string.to_string(), - license: package.license.clone(), - license_file: license_file.to_owned(), - readme: readme.to_owned(), - repository: package.repository.clone(), - homepage: package.homepage.clone(), - file_name: Some(archive_name.to_string()), - signature: maybe_signature_data, - signed_url: Some(signed_url), - }); - - let _response: publish_package_mutation_chunked::ResponseData = - crate::graphql::execute_query(®istry, &token, &q)?; - - println!( - "Successfully published package `{}@{}`", - package.name, package.version - ); - - Ok(()) -} From 59a192ec8751930abb8b9080ca1b464edb00dc7a Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Fri, 16 Dec 2022 14:09:55 -0800 Subject: [PATCH 22/32] Revert "Implement wasmer init and wasmer publish" From 58ee1740564d1c14a235e6cbaa68bf98147da3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 20 Dec 2022 11:34:13 +0100 Subject: [PATCH 23/32] Move wasmer config registries to new format for wasmer.toml file --- lib/registry/src/config.rs | 107 ++++++++++++------------------------- lib/registry/src/lib.rs | 12 +---- 2 files changed, 36 insertions(+), 83 deletions(-) diff --git a/lib/registry/src/config.rs b/lib/registry/src/config.rs index faff2d4c90a..2139cdb4cc7 100644 --- a/lib/registry/src/config.rs +++ b/lib/registry/src/config.rs @@ -1,6 +1,5 @@ use graphql_client::GraphQLQuery; use serde::{Deserialize, Serialize}; -use std::collections::BTreeMap; use std::path::{Path, PathBuf}; #[derive(Deserialize, Default, Serialize, Debug, PartialEq, Eq)] @@ -19,7 +18,7 @@ pub struct WasmerConfig { pub update_notifications_enabled: bool, /// The registry that wapm will connect to. - pub registry: Registries, + pub registry: MultiRegistry, /// The proxy to use when connecting to the Internet. #[serde(default)] @@ -35,28 +34,29 @@ pub struct Proxy { pub url: Option, } -#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)] -#[serde(untagged)] -pub enum Registries { - Single(Registry), - Multi(MultiRegistry), -} - #[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)] pub struct MultiRegistry { /// Currently active registry - pub current: String, + pub active_registry: String, /// Map from "RegistryUrl" to "LoginToken", in order to /// be able to be able to easily switch between registries - pub tokens: BTreeMap, + pub tokens: Vec, } -impl Default for Registries { +#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)] +pub struct RegistryLogin { + /// Registry URL to login to + pub registry: String, + /// Login token for the registry + pub token: String, +} + +impl Default for MultiRegistry { fn default() -> Self { - Registries::Single(Registry { - url: format_graphql("https://registry.wapm.io"), - token: None, - }) + MultiRegistry { + active_registry: format_graphql("wapm.io"), + tokens: Vec::new(), + } } } @@ -131,18 +131,12 @@ fn test_registries_switch_token() { ); } -impl Registries { +impl MultiRegistry { /// Gets the current (active) registry URL pub fn clear_current_registry_token(&mut self) { - match self { - Registries::Single(s) => { - s.token = None; - } - Registries::Multi(m) => { - m.tokens.remove(&m.current); - m.tokens.remove(&format_graphql(&m.current)); - } - } + self.tokens.retain(|i| i.registry != self.active_registry); + self.tokens + .retain(|i| i.registry != format_graphql(&self.active_registry)); } pub fn get_graphql_url(&self) -> String { @@ -152,10 +146,7 @@ impl Registries { /// Gets the current (active) registry URL pub fn get_current_registry(&self) -> String { - match self { - Registries::Single(s) => format_graphql(&s.url), - Registries::Multi(m) => format_graphql(&m.current), - } + format_graphql(&self.active_registry) } /// Sets the current (active) registry URL @@ -165,25 +156,16 @@ impl Registries { println!("Error when trying to ping registry {registry:?}: {e}"); println!("WARNING: Registry {registry:?} will be used, but commands may not succeed."); } - match self { - Registries::Single(s) => s.url = registry, - Registries::Multi(m) => m.current = registry, - } + self.active_registry = registry; } /// Returns the login token for the registry pub fn get_login_token_for_registry(&self, registry: &str) -> Option { - match self { - Registries::Single(s) if s.url == registry || format_graphql(registry) == s.url => { - s.token.clone() - } - Registries::Multi(m) => m - .tokens - .get(registry) - .or_else(|| m.tokens.get(&format_graphql(registry))) - .cloned(), - _ => None, - } + let registry_formatted = format_graphql(registry); + self.tokens + .iter() + .find(|login| login.registry == registry || login.registry == registry_formatted) + .map(|login| login.token.clone()) } /// Sets the login token for the registry URL @@ -193,34 +175,13 @@ impl Registries { token: &str, update_current_registry: UpdateRegistry, ) { - let new_map = match self { - Registries::Single(s) => { - if s.url == registry { - Registries::Single(Registry { - url: format_graphql(registry), - token: Some(token.to_string()), - }) - } else { - let mut map = BTreeMap::new(); - if let Some(token) = s.token.clone() { - map.insert(format_graphql(&s.url), token); - } - map.insert(format_graphql(registry), token.to_string()); - Registries::Multi(MultiRegistry { - current: format_graphql(&s.url), - tokens: map, - }) - } - } - Registries::Multi(m) => { - m.tokens.insert(format_graphql(registry), token.to_string()); - if update_current_registry == UpdateRegistry::Update { - m.current = format_graphql(registry); - } - Registries::Multi(m.clone()) - } - }; - *self = new_map; + self.tokens.push(RegistryLogin { + registry: format_graphql(registry), + token: token.to_string(), + }); + if update_current_registry == UpdateRegistry::Update { + self.active_registry = format_graphql(registry); + } } } diff --git a/lib/registry/src/lib.rs b/lib/registry/src/lib.rs index 07e0a81c354..9d489bc3ec1 100644 --- a/lib/registry/src/lib.rs +++ b/lib/registry/src/lib.rs @@ -8,7 +8,6 @@ //! curl -sSfL https://registry.wapm.io/graphql/schema.graphql > lib/registry/graphql/schema.graphql //! ``` -use crate::config::Registries; use anyhow::Context; use core::ops::Range; use reqwest::header::{ACCEPT, RANGE}; @@ -664,15 +663,8 @@ pub fn get_all_available_registries(#[cfg(test)] test_name: &str) -> Result { - registries.push(format_graphql(&s.url)); - } - Registries::Multi(m) => { - for key in m.tokens.keys() { - registries.push(format_graphql(key)); - } - } + for login in config.registry.tokens { + registries.push(format_graphql(&login.registry)); } Ok(registries) } From 506f21a4927d7c24954200885c83e8d0e12da80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 20 Dec 2022 14:15:21 +0100 Subject: [PATCH 24/32] Remove old login tokens when updating config --- lib/registry/src/config.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/registry/src/config.rs b/lib/registry/src/config.rs index 2139cdb4cc7..49d29943048 100644 --- a/lib/registry/src/config.rs +++ b/lib/registry/src/config.rs @@ -164,7 +164,8 @@ impl MultiRegistry { let registry_formatted = format_graphql(registry); self.tokens .iter() - .find(|login| login.registry == registry || login.registry == registry_formatted) + .filter(|login| login.registry == registry || login.registry == registry_formatted) + .last() .map(|login| login.token.clone()) } @@ -175,6 +176,9 @@ impl MultiRegistry { token: &str, update_current_registry: UpdateRegistry, ) { + let registry_formatted = format_graphql(registry); + self.tokens + .retain(|login| !(login.registry == registry || login.registry == registry_formatted)); self.tokens.push(RegistryLogin { registry: format_graphql(registry), token: token.to_string(), From 0c1dc1c42dcdbedb817dd2b32a5ca8dfe3e33b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 20 Dec 2022 15:36:55 +0100 Subject: [PATCH 25/32] Fix tests --- lib/registry/src/config.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/registry/src/config.rs b/lib/registry/src/config.rs index 49d29943048..af72ba1af6d 100644 --- a/lib/registry/src/config.rs +++ b/lib/registry/src/config.rs @@ -1,6 +1,9 @@ use graphql_client::GraphQLQuery; use serde::{Deserialize, Serialize}; -use std::path::{Path, PathBuf}; +use std::{ + ops::Mul, + path::{Path, PathBuf}, +}; #[derive(Deserialize, Default, Serialize, Debug, PartialEq, Eq)] pub struct WasmerConfig { @@ -34,6 +37,8 @@ pub struct Proxy { pub url: Option, } +/// Struct to store login tokens for multiple registry URLs +/// inside of the wasmer.toml configuration file #[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)] pub struct MultiRegistry { /// Currently active registry @@ -99,7 +104,7 @@ pub enum UpdateRegistry { #[test] fn test_registries_switch_token() { - let mut registries = Registries::default(); + let mut registries = MultiRegistry::default(); registries.set_current_registry("https://registry.wapm.dev"); assert_eq!( From 1330c1ad4d2072cc6e9ee8cf6dd7f266c11d3e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 20 Dec 2022 15:42:10 +0100 Subject: [PATCH 26/32] Fix make lint --- lib/registry/src/config.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/registry/src/config.rs b/lib/registry/src/config.rs index af72ba1af6d..de31c171483 100644 --- a/lib/registry/src/config.rs +++ b/lib/registry/src/config.rs @@ -1,9 +1,6 @@ use graphql_client::GraphQLQuery; use serde::{Deserialize, Serialize}; -use std::{ - ops::Mul, - path::{Path, PathBuf}, -}; +use std::path::{Path, PathBuf}; #[derive(Deserialize, Default, Serialize, Debug, PartialEq, Eq)] pub struct WasmerConfig { From fc4e40b8c0b91bccd5ca34c75d9d80519e9859ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 21 Dec 2022 08:24:24 +0100 Subject: [PATCH 27/32] Never crash when wapm.toml could not be read --- lib/registry/src/config.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/registry/src/config.rs b/lib/registry/src/config.rs index de31c171483..705ba01ccfd 100644 --- a/lib/registry/src/config.rs +++ b/lib/registry/src/config.rs @@ -208,9 +208,7 @@ impl WasmerConfig { let path = Self::get_file_location()?; match std::fs::read_to_string(&path) { - Ok(config_toml) => { - toml::from_str(&config_toml).map_err(|e| format!("could not parse {path:?}: {e}")) - } + Ok(config_toml) => Ok(toml::from_str(&config_toml).unwrap_or_else(|_| Self::default())), Err(_e) => Ok(Self::default()), } } From b89d12837719e367b533e674f8b4fc58893a9a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 21 Dec 2022 08:25:10 +0100 Subject: [PATCH 28/32] Remove wax_cooldown --- lib/registry/src/config.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/registry/src/config.rs b/lib/registry/src/config.rs index 705ba01ccfd..a368f1ee9c7 100644 --- a/lib/registry/src/config.rs +++ b/lib/registry/src/config.rs @@ -4,10 +4,6 @@ use std::path::{Path, PathBuf}; #[derive(Deserialize, Default, Serialize, Debug, PartialEq, Eq)] pub struct WasmerConfig { - /// The number of seconds to wait before checking the registry for a new - /// version of the package. - #[serde(default = "wax_default_cooldown")] - pub wax_cooldown: i32, /// Whether or not telemetry is enabled. #[serde(default)] From 139c3147d67eeb2597ddbb69de4971c389979a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 21 Dec 2022 09:02:07 +0100 Subject: [PATCH 29/32] Revert to "get" / "set" for settable config keys --- lib/cli/src/commands/config.rs | 184 ++++++++++++++------------ lib/registry/src/config.rs | 1 - tests/integration/cli/tests/config.rs | 40 ++++-- 3 files changed, 124 insertions(+), 101 deletions(-) diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index 6f4b9e7c554..7766423b45f 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -13,7 +13,7 @@ pub struct Config { flags: Flags, /// Subcommand for `wasmer config get | set` #[clap(subcommand)] - set: Option, + set: Option, } /// Normal configuration @@ -47,26 +47,6 @@ pub struct Flags { #[clap(long, conflicts_with = "pkg-config")] config_path: bool, - /// Print the registry URL of the currently active registry - #[clap(long, conflicts_with = "pkg-config")] - registry_url: bool, - - /// Print the token for the currently active registry or nothing if not logged in - #[clap(long, conflicts_with = "pkg-config")] - registry_token: bool, - - /// Print whether telemetry is currently enabled - #[clap(long, conflicts_with = "pkg-config")] - telemetry_enabled: bool, - - /// Print whether update notifications are enabled - #[clap(long, conflicts_with = "pkg-config")] - update_notifications_enabled: bool, - - /// Print the proxy URL - #[clap(long, conflicts_with = "pkg-config")] - proxy_url: bool, - /// Outputs the necessary details for compiling /// and linking a program to Wasmer, using the `pkg-config` format. #[clap(long)] @@ -75,28 +55,51 @@ pub struct Flags { /// Subcommand for `wasmer config set` #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] -pub enum Set { +pub enum GetOrSet { + /// `wasmer config get $KEY` + #[clap(subcommand)] + Get(RetrievableConfigField), /// `wasmer config set $KEY $VALUE` #[clap(subcommand)] Set(StorableConfigField), } +/// Subcommand for `wasmer config get` +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] +pub enum RetrievableConfigField { + /// Print the registry URL of the currently active registry + #[clap(name = "registry.url")] + RegistryUrl, + /// Print the token for the currently active registry or nothing if not logged in + #[clap(name = "registry.token")] + RegistryToken, + /// Print whether telemetry is currently enabled + #[clap(name = "telemetry.enabled")] + TelemetryEnabled, + /// Print whether update notifications are enabled + #[clap(name = "update-notifications.enabled")] + UpdateNotificationsEnabled, + /// Print the proxy URL + #[clap(name = "proxy.url")] + ProxyUrl, +} + /// Setting that can be stored in the wasmer config #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] pub enum StorableConfigField { - /// Print the registry URL of the currently active registry + /// Set the registry URL of the currently active registry #[clap(name = "registry.url")] RegistryUrl(SetRegistryUrl), - /// Print the token for the currently active registry or nothing if not logged in + /// Set the token for the currently active registry or nothing if not logged in #[clap(name = "registry.token")] RegistryToken(SetRegistryToken), - /// Print whether telemetry is currently enabled + /// Set whether telemetry is currently enabled #[clap(name = "telemetry.enabled")] TelemetryEnabled(SetTelemetryEnabled), - /// Print whether update notifications are enabled + /// Set whether update notifications are enabled #[clap(name = "update-notifications.enabled")] UpdateNotificationsEnabled(SetUpdateNotificationsEnabled), - /// Print the proxy URL + /// Set the active proxy URL #[clap(name = "proxy.url")] ProxyUrl(SetProxyUrl), } @@ -149,7 +152,7 @@ pub struct SetTelemetryEnabled { pub struct SetProxyUrl { /// Set if a proxy URL should be used (empty = unset proxy) #[clap(name = "URL")] - pub url: Option, + pub url: String, } impl Config { @@ -159,7 +162,7 @@ impl Config { .context("failed to retrieve the wasmer config".to_string()) } fn inner_execute(&self) -> Result<()> { - if let Some(Set::Set(s)) = self.set.as_ref() { + if let Some(s) = self.set.as_ref() { return s.execute(); } @@ -225,41 +228,11 @@ impl Config { println!("{}", path.display()); } - let config = WasmerConfig::from_file() - .map_err(|e| anyhow::anyhow!("could not find config file: {e}"))?; - - if flags.registry_url { - println!("{}", config.registry.get_current_registry()); - } - - if flags.registry_token { - if let Some(s) = config - .registry - .get_login_token_for_registry(&config.registry.get_current_registry()) - { - println!("{s}"); - } - } - - if flags.telemetry_enabled { - println!("{:?}", config.telemetry_enabled); - } - - if flags.update_notifications_enabled { - println!("{:?}", config.update_notifications_enabled); - } - - if flags.proxy_url { - if let Some(s) = config.proxy.url.as_ref() { - println!("{s}"); - } - } - Ok(()) } } -impl StorableConfigField { +impl GetOrSet { fn execute(&self) -> Result<()> { let config_file = WasmerConfig::get_file_location() .map_err(|e| anyhow::anyhow!("could not find config file {e}"))?; @@ -270,36 +243,75 @@ impl StorableConfigField { ) })?; match self { - StorableConfigField::RegistryUrl(s) => { - config.registry.set_current_registry(&s.url); - let current_registry = config.registry.get_current_registry(); - if let Some(u) = wasmer_registry::utils::get_username().ok().and_then(|o| o) { - println!( - "Successfully logged into registry {current_registry:?} as user {u:?}" - ); + GetOrSet::Get(g) => { + let config = WasmerConfig::from_file() + .map_err(|e| anyhow::anyhow!("could not find config file: {e}"))?; + + match g { + RetrievableConfigField::RegistryUrl => { + println!("{}", config.registry.get_current_registry()); + } + RetrievableConfigField::RegistryToken => { + if let Some(s) = config + .registry + .get_login_token_for_registry(&config.registry.get_current_registry()) + { + println!("{s}"); + } + } + RetrievableConfigField::TelemetryEnabled => { + println!("{:?}", config.telemetry_enabled); + } + RetrievableConfigField::UpdateNotificationsEnabled => { + println!("{:?}", config.update_notifications_enabled); + } + RetrievableConfigField::ProxyUrl => { + if let Some(s) = config.proxy.url.as_ref() { + println!("{s}"); + } else { + println!("none"); + } + } } } - StorableConfigField::RegistryToken(t) => { - config.registry.set_login_token_for_registry( - &config.registry.get_current_registry(), - &t.token, - wasmer_registry::config::UpdateRegistry::LeaveAsIs, - ); - } - StorableConfigField::TelemetryEnabled(t) => { - config.telemetry_enabled = t.enabled.0; - } - StorableConfigField::ProxyUrl(p) => { - config.proxy.url = p.url.clone(); - } - StorableConfigField::UpdateNotificationsEnabled(u) => { - config.update_notifications_enabled = u.enabled.0; + GetOrSet::Set(s) => { + match s { + StorableConfigField::RegistryUrl(s) => { + config.registry.set_current_registry(&s.url); + let current_registry = config.registry.get_current_registry(); + if let Some(u) = wasmer_registry::utils::get_username().ok().and_then(|o| o) + { + println!( + "Successfully logged into registry {current_registry:?} as user {u:?}" + ); + } + } + StorableConfigField::RegistryToken(t) => { + config.registry.set_login_token_for_registry( + &config.registry.get_current_registry(), + &t.token, + wasmer_registry::config::UpdateRegistry::LeaveAsIs, + ); + } + StorableConfigField::TelemetryEnabled(t) => { + config.telemetry_enabled = t.enabled.0; + } + StorableConfigField::ProxyUrl(p) => { + if p.url == "none" || p.url.is_empty() { + config.proxy.url = None; + } else { + config.proxy.url = Some(p.url.clone()); + } + } + StorableConfigField::UpdateNotificationsEnabled(u) => { + config.update_notifications_enabled = u.enabled.0; + } + } + config + .save(config_file) + .with_context(|| anyhow::anyhow!("could not save config file"))?; } } - config - .save(config_file) - .with_context(|| anyhow::anyhow!("could not save config file"))?; - Ok(()) } } diff --git a/lib/registry/src/config.rs b/lib/registry/src/config.rs index a368f1ee9c7..729934ee60a 100644 --- a/lib/registry/src/config.rs +++ b/lib/registry/src/config.rs @@ -4,7 +4,6 @@ use std::path::{Path, PathBuf}; #[derive(Deserialize, Default, Serialize, Debug, PartialEq, Eq)] pub struct WasmerConfig { - /// Whether or not telemetry is enabled. #[serde(default)] pub telemetry_enabled: bool, diff --git a/tests/integration/cli/tests/config.rs b/tests/integration/cli/tests/config.rs index e677a3dcb35..fa3ea57708c 100644 --- a/tests/integration/cli/tests/config.rs +++ b/tests/integration/cli/tests/config.rs @@ -154,8 +154,6 @@ fn config_works() -> anyhow::Result<()> { assert_eq!(lines, args); - // ---- config get - let output = Command::new(get_wasmer_path()) .arg("config") .arg("--config-path") @@ -167,9 +165,12 @@ fn config_works() -> anyhow::Result<()> { format!("{}\n", config_path.display()) ); + // ---- config get + let output = Command::new(get_wasmer_path()) .arg("config") - .arg("--registry-token") + .arg("get") + .arg("registry.token") .output()?; let original_token = String::from_utf8_lossy(&output.stdout); @@ -185,7 +186,8 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("--registry-token") + .arg("get") + .arg("registry.token") .output()?; assert_eq!( @@ -204,7 +206,8 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("--registry-token") + .arg("get") + .arg("registry.token") .output()?; assert_eq!( @@ -214,7 +217,8 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("--registry-url") + .arg("get") + .arg("registry.url") .output()?; let original_url = String::from_utf8_lossy(&output.stdout); @@ -232,7 +236,8 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("--registry-url") + .arg("get") + .arg("registry.url") .output()?; let output_str = String::from_utf8_lossy(&output.stdout); @@ -253,7 +258,8 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("--registry-url") + .arg("get") + .arg("registry.url") .output()?; let output_str = String::from_utf8_lossy(&output.stdout); @@ -261,7 +267,8 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("--telemetry-enabled") + .arg("get") + .arg("telemetry.enabled") .output()?; let original_output = String::from_utf8_lossy(&output.stdout); @@ -277,7 +284,8 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("--telemetry-enabled") + .arg("get") + .arg("telemetry.enabled") .output()?; assert_eq!( @@ -296,7 +304,8 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("--telemetry-enabled") + .arg("get") + .arg("telemetry.enabled") .output()?; assert_eq!( @@ -306,7 +315,8 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("--update-notifications-enabled") + .arg("get") + .arg("update-notifications.enabled") .output()?; let original_output = String::from_utf8_lossy(&output.stdout); @@ -322,7 +332,8 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("--update-notifications-enabled") + .arg("get") + .arg("update-notifications.enabled") .output()?; assert_eq!( @@ -341,7 +352,8 @@ fn config_works() -> anyhow::Result<()> { let output = Command::new(get_wasmer_path()) .arg("config") - .arg("--update-notifications-enabled") + .arg("get") + .arg("update-notifications.enabled") .output()?; assert_eq!( From ec18ec71e735d2f5be19c1ffebcae02eb6a45ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 22 Dec 2022 11:29:39 +0100 Subject: [PATCH 30/32] PartialWapmConfig -> WasmerConfig --- lib/cli/src/commands/add.rs | 4 ++-- lib/cli/src/commands/init.rs | 4 ++-- lib/cli/src/commands/list.rs | 4 ++-- lib/cli/src/commands/login.rs | 4 ++-- lib/cli/src/commands/publish.rs | 10 +++++----- lib/cli/src/commands/whoami.rs | 4 ++-- lib/cli/src/package_source.rs | 10 +++++----- lib/registry/src/lib.rs | 4 ++-- lib/registry/src/login.rs | 6 +++--- lib/registry/src/package.rs | 6 +++--- lib/registry/src/publish.rs | 10 +++++----- 11 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/cli/src/commands/add.rs b/lib/cli/src/commands/add.rs index b95c472c869..885dc1f9b38 100644 --- a/lib/cli/src/commands/add.rs +++ b/lib/cli/src/commands/add.rs @@ -77,8 +77,8 @@ impl Add { Some(r) => Ok(r.clone()), None => { let wasmer_dir = - PartialWapmConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?; - let cfg = PartialWapmConfig::from_file(&wasmer_dir) + WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?; + let cfg = WasmerConfig::from_file(&wasmer_dir) .map_err(Error::msg) .context("Unable to load WAPM's config file")?; Ok(cfg.registry.get_current_registry()) diff --git a/lib/cli/src/commands/init.rs b/lib/cli/src/commands/init.rs index d3e4e520313..ba641ec0ccb 100644 --- a/lib/cli/src/commands/init.rs +++ b/lib/cli/src/commands/init.rs @@ -4,7 +4,7 @@ use clap::Parser; use std::collections::HashMap; use std::path::Path; use std::path::PathBuf; -use wasmer_registry::PartialWapmConfig; +use wasmer_registry::WasmerConfig; static NOTE: &str = "# See more keys and definitions at https://docs.wasmer.io/ecosystem/wapm/manifest"; @@ -365,7 +365,7 @@ fn construct_manifest( .map(|p| &p.name) .unwrap_or(fallback_package_name) }); - let wasmer_dir = PartialWapmConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?; + let wasmer_dir = WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?; let namespace = namespace.or_else(|| { wasmer_registry::whoami(&wasmer_dir, None, None) .ok() diff --git a/lib/cli/src/commands/list.rs b/lib/cli/src/commands/list.rs index 34c494e889f..770b4c4dd6e 100644 --- a/lib/cli/src/commands/list.rs +++ b/lib/cli/src/commands/list.rs @@ -1,5 +1,5 @@ use clap::Parser; -use wasmer_registry::PartialWapmConfig; +use wasmer_registry::WasmerConfig; /// Subcommand for listing packages #[derive(Debug, Copy, Clone, Parser)] @@ -9,7 +9,7 @@ impl List { /// execute [List] pub fn execute(&self) -> Result<(), anyhow::Error> { use prettytable::{format, row, Table}; - let wasmer_dir = PartialWapmConfig::get_wasmer_dir() + let wasmer_dir = WasmerConfig::get_wasmer_dir() .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; let rows = wasmer_registry::get_all_local_packages(&wasmer_dir) .into_iter() diff --git a/lib/cli/src/commands/login.rs b/lib/cli/src/commands/login.rs index f23694dc3da..25a42fe2788 100644 --- a/lib/cli/src/commands/login.rs +++ b/lib/cli/src/commands/login.rs @@ -1,7 +1,7 @@ use clap::Parser; #[cfg(not(test))] use dialoguer::Input; -use wasmer_registry::PartialWapmConfig; +use wasmer_registry::WasmerConfig; /// Subcommand for listing packages #[derive(Debug, Clone, Parser)] @@ -52,7 +52,7 @@ impl Login { /// execute [List] pub fn execute(&self) -> Result<(), anyhow::Error> { let token = self.get_token_or_ask_user()?; - let wasmer_dir = PartialWapmConfig::get_wasmer_dir() + let wasmer_dir = WasmerConfig::get_wasmer_dir() .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; match wasmer_registry::login::login_and_save_token(&wasmer_dir, &self.registry, &token)? { Some(s) => println!("Login for WAPM user {:?} saved", s), diff --git a/lib/cli/src/commands/publish.rs b/lib/cli/src/commands/publish.rs index e3a825be79a..f4b038d3e0c 100644 --- a/lib/cli/src/commands/publish.rs +++ b/lib/cli/src/commands/publish.rs @@ -9,7 +9,7 @@ use tar::Builder; use thiserror::Error; use time::{self, OffsetDateTime}; use wasmer_registry::publish::SignArchiveResult; -use wasmer_registry::{PartialWapmConfig, PACKAGE_TOML_FALLBACK_NAME}; +use wasmer_registry::{WasmerConfig, PACKAGE_TOML_FALLBACK_NAME}; const MIGRATIONS: &[(i32, &str)] = &[ (0, include_str!("../../sql/migrations/0000.sql")), @@ -94,9 +94,9 @@ impl Publish { let registry = match self.registry.as_deref() { Some(s) => wasmer_registry::format_graphql(s), None => { - let wasmer_dir = PartialWapmConfig::get_wasmer_dir() + let wasmer_dir = WasmerConfig::get_wasmer_dir() .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; - let config = PartialWapmConfig::from_file(&wasmer_dir) + let config = WasmerConfig::from_file(&wasmer_dir) .map_err(|e| anyhow::anyhow!("could not load config {e}"))?; config.registry.get_current_registry() } @@ -325,8 +325,8 @@ pub fn sign_compressed_archive( /// Opens an exclusive read/write connection to the database, creating it if it does not exist pub fn open_db() -> anyhow::Result { let wasmer_dir = - PartialWapmConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; - let db_path = PartialWapmConfig::get_database_file_path(&wasmer_dir); + WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; + let db_path = WasmerConfig::get_database_file_path(&wasmer_dir); let mut conn = Connection::open_with_flags( db_path, OpenFlags::SQLITE_OPEN_CREATE diff --git a/lib/cli/src/commands/whoami.rs b/lib/cli/src/commands/whoami.rs index a0fbedd3ab1..c72f9ac7613 100644 --- a/lib/cli/src/commands/whoami.rs +++ b/lib/cli/src/commands/whoami.rs @@ -1,5 +1,5 @@ use clap::Parser; -use wasmer_registry::PartialWapmConfig; +use wasmer_registry::WasmerConfig; #[derive(Debug, Parser)] /// The options for the `wasmer whoami` subcommand @@ -12,7 +12,7 @@ pub struct Whoami { impl Whoami { /// Execute `wasmer whoami` pub fn execute(&self) -> Result<(), anyhow::Error> { - let wasmer_dir = PartialWapmConfig::get_wasmer_dir() + let wasmer_dir = WasmerConfig::get_wasmer_dir() .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; let (registry, username) = wasmer_registry::whoami(&wasmer_dir, self.registry.as_deref(), None)?; diff --git a/lib/cli/src/package_source.rs b/lib/cli/src/package_source.rs index d3ffc116615..3e1c854fbf4 100644 --- a/lib/cli/src/package_source.rs +++ b/lib/cli/src/package_source.rs @@ -4,7 +4,7 @@ use anyhow::Context; use std::path::{Path, PathBuf}; use std::str::FromStr; use url::Url; -use wasmer_registry::PartialWapmConfig; +use wasmer_registry::WasmerConfig; /// Source of a package #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] @@ -62,7 +62,7 @@ impl PackageSource { }; } Self::Url(u) => { - let wasmer_dir = PartialWapmConfig::get_wasmer_dir() + let wasmer_dir = WasmerConfig::get_wasmer_dir() .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; if let Some(path) = wasmer_registry::Package::is_url_already_installed(u, &wasmer_dir) @@ -73,7 +73,7 @@ impl PackageSource { } } Self::Package(p) => { - let wasmer_dir = PartialWapmConfig::get_wasmer_dir() + let wasmer_dir = WasmerConfig::get_wasmer_dir() .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; let package_path = Path::new(&p.file()).to_path_buf(); if package_path.exists() { @@ -81,7 +81,7 @@ impl PackageSource { } else if let Some(path) = p.already_installed(&wasmer_dir) { return Ok(path); } else { - let config = PartialWapmConfig::from_file(&wasmer_dir) + let config = WasmerConfig::from_file(&wasmer_dir) .map_err(|e| anyhow::anyhow!("error loading wasmer config file: {e}"))?; p.url(&config.registry.get_current_registry())? } @@ -94,7 +94,7 @@ impl PackageSource { String::new() }; - let wasmer_dir = PartialWapmConfig::get_wasmer_dir() + let wasmer_dir = WasmerConfig::get_wasmer_dir() .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; let mut sp = start_spinner(format!("Installing package {url} ...")); let opt_path = wasmer_registry::install_package(&wasmer_dir, &url); diff --git a/lib/registry/src/lib.rs b/lib/registry/src/lib.rs index 6c8ae17d1ff..c4dc32ab397 100644 --- a/lib/registry/src/lib.rs +++ b/lib/registry/src/lib.rs @@ -576,7 +576,7 @@ pub fn whoami( use crate::queries::{who_am_i_query, WhoAmIQuery}; use graphql_client::GraphQLQuery; - let config = PartialWapmConfig::from_file(wasmer_dir); + let config = WasmerConfig::from_file(wasmer_dir); let config = config .map_err(|e| anyhow::anyhow!("{e}")) @@ -626,7 +626,7 @@ pub fn test_if_registry_present(registry: &str) -> Result { pub fn get_all_available_registries(wasmer_dir: &Path) -> Result, String> { - let config = PartialWapmConfig::from_file(wasmer_dir)?; + let config = WasmerConfig::from_file(wasmer_dir)?; let mut registries = Vec::new(); for login in config.registry.tokens { registries.push(format_graphql(&login.registry)); diff --git a/lib/registry/src/login.rs b/lib/registry/src/login.rs index 2aba0f05a00..e112be4babf 100644 --- a/lib/registry/src/login.rs +++ b/lib/registry/src/login.rs @@ -1,5 +1,5 @@ use crate::config::{format_graphql, UpdateRegistry}; -use crate::PartialWapmConfig; +use crate::WasmerConfig; use std::path::Path; @@ -12,7 +12,7 @@ pub fn login_and_save_token( token: &str, ) -> Result, anyhow::Error> { let registry = format_graphql(registry); - let mut config = PartialWapmConfig::from_file(wasmer_dir) + let mut config = WasmerConfig::from_file(wasmer_dir) .map_err(|e| anyhow::anyhow!("config from file: {e}"))?; config.registry.set_current_registry(®istry); config.registry.set_login_token_for_registry( @@ -20,7 +20,7 @@ pub fn login_and_save_token( token, UpdateRegistry::Update, ); - let path = PartialWapmConfig::get_file_location(wasmer_dir); + let path = WasmerConfig::get_file_location(wasmer_dir); config.save(&path)?; crate::utils::get_username_registry_token(®istry, token) } diff --git a/lib/registry/src/package.rs b/lib/registry/src/package.rs index 9662e2a8584..062800f7f92 100644 --- a/lib/registry/src/package.rs +++ b/lib/registry/src/package.rs @@ -1,4 +1,4 @@ -use crate::PartialWapmConfig; +use crate::WasmerConfig; use regex::Regex; use std::path::{Path, PathBuf}; use std::{fmt, str::FromStr}; @@ -28,7 +28,7 @@ impl Package { /// Checks whether the package is already installed, if yes, returns the path to the root dir pub fn already_installed(&self, wasmer_dir: &Path) -> Option { let checkouts_dir = crate::get_checkouts_dir(wasmer_dir); - let config = PartialWapmConfig::from_file(wasmer_dir).ok()?; + let config = WasmerConfig::from_file(wasmer_dir).ok()?; let current_registry = config.registry.get_current_registry(); let hash = self.get_hash(¤t_registry); @@ -134,7 +134,7 @@ impl Package { /// Does not check whether the installation directory already exists. pub fn get_path(&self, wasmer_dir: &Path) -> Result { let checkouts_dir = crate::get_checkouts_dir(wasmer_dir); - let config = PartialWapmConfig::from_file(wasmer_dir) + let config = WasmerConfig::from_file(wasmer_dir) .map_err(|e| anyhow::anyhow!("could not load config {e}"))?; let hash = self.get_hash(&config.registry.get_current_registry()); diff --git a/lib/registry/src/publish.rs b/lib/registry/src/publish.rs index 612cd2ca733..ec5f5c5dfaf 100644 --- a/lib/registry/src/publish.rs +++ b/lib/registry/src/publish.rs @@ -1,6 +1,6 @@ use crate::graphql::{execute_query_modifier_inner, get_signed_url, GetSignedUrl}; use crate::graphql::{publish_package_mutation_chunked, PublishPackageMutationChunked}; -use crate::{format_graphql, PartialWapmConfig}; +use crate::{format_graphql, WasmerConfig}; use console::{style, Emoji}; use graphql_client::GraphQLQuery; use indicatif::{ProgressBar, ProgressState, ProgressStyle}; @@ -40,9 +40,9 @@ pub fn try_chunked_uploading( Some(s) => format_graphql(s), None => { let wasmer_dir = - PartialWapmConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?; + WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?; - let config = PartialWapmConfig::from_file(&wasmer_dir); + let config = WasmerConfig::from_file(&wasmer_dir); config .map_err(|e| anyhow::anyhow!("{e}"))? @@ -55,9 +55,9 @@ pub fn try_chunked_uploading( Some(s) => s.to_string(), None => { let wasmer_dir = - PartialWapmConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?; + WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?; - let config = PartialWapmConfig::from_file(&wasmer_dir); + let config = WasmerConfig::from_file(&wasmer_dir); config .map_err(|e| anyhow::anyhow!("{e}"))? From fdd62e188d3d31c2dd4d8b04439c48415b1ebdbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 22 Dec 2022 11:36:34 +0100 Subject: [PATCH 31/32] Fix merge issues --- lib/cli/src/commands/config.rs | 67 +++++++++++++++++----------------- lib/cli/src/commands/list.rs | 4 +- lib/cli/src/commands/login.rs | 4 +- lib/cli/src/commands/whoami.rs | 4 +- lib/cli/src/package_source.rs | 4 +- lib/registry/src/lib.rs | 1 - lib/registry/src/login.rs | 1 - lib/registry/src/publish.rs | 6 +-- lib/registry/src/utils.rs | 3 +- 9 files changed, 44 insertions(+), 50 deletions(-) diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index 7766423b45f..3df09d409de 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -223,8 +223,9 @@ impl Config { } if flags.config_path { - let path = WasmerConfig::get_file_location() - .map_err(|e| anyhow::anyhow!("could not find config file: {e}"))?; + let wasmer_dir = WasmerConfig::get_wasmer_dir() + .map_err(|e| anyhow::anyhow!("could not find wasmer dir: {e}"))?; + let path = WasmerConfig::get_file_location(&wasmer_dir); println!("{}", path.display()); } @@ -234,52 +235,50 @@ impl Config { impl GetOrSet { fn execute(&self) -> Result<()> { - let config_file = WasmerConfig::get_file_location() - .map_err(|e| anyhow::anyhow!("could not find config file {e}"))?; - let mut config = WasmerConfig::from_file().map_err(|e| { + let wasmer_dir = WasmerConfig::get_wasmer_dir() + .map_err(|e| anyhow::anyhow!("could not find wasmer dir: {e}"))?; + let config_file = WasmerConfig::get_file_location(&wasmer_dir); + let mut config = WasmerConfig::from_file(&wasmer_dir).map_err(|e| { anyhow::anyhow!( "could not find config file {e} at {}", config_file.display() ) })?; match self { - GetOrSet::Get(g) => { - let config = WasmerConfig::from_file() - .map_err(|e| anyhow::anyhow!("could not find config file: {e}"))?; - - match g { - RetrievableConfigField::RegistryUrl => { - println!("{}", config.registry.get_current_registry()); - } - RetrievableConfigField::RegistryToken => { - if let Some(s) = config - .registry - .get_login_token_for_registry(&config.registry.get_current_registry()) - { - println!("{s}"); - } - } - RetrievableConfigField::TelemetryEnabled => { - println!("{:?}", config.telemetry_enabled); - } - RetrievableConfigField::UpdateNotificationsEnabled => { - println!("{:?}", config.update_notifications_enabled); + GetOrSet::Get(g) => match g { + RetrievableConfigField::RegistryUrl => { + println!("{}", config.registry.get_current_registry()); + } + RetrievableConfigField::RegistryToken => { + if let Some(s) = config + .registry + .get_login_token_for_registry(&config.registry.get_current_registry()) + { + println!("{s}"); } - RetrievableConfigField::ProxyUrl => { - if let Some(s) = config.proxy.url.as_ref() { - println!("{s}"); - } else { - println!("none"); - } + } + RetrievableConfigField::TelemetryEnabled => { + println!("{:?}", config.telemetry_enabled); + } + RetrievableConfigField::UpdateNotificationsEnabled => { + println!("{:?}", config.update_notifications_enabled); + } + RetrievableConfigField::ProxyUrl => { + if let Some(s) = config.proxy.url.as_ref() { + println!("{s}"); + } else { + println!("none"); } } - } + }, GetOrSet::Set(s) => { match s { StorableConfigField::RegistryUrl(s) => { config.registry.set_current_registry(&s.url); let current_registry = config.registry.get_current_registry(); - if let Some(u) = wasmer_registry::utils::get_username().ok().and_then(|o| o) + if let Some(u) = wasmer_registry::utils::get_username(¤t_registry) + .ok() + .and_then(|o| o) { println!( "Successfully logged into registry {current_registry:?} as user {u:?}" diff --git a/lib/cli/src/commands/list.rs b/lib/cli/src/commands/list.rs index 770b4c4dd6e..ae0ec3462f6 100644 --- a/lib/cli/src/commands/list.rs +++ b/lib/cli/src/commands/list.rs @@ -9,8 +9,8 @@ impl List { /// execute [List] pub fn execute(&self) -> Result<(), anyhow::Error> { use prettytable::{format, row, Table}; - let wasmer_dir = WasmerConfig::get_wasmer_dir() - .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; + let wasmer_dir = + WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; let rows = wasmer_registry::get_all_local_packages(&wasmer_dir) .into_iter() .filter_map(|pkg| { diff --git a/lib/cli/src/commands/login.rs b/lib/cli/src/commands/login.rs index 25a42fe2788..e1d141db492 100644 --- a/lib/cli/src/commands/login.rs +++ b/lib/cli/src/commands/login.rs @@ -52,8 +52,8 @@ impl Login { /// execute [List] pub fn execute(&self) -> Result<(), anyhow::Error> { let token = self.get_token_or_ask_user()?; - let wasmer_dir = WasmerConfig::get_wasmer_dir() - .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; + let wasmer_dir = + WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; match wasmer_registry::login::login_and_save_token(&wasmer_dir, &self.registry, &token)? { Some(s) => println!("Login for WAPM user {:?} saved", s), None => println!( diff --git a/lib/cli/src/commands/whoami.rs b/lib/cli/src/commands/whoami.rs index c72f9ac7613..8d5b27fedee 100644 --- a/lib/cli/src/commands/whoami.rs +++ b/lib/cli/src/commands/whoami.rs @@ -12,8 +12,8 @@ pub struct Whoami { impl Whoami { /// Execute `wasmer whoami` pub fn execute(&self) -> Result<(), anyhow::Error> { - let wasmer_dir = WasmerConfig::get_wasmer_dir() - .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; + let wasmer_dir = + WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; let (registry, username) = wasmer_registry::whoami(&wasmer_dir, self.registry.as_deref(), None)?; println!("logged into registry {registry:?} as user {username:?}"); diff --git a/lib/cli/src/package_source.rs b/lib/cli/src/package_source.rs index 3e1c854fbf4..3cb973d68e7 100644 --- a/lib/cli/src/package_source.rs +++ b/lib/cli/src/package_source.rs @@ -94,8 +94,8 @@ impl PackageSource { String::new() }; - let wasmer_dir = WasmerConfig::get_wasmer_dir() - .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; + let wasmer_dir = + WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; let mut sp = start_spinner(format!("Installing package {url} ...")); let opt_path = wasmer_registry::install_package(&wasmer_dir, &url); if let Some(sp) = sp.take() { diff --git a/lib/registry/src/lib.rs b/lib/registry/src/lib.rs index c4dc32ab397..bb6f6a162c8 100644 --- a/lib/registry/src/lib.rs +++ b/lib/registry/src/lib.rs @@ -624,7 +624,6 @@ pub fn test_if_registry_present(registry: &str) -> Result { Ok(true) } - pub fn get_all_available_registries(wasmer_dir: &Path) -> Result, String> { let config = WasmerConfig::from_file(wasmer_dir)?; let mut registries = Vec::new(); diff --git a/lib/registry/src/login.rs b/lib/registry/src/login.rs index e112be4babf..d2a095a9b9a 100644 --- a/lib/registry/src/login.rs +++ b/lib/registry/src/login.rs @@ -2,7 +2,6 @@ use crate::config::{format_graphql, UpdateRegistry}; use crate::WasmerConfig; use std::path::Path; - /// Login to a registry and save the token associated with it. /// /// Also sets the registry as the currently active registry to provide a better UX. diff --git a/lib/registry/src/publish.rs b/lib/registry/src/publish.rs index ec5f5c5dfaf..71a605ae0b0 100644 --- a/lib/registry/src/publish.rs +++ b/lib/registry/src/publish.rs @@ -39,8 +39,7 @@ pub fn try_chunked_uploading( let registry = match registry.as_ref() { Some(s) => format_graphql(s), None => { - let wasmer_dir = - WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?; + let wasmer_dir = WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?; let config = WasmerConfig::from_file(&wasmer_dir); @@ -54,8 +53,7 @@ pub fn try_chunked_uploading( let token = match token.as_ref() { Some(s) => s.to_string(), None => { - let wasmer_dir = - WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?; + let wasmer_dir = WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?; let config = WasmerConfig::from_file(&wasmer_dir); diff --git a/lib/registry/src/utils.rs b/lib/registry/src/utils.rs index 1e3cb493bf5..54f7f1f74ef 100644 --- a/lib/registry/src/utils.rs +++ b/lib/registry/src/utils.rs @@ -1,4 +1,4 @@ -use crate::{graphql::execute_query, WasmerConfig}; +use crate::graphql::execute_query; use graphql_client::GraphQLQuery; #[derive(GraphQLQuery)] @@ -9,7 +9,6 @@ use graphql_client::GraphQLQuery; )] struct WhoAmIQuery; - pub fn get_username(registry: &str) -> anyhow::Result> { let q = WhoAmIQuery::build_query(who_am_i_query::Variables {}); let response: who_am_i_query::ResponseData = execute_query(registry, "", &q)?; From aa04d58d6207a14ffc47d9ea4d42868f72bb45d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 22 Dec 2022 14:25:45 +0100 Subject: [PATCH 32/32] Update wasmer-registry to 4.0.0 --- Cargo.lock | 2 +- lib/cli/Cargo.toml | 2 +- lib/registry/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59accbaca8c..538ee0fd468 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4552,7 +4552,7 @@ dependencies = [ [[package]] name = "wasmer-registry" -version = "3.1.0" +version = "4.0.0" dependencies = [ "anyhow", "console", diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 0062558e3d9..be699380915 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -37,7 +37,7 @@ wasmer-wasi-experimental-io-devices = { version = "=3.1.0", path = "../wasi-expe wasmer-wast = { version = "=3.1.0", path = "../../tests/lib/wast", optional = true } wasmer-cache = { version = "=3.1.0", path = "../cache", optional = true } wasmer-types = { version = "=3.1.0", path = "../types" } -wasmer-registry = { version = "=3.1.0", path = "../registry" } +wasmer-registry = { version = "=4.0.0", path = "../registry" } wasmer-object = { version = "=3.1.0", path = "../object", optional = true } wasmer-vfs = { version = "=3.1.0", path = "../vfs", default-features = false, features = ["host-fs"] } wasmer-wasm-interface = { version = "3.1.0", path = "../wasm-interface" } diff --git a/lib/registry/Cargo.toml b/lib/registry/Cargo.toml index af96584af6e..a1fb62d8a07 100644 --- a/lib/registry/Cargo.toml +++ b/lib/registry/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-registry" -version = "3.1.0" +version = "4.0.0" edition = "2021" license = "MIT" description = "Crate to interact with the wasmer registry (wapm.io), download packages, etc."