PartialWapmConfig -> WasmerConfig

This commit is contained in:
Felix Schütt
2022-12-22 11:29:39 +01:00
parent 45f4b8da4e
commit ec18ec71e7
11 changed files with 33 additions and 33 deletions

View File

@@ -77,8 +77,8 @@ impl Add {
Some(r) => Ok(r.clone()), Some(r) => Ok(r.clone()),
None => { None => {
let wasmer_dir = let wasmer_dir =
PartialWapmConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?; WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?;
let cfg = PartialWapmConfig::from_file(&wasmer_dir) let cfg = WasmerConfig::from_file(&wasmer_dir)
.map_err(Error::msg) .map_err(Error::msg)
.context("Unable to load WAPM's config file")?; .context("Unable to load WAPM's config file")?;
Ok(cfg.registry.get_current_registry()) Ok(cfg.registry.get_current_registry())

View File

@@ -4,7 +4,7 @@ use clap::Parser;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use wasmer_registry::PartialWapmConfig; use wasmer_registry::WasmerConfig;
static NOTE: &str = static NOTE: &str =
"# See more keys and definitions at https://docs.wasmer.io/ecosystem/wapm/manifest"; "# See more keys and definitions at https://docs.wasmer.io/ecosystem/wapm/manifest";
@@ -365,7 +365,7 @@ fn construct_manifest(
.map(|p| &p.name) .map(|p| &p.name)
.unwrap_or(fallback_package_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(|| { let namespace = namespace.or_else(|| {
wasmer_registry::whoami(&wasmer_dir, None, None) wasmer_registry::whoami(&wasmer_dir, None, None)
.ok() .ok()

View File

@@ -1,5 +1,5 @@
use clap::Parser; use clap::Parser;
use wasmer_registry::PartialWapmConfig; use wasmer_registry::WasmerConfig;
/// Subcommand for listing packages /// Subcommand for listing packages
#[derive(Debug, Copy, Clone, Parser)] #[derive(Debug, Copy, Clone, Parser)]
@@ -9,7 +9,7 @@ impl List {
/// execute [List] /// execute [List]
pub fn execute(&self) -> Result<(), anyhow::Error> { pub fn execute(&self) -> Result<(), anyhow::Error> {
use prettytable::{format, row, Table}; 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}"))?; .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
let rows = wasmer_registry::get_all_local_packages(&wasmer_dir) let rows = wasmer_registry::get_all_local_packages(&wasmer_dir)
.into_iter() .into_iter()

View File

@@ -1,7 +1,7 @@
use clap::Parser; use clap::Parser;
#[cfg(not(test))] #[cfg(not(test))]
use dialoguer::Input; use dialoguer::Input;
use wasmer_registry::PartialWapmConfig; use wasmer_registry::WasmerConfig;
/// Subcommand for listing packages /// Subcommand for listing packages
#[derive(Debug, Clone, Parser)] #[derive(Debug, Clone, Parser)]
@@ -52,7 +52,7 @@ impl Login {
/// execute [List] /// execute [List]
pub fn execute(&self) -> Result<(), anyhow::Error> { pub fn execute(&self) -> Result<(), anyhow::Error> {
let token = self.get_token_or_ask_user()?; 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}"))?; .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
match wasmer_registry::login::login_and_save_token(&wasmer_dir, &self.registry, &token)? { match wasmer_registry::login::login_and_save_token(&wasmer_dir, &self.registry, &token)? {
Some(s) => println!("Login for WAPM user {:?} saved", s), Some(s) => println!("Login for WAPM user {:?} saved", s),

View File

@@ -9,7 +9,7 @@ use tar::Builder;
use thiserror::Error; use thiserror::Error;
use time::{self, OffsetDateTime}; use time::{self, OffsetDateTime};
use wasmer_registry::publish::SignArchiveResult; 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)] = &[ const MIGRATIONS: &[(i32, &str)] = &[
(0, include_str!("../../sql/migrations/0000.sql")), (0, include_str!("../../sql/migrations/0000.sql")),
@@ -94,9 +94,9 @@ impl Publish {
let registry = match self.registry.as_deref() { let registry = match self.registry.as_deref() {
Some(s) => wasmer_registry::format_graphql(s), Some(s) => wasmer_registry::format_graphql(s),
None => { None => {
let wasmer_dir = PartialWapmConfig::get_wasmer_dir() let wasmer_dir = WasmerConfig::get_wasmer_dir()
.map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; .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}"))?; .map_err(|e| anyhow::anyhow!("could not load config {e}"))?;
config.registry.get_current_registry() 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 /// Opens an exclusive read/write connection to the database, creating it if it does not exist
pub fn open_db() -> anyhow::Result<Connection> { pub fn open_db() -> anyhow::Result<Connection> {
let wasmer_dir = let wasmer_dir =
PartialWapmConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?; WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
let db_path = PartialWapmConfig::get_database_file_path(&wasmer_dir); let db_path = WasmerConfig::get_database_file_path(&wasmer_dir);
let mut conn = Connection::open_with_flags( let mut conn = Connection::open_with_flags(
db_path, db_path,
OpenFlags::SQLITE_OPEN_CREATE OpenFlags::SQLITE_OPEN_CREATE

View File

@@ -1,5 +1,5 @@
use clap::Parser; use clap::Parser;
use wasmer_registry::PartialWapmConfig; use wasmer_registry::WasmerConfig;
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
/// The options for the `wasmer whoami` subcommand /// The options for the `wasmer whoami` subcommand
@@ -12,7 +12,7 @@ pub struct Whoami {
impl Whoami { impl Whoami {
/// Execute `wasmer whoami` /// Execute `wasmer whoami`
pub fn execute(&self) -> Result<(), anyhow::Error> { 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}"))?; .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
let (registry, username) = let (registry, username) =
wasmer_registry::whoami(&wasmer_dir, self.registry.as_deref(), None)?; wasmer_registry::whoami(&wasmer_dir, self.registry.as_deref(), None)?;

View File

@@ -4,7 +4,7 @@ use anyhow::Context;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::str::FromStr; use std::str::FromStr;
use url::Url; use url::Url;
use wasmer_registry::PartialWapmConfig; use wasmer_registry::WasmerConfig;
/// Source of a package /// Source of a package
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
@@ -62,7 +62,7 @@ impl PackageSource {
}; };
} }
Self::Url(u) => { 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}"))?; .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
if let Some(path) = if let Some(path) =
wasmer_registry::Package::is_url_already_installed(u, &wasmer_dir) wasmer_registry::Package::is_url_already_installed(u, &wasmer_dir)
@@ -73,7 +73,7 @@ impl PackageSource {
} }
} }
Self::Package(p) => { 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}"))?; .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
let package_path = Path::new(&p.file()).to_path_buf(); let package_path = Path::new(&p.file()).to_path_buf();
if package_path.exists() { if package_path.exists() {
@@ -81,7 +81,7 @@ impl PackageSource {
} else if let Some(path) = p.already_installed(&wasmer_dir) { } else if let Some(path) = p.already_installed(&wasmer_dir) {
return Ok(path); return Ok(path);
} else { } 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}"))?; .map_err(|e| anyhow::anyhow!("error loading wasmer config file: {e}"))?;
p.url(&config.registry.get_current_registry())? p.url(&config.registry.get_current_registry())?
} }
@@ -94,7 +94,7 @@ impl PackageSource {
String::new() 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}"))?; .map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
let mut sp = start_spinner(format!("Installing package {url} ...")); let mut sp = start_spinner(format!("Installing package {url} ..."));
let opt_path = wasmer_registry::install_package(&wasmer_dir, &url); let opt_path = wasmer_registry::install_package(&wasmer_dir, &url);

View File

@@ -576,7 +576,7 @@ pub fn whoami(
use crate::queries::{who_am_i_query, WhoAmIQuery}; use crate::queries::{who_am_i_query, WhoAmIQuery};
use graphql_client::GraphQLQuery; use graphql_client::GraphQLQuery;
let config = PartialWapmConfig::from_file(wasmer_dir); let config = WasmerConfig::from_file(wasmer_dir);
let config = config let config = config
.map_err(|e| anyhow::anyhow!("{e}")) .map_err(|e| anyhow::anyhow!("{e}"))
@@ -626,7 +626,7 @@ pub fn test_if_registry_present(registry: &str) -> Result<bool, String> {
pub fn get_all_available_registries(wasmer_dir: &Path) -> Result<Vec<String>, String> { pub fn get_all_available_registries(wasmer_dir: &Path) -> Result<Vec<String>, String> {
let config = PartialWapmConfig::from_file(wasmer_dir)?; let config = WasmerConfig::from_file(wasmer_dir)?;
let mut registries = Vec::new(); let mut registries = Vec::new();
for login in config.registry.tokens { for login in config.registry.tokens {
registries.push(format_graphql(&login.registry)); registries.push(format_graphql(&login.registry));

View File

@@ -1,5 +1,5 @@
use crate::config::{format_graphql, UpdateRegistry}; use crate::config::{format_graphql, UpdateRegistry};
use crate::PartialWapmConfig; use crate::WasmerConfig;
use std::path::Path; use std::path::Path;
@@ -12,7 +12,7 @@ pub fn login_and_save_token(
token: &str, token: &str,
) -> Result<Option<String>, anyhow::Error> { ) -> Result<Option<String>, anyhow::Error> {
let registry = format_graphql(registry); 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}"))?; .map_err(|e| anyhow::anyhow!("config from file: {e}"))?;
config.registry.set_current_registry(&registry); config.registry.set_current_registry(&registry);
config.registry.set_login_token_for_registry( config.registry.set_login_token_for_registry(
@@ -20,7 +20,7 @@ pub fn login_and_save_token(
token, token,
UpdateRegistry::Update, UpdateRegistry::Update,
); );
let path = PartialWapmConfig::get_file_location(wasmer_dir); let path = WasmerConfig::get_file_location(wasmer_dir);
config.save(&path)?; config.save(&path)?;
crate::utils::get_username_registry_token(&registry, token) crate::utils::get_username_registry_token(&registry, token)
} }

View File

@@ -1,4 +1,4 @@
use crate::PartialWapmConfig; use crate::WasmerConfig;
use regex::Regex; use regex::Regex;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::{fmt, str::FromStr}; 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 /// 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<PathBuf> { pub fn already_installed(&self, wasmer_dir: &Path) -> Option<PathBuf> {
let checkouts_dir = crate::get_checkouts_dir(wasmer_dir); 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 current_registry = config.registry.get_current_registry();
let hash = self.get_hash(&current_registry); let hash = self.get_hash(&current_registry);
@@ -134,7 +134,7 @@ impl Package {
/// Does not check whether the installation directory already exists. /// Does not check whether the installation directory already exists.
pub fn get_path(&self, wasmer_dir: &Path) -> Result<PathBuf, anyhow::Error> { pub fn get_path(&self, wasmer_dir: &Path) -> Result<PathBuf, anyhow::Error> {
let checkouts_dir = crate::get_checkouts_dir(wasmer_dir); 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}"))?; .map_err(|e| anyhow::anyhow!("could not load config {e}"))?;
let hash = self.get_hash(&config.registry.get_current_registry()); let hash = self.get_hash(&config.registry.get_current_registry());

View File

@@ -1,6 +1,6 @@
use crate::graphql::{execute_query_modifier_inner, get_signed_url, GetSignedUrl}; use crate::graphql::{execute_query_modifier_inner, get_signed_url, GetSignedUrl};
use crate::graphql::{publish_package_mutation_chunked, PublishPackageMutationChunked}; use crate::graphql::{publish_package_mutation_chunked, PublishPackageMutationChunked};
use crate::{format_graphql, PartialWapmConfig}; use crate::{format_graphql, WasmerConfig};
use console::{style, Emoji}; use console::{style, Emoji};
use graphql_client::GraphQLQuery; use graphql_client::GraphQLQuery;
use indicatif::{ProgressBar, ProgressState, ProgressStyle}; use indicatif::{ProgressBar, ProgressState, ProgressStyle};
@@ -40,9 +40,9 @@ pub fn try_chunked_uploading(
Some(s) => format_graphql(s), Some(s) => format_graphql(s),
None => { None => {
let wasmer_dir = 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 config
.map_err(|e| anyhow::anyhow!("{e}"))? .map_err(|e| anyhow::anyhow!("{e}"))?
@@ -55,9 +55,9 @@ pub fn try_chunked_uploading(
Some(s) => s.to_string(), Some(s) => s.to_string(),
None => { None => {
let wasmer_dir = 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 config
.map_err(|e| anyhow::anyhow!("{e}"))? .map_err(|e| anyhow::anyhow!("{e}"))?