feat: Rename wasmer-api to wasmer-backend-api

This commit is contained in:
Edoardo Marangoni
2024-10-29 13:48:14 +01:00
parent 7a75251846
commit cc969fc56a
52 changed files with 188 additions and 157 deletions

View File

@ -1,9 +1,9 @@
[package]
name = "wasmer-api"
name = "wasmer-backend-api"
version = "0.1.0"
description = "Client library for the Wasmer GraphQL API"
readme = "README.md"
documentation = "https://docs.rs/wasmer-api"
documentation = "https://docs.rs/wasmer-backend-api"
authors.workspace = true
edition.workspace = true

View File

@ -1,4 +1,4 @@
# wasmer-api
# wasmer-backend-api
GraphQL API client for the [Wasmer](https://wasmer.io) backend.

View File

@ -144,7 +144,7 @@ virtual-mio = { version = "0.5.0", path = "../virtual-io" }
# Wasmer-owned dependencies.
webc = { workspace = true }
wasmer-api = { version = "=0.1.0", path = "../backend-api" }
wasmer-backend-api = { version = "=0.1.0", path = "../backend-api" }
lazy_static = "1.4.0"
# Used by the mount command

View File

@ -3,7 +3,7 @@ use crate::config::WasmerEnv;
use anyhow::{Context, Error};
use clap::Parser;
use std::process::{Command, Stdio};
use wasmer_api::{
use wasmer_backend_api::{
types::{Bindings, ProgrammingLanguage},
WasmerClient,
};
@ -102,7 +102,7 @@ async fn lookup_bindings_for_package(
pkg: &NamedPackageIdent,
language: &ProgrammingLanguage,
) -> Result<Bindings, Error> {
let all_bindings = wasmer_api::query::list_bindings(
let all_bindings = wasmer_backend_api::query::list_bindings(
client,
&pkg.name,
pkg.version_opt().map(|v| v.to_string()).as_deref(),

View File

@ -14,7 +14,7 @@ use colored::Colorize;
use dialoguer::{theme::ColorfulTheme, Confirm, Select};
use futures::stream::TryStreamExt;
use is_terminal::IsTerminal;
use wasmer_api::{
use wasmer_backend_api::{
types::{AppTemplate, TemplateLanguage},
WasmerClient,
};
@ -190,7 +190,7 @@ impl CmdAppCreate {
}
let user = if let Some(client) = client {
Some(wasmer_api::query::current_user_with_namespaces(client, None).await?)
Some(wasmer_backend_api::query::current_user_with_namespaces(client, None).await?)
} else {
None
};
@ -359,10 +359,10 @@ impl CmdAppCreate {
// Fetch the first page.
// If first item matches, then no need to re-fetch.
//
let stream = wasmer_api::query::fetch_all_app_templates_from_language(
let stream = wasmer_backend_api::query::fetch_all_app_templates_from_language(
client,
10,
Some(wasmer_api::types::AppTemplatesSortBy::Newest),
Some(wasmer_backend_api::types::AppTemplatesSortBy::Newest),
language.to_string(),
);
@ -446,7 +446,7 @@ impl CmdAppCreate {
// Either no cache present, or cache has exceeded max age.
// Fetch the first page.
// If first item matches, then no need to re-fetch.
let mut stream = Box::pin(wasmer_api::query::fetch_all_app_template_languages(
let mut stream = Box::pin(wasmer_backend_api::query::fetch_all_app_template_languages(
client, None,
));
@ -489,7 +489,8 @@ impl CmdAppCreate {
if let Ok(url) = url::Url::parse(template) {
url
} else if let Some(template) =
wasmer_api::query::fetch_app_template_from_slug(client, template.clone()).await?
wasmer_backend_api::query::fetch_app_template_from_slug(client, template.clone())
.await?
{
url::Url::parse(&template.repo_url)?
} else {

View File

@ -53,7 +53,7 @@ impl AsyncCliCommand for CmdAppDelete {
app.name,
app.id.inner(),
);
wasmer_api::query::delete_app(&client, app.id.into_inner()).await?;
wasmer_backend_api::query::delete_app(&client, app.id.into_inner()).await?;
eprintln!("App '{}/{}' was deleted!", app.owner.global_name, app.name);

View File

@ -11,7 +11,7 @@ use dialoguer::Confirm;
use is_terminal::IsTerminal;
use std::io::Write;
use std::{path::PathBuf, str::FromStr, time::Duration};
use wasmer_api::{
use wasmer_backend_api::{
types::{DeployApp, DeployAppVersion},
WasmerClient,
};
@ -185,7 +185,7 @@ impl CmdAppDeploy {
anyhow::bail!("No owner specified: use --owner XXX");
}
let user = wasmer_api::query::current_user_with_namespaces(client, None).await?;
let user = wasmer_backend_api::query::current_user_with_namespaces(client, None).await?;
let owner = crate::utils::prompts::prompt_for_namespace(
"Who should own this app?",
None,
@ -274,7 +274,7 @@ impl AsyncCliCommand for CmdAppDeploy {
// We want to allow the user to specify the app name interactively.
let mut app_yaml: serde_yaml::Value = serde_yaml::from_str(&config_str)?;
let maybe_edge_app = if let Some(app_id) = app_yaml.get("app_id").and_then(|s| s.as_str()) {
wasmer_api::query::get_app_by_id(&client, app_id.to_owned())
wasmer_backend_api::query::get_app_by_id(&client, app_id.to_owned())
.await
.ok()
} else {
@ -285,12 +285,13 @@ impl AsyncCliCommand for CmdAppDeploy {
.get_owner(&client, &mut app_yaml, maybe_edge_app.as_ref())
.await?;
if !wasmer_api::query::viewer_can_deploy_to_namespace(&client, &owner).await? {
if !wasmer_backend_api::query::viewer_can_deploy_to_namespace(&client, &owner).await? {
eprintln!("It seems you don't have access to {}", owner.bold());
if self.non_interactive {
anyhow::bail!("Please, change the owner before deploying or check your current user with `{} whoami`.", std::env::args().next().unwrap_or("wasmer".into()));
} else {
let user = wasmer_api::query::current_user_with_namespaces(&client, None).await?;
let user =
wasmer_backend_api::query::current_user_with_namespaces(&client, None).await?;
owner = crate::utils::prompts::prompt_for_namespace(
"Who should own this app?",
None,
@ -624,9 +625,9 @@ pub async fn deploy_app(
// TODO: respect allow_create flag
let version = wasmer_api::query::publish_deploy_app(
let version = wasmer_backend_api::query::publish_deploy_app(
client,
wasmer_api::types::PublishDeployAppVars {
wasmer_backend_api::types::PublishDeployAppVars {
config: raw_config,
name: app.name.clone().into(),
owner: opts.owner.map(|o| o.into()),
@ -665,7 +666,7 @@ pub async fn wait_app(
.inner()
.to_string();
let app = wasmer_api::query::get_app_by_id(client, app_id.clone())
let app = wasmer_backend_api::query::get_app_by_id(client, app_id.clone())
.await
.context("could not fetch app from backend")?;

View File

@ -21,7 +21,7 @@ impl AsyncCliCommand for CmdAppDeploymentGet {
async fn run_async(mut self) -> Result<(), anyhow::Error> {
let client = self.env.client()?;
let item = wasmer_api::query::app_deployment(&client, self.id).await?;
let item = wasmer_backend_api::query::app_deployment(&client, self.id).await?;
println!("{}", self.fmt.get().render(&item));
Ok(())

View File

@ -30,14 +30,14 @@ impl AsyncCliCommand for CmdAppDeploymentList {
let client = self.env.client()?;
let (_ident, app) = self.ident.load_app(&client).await?;
let vars = wasmer_api::types::GetAppDeploymentsVariables {
let vars = wasmer_backend_api::types::GetAppDeploymentsVariables {
after: None,
first: self.limit.map(|x| x as i32),
name: app.name.clone(),
offset: self.offset.map(|x| x as i32),
owner: app.owner.global_name,
};
let items = wasmer_api::query::app_deployments(&client, vars).await?;
let items = wasmer_backend_api::query::app_deployments(&client, vars).await?;
if items.is_empty() {
eprintln!("App {} has no deployments!", app.name);

View File

@ -26,7 +26,7 @@ impl AsyncCliCommand for CmdAppDeploymentLogs {
async fn run_async(mut self) -> Result<(), anyhow::Error> {
let client = self.env.client()?;
let item = wasmer_api::query::app_deployment(&client, self.id).await?;
let item = wasmer_backend_api::query::app_deployment(&client, self.id).await?;
let url = item
.log_url

View File

@ -1,6 +1,6 @@
//! Get information about an edge app.
use wasmer_api::types::DeployApp;
use wasmer_backend_api::types::DeployApp;
use super::util::AppIdentOpts;

View File

@ -3,7 +3,7 @@
use std::pin::Pin;
use futures::{Stream, StreamExt};
use wasmer_api::types::{DeployApp, DeployAppsSortBy};
use wasmer_backend_api::types::{DeployApp, DeployAppsSortBy};
use crate::{commands::AsyncCliCommand, config::WasmerEnv, opts::ListFormatOpts};
@ -65,11 +65,11 @@ impl AsyncCliCommand for CmdAppList {
let apps_stream: Pin<
Box<dyn Stream<Item = Result<Vec<DeployApp>, anyhow::Error>> + Send + Sync>,
> = if let Some(ns) = self.namespace.clone() {
Box::pin(wasmer_api::query::namespace_apps(&client, ns, sort).await)
Box::pin(wasmer_backend_api::query::namespace_apps(&client, ns, sort).await)
} else if self.all {
Box::pin(wasmer_api::query::user_accessible_apps(&client, sort).await?)
Box::pin(wasmer_backend_api::query::user_accessible_apps(&client, sort).await?)
} else {
Box::pin(wasmer_api::query::user_apps(&client, sort).await)
Box::pin(wasmer_backend_api::query::user_apps(&client, sort).await)
};
let mut apps_stream = std::pin::pin!(apps_stream);

View File

@ -5,7 +5,7 @@ use colored::Colorize;
use comfy_table::{Cell, Table};
use futures::StreamExt;
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
use wasmer_api::types::{Log, LogStream};
use wasmer_backend_api::types::{Log, LogStream};
use crate::{config::WasmerEnv, opts::ListFormatOpts, utils::render::CliRender};
@ -127,7 +127,7 @@ impl crate::commands::AsyncCliCommand for CmdAppLogs {
// Code duplication to avoid a dependency to `OR` streams.
if let Some(instance_id) = &self.instance_id {
let logs_stream = wasmer_api::query::get_app_logs_paginated_filter_instance(
let logs_stream = wasmer_backend_api::query::get_app_logs_paginated_filter_instance(
&client,
app.name.clone(),
app.owner.global_name.to_string(),
@ -162,7 +162,7 @@ impl crate::commands::AsyncCliCommand for CmdAppLogs {
}
}
} else if let Some(request_id) = &self.request_id {
let logs_stream = wasmer_api::query::get_app_logs_paginated_filter_request(
let logs_stream = wasmer_backend_api::query::get_app_logs_paginated_filter_request(
&client,
app.name.clone(),
app.owner.global_name.to_string(),
@ -197,7 +197,7 @@ impl crate::commands::AsyncCliCommand for CmdAppLogs {
}
}
} else {
let logs_stream = wasmer_api::query::get_app_logs_paginated(
let logs_stream = wasmer_backend_api::query::get_app_logs_paginated(
&client,
app.name.clone(),
app.owner.global_name.to_string(),

View File

@ -46,8 +46,8 @@ impl AsyncCliCommand for CmdAppPurgeCache {
version_id.inner()
);
let vars = wasmer_api::types::PurgeCacheForAppVersionVars { id: version_id };
wasmer_api::query::purge_cache_for_app_version(&client, vars).await?;
let vars = wasmer_backend_api::types::PurgeCacheForAppVersionVars { id: version_id };
wasmer_backend_api::query::purge_cache_for_app_version(&client, vars).await?;
println!("🚽 swirl! All caches have been purged!");

View File

@ -26,7 +26,7 @@ impl AsyncCliCommand for CmdAppRegionsList {
async fn run_async(self) -> Result<Self::Output, anyhow::Error> {
let client = self.env.client()?;
let regions = wasmer_api::query::get_all_app_regions(&client).await?;
let regions = wasmer_backend_api::query::get_all_app_regions(&client).await?;
println!("{}", self.fmt.format.render(regions.as_slice()));

View File

@ -1,6 +1,6 @@
use crate::utils::render::CliRender;
use comfy_table::{Cell, Table};
use wasmer_api::types::AppRegion;
use wasmer_backend_api::types::AppRegion;
impl CliRender for AppRegion {
fn render_item_table(&self) -> String {

View File

@ -11,7 +11,7 @@ use std::{
collections::{HashMap, HashSet},
path::{Path, PathBuf},
};
use wasmer_api::WasmerClient;
use wasmer_backend_api::WasmerClient;
/// Create a new app secret.
#[derive(clap::Parser, Debug)]
@ -95,7 +95,7 @@ impl CmdAppSecretsCreate {
) -> anyhow::Result<Vec<Secret>> {
let names = secrets.iter().map(|s| &s.name);
let app_secrets =
wasmer_api::query::get_all_app_secrets_filtered(client, app_id, names).await?;
wasmer_backend_api::query::get_all_app_secrets_filtered(client, app_id, names).await?;
let mut sset = HashSet::<String>::from_iter(app_secrets.iter().map(|s| s.name.clone()));
let mut ret = HashMap::new();
@ -142,7 +142,7 @@ impl CmdAppSecretsCreate {
app_id: &str,
secrets: Vec<Secret>,
) -> Result<(), anyhow::Error> {
let res = wasmer_api::query::upsert_app_secrets(
let res = wasmer_backend_api::query::upsert_app_secrets(
client,
app_id,
secrets.iter().map(|s| (s.name.as_str(), s.value.as_str())),
@ -173,7 +173,7 @@ impl CmdAppSecretsCreate {
};
if should_redeploy {
wasmer_api::query::redeploy_app_by_id(client, app_id).await?;
wasmer_backend_api::query::redeploy_app_by_id(client, app_id).await?;
eprintln!("{} Deployment complete", "𖥔".yellow().bold());
} else {
eprintln!(

View File

@ -6,7 +6,7 @@ use colored::Colorize;
use dialoguer::theme::ColorfulTheme;
use is_terminal::IsTerminal;
use std::path::{Path, PathBuf};
use wasmer_api::WasmerClient;
use wasmer_backend_api::WasmerClient;
use super::utils::{self, get_secrets};
@ -91,7 +91,8 @@ impl CmdAppSecretsDelete {
}
}
let res = wasmer_api::query::delete_app_secret(client, secret.id.into_inner()).await?;
let res = wasmer_backend_api::query::delete_app_secret(client, secret.id.into_inner())
.await?;
match res {
Some(res) if !res.success => {

View File

@ -11,7 +11,7 @@ use std::{
collections::HashSet,
path::{Path, PathBuf},
};
use wasmer_api::WasmerClient;
use wasmer_backend_api::WasmerClient;
/// Update an existing app secret.
#[derive(clap::Parser, Debug)]
@ -100,7 +100,7 @@ impl CmdAppSecretsUpdate {
) -> anyhow::Result<Vec<Secret>> {
let names = secrets.iter().map(|s| &s.name);
let app_secrets =
wasmer_api::query::get_all_app_secrets_filtered(client, app_id, names).await?;
wasmer_backend_api::query::get_all_app_secrets_filtered(client, app_id, names).await?;
let sset = HashSet::<&str>::from_iter(app_secrets.iter().map(|s| s.name.as_str()));
let mut ret = vec![];
@ -136,7 +136,7 @@ impl CmdAppSecretsUpdate {
app_id: &str,
secrets: Vec<Secret>,
) -> Result<(), anyhow::Error> {
let res = wasmer_api::query::upsert_app_secrets(
let res = wasmer_backend_api::query::upsert_app_secrets(
client,
app_id,
secrets.iter().map(|s| (s.name.as_str(), s.value.as_str())),
@ -167,7 +167,7 @@ impl CmdAppSecretsUpdate {
};
if should_redeploy {
wasmer_api::query::redeploy_app_by_id(client, app_id).await?;
wasmer_backend_api::query::redeploy_app_by_id(client, app_id).await?;
eprintln!("{} Deployment complete", "𖥔".yellow().bold());
} else {
eprintln!(

View File

@ -6,7 +6,7 @@ use std::{
path::{Path, PathBuf},
str::FromStr,
};
use wasmer_api::{types::Secret as BackendSecret, WasmerClient};
use wasmer_backend_api::{types::Secret as BackendSecret, WasmerClient};
use crate::commands::app::util::{get_app_config_from_dir, prompt_app_ident, AppIdent};
@ -30,20 +30,20 @@ pub(super) async fn get_secret_by_name(
app_id: &str,
secret_name: &str,
) -> anyhow::Result<Option<BackendSecret>> {
wasmer_api::query::get_app_secret_by_name(client, app_id, secret_name).await
wasmer_backend_api::query::get_app_secret_by_name(client, app_id, secret_name).await
}
pub(crate) async fn get_secrets(
client: &WasmerClient,
app_id: &str,
) -> anyhow::Result<Vec<wasmer_api::types::Secret>> {
wasmer_api::query::get_all_app_secrets(client, app_id).await
) -> anyhow::Result<Vec<wasmer_backend_api::types::Secret>> {
wasmer_backend_api::query::get_all_app_secrets(client, app_id).await
}
pub(crate) async fn get_secret_value(
client: &WasmerClient,
secret: &wasmer_api::types::Secret,
secret: &wasmer_backend_api::types::Secret,
) -> anyhow::Result<String> {
wasmer_api::query::get_app_secret_value_by_id(client, secret.id.clone().into_inner())
wasmer_backend_api::query::get_app_secret_value_by_id(client, secret.id.clone().into_inner())
.await?
.ok_or_else(|| {
anyhow::anyhow!(
@ -68,7 +68,7 @@ pub(crate) async fn reveal_secrets(
client: &WasmerClient,
app_id: &str,
) -> anyhow::Result<Vec<Secret>> {
let secrets = wasmer_api::query::get_all_app_secrets(client, app_id).await?;
let secrets = wasmer_backend_api::query::get_all_app_secrets(client, app_id).await?;
let mut ret = vec![];
for secret in secrets {
let name = secret.name.clone();

View File

@ -3,7 +3,7 @@ use crate::utils::render::CliRender;
use colored::Colorize;
use comfy_table::{Cell, Table};
use time::OffsetDateTime;
use wasmer_api::types::{DateTime, Secret as BackendSecret};
use wasmer_backend_api::types::{DateTime, Secret as BackendSecret};
impl CliRender for Secret {
fn render_item_table(&self) -> String {

View File

@ -3,7 +3,7 @@ use std::{path::Path, str::FromStr};
use anyhow::{bail, Context};
use colored::Colorize;
use dialoguer::{theme::ColorfulTheme, Confirm};
use wasmer_api::{
use wasmer_backend_api::{
global_id::{GlobalId, NodeKind},
types::DeployApp,
WasmerClient,
@ -32,12 +32,14 @@ impl AppIdent {
/// Resolve an app identifier through the API.
pub async fn resolve(&self, client: &WasmerClient) -> Result<DeployApp, anyhow::Error> {
match self {
AppIdent::AppId(app_id) => wasmer_api::query::get_app_by_id(client, app_id.clone())
.await
.with_context(|| format!("Could not find app with id '{}'", app_id)),
AppIdent::AppId(app_id) => {
wasmer_backend_api::query::get_app_by_id(client, app_id.clone())
.await
.with_context(|| format!("Could not find app with id '{}'", app_id))
}
AppIdent::AppVersionId(id) => {
let (app, _version) =
wasmer_api::query::get_app_version_by_id_with_app(client, id.clone())
wasmer_backend_api::query::get_app_version_by_id_with_app(client, id.clone())
.await
.with_context(|| format!("Could not query for app version id '{}'", id))?;
Ok(app)
@ -46,16 +48,16 @@ impl AppIdent {
// The API only allows to query by owner + name,
// so default to the current user as the owner.
// To to so the username must first be retrieved.
let user = wasmer_api::query::current_user(client)
let user = wasmer_backend_api::query::current_user(client)
.await?
.context("not logged in")?;
wasmer_api::query::get_app(client, user.username, name.clone())
wasmer_backend_api::query::get_app(client, user.username, name.clone())
.await?
.with_context(|| format!("Could not find app with name '{name}'"))
}
AppIdent::NamespacedName(owner, name) => {
wasmer_api::query::get_app(client, owner.clone(), name.clone())
wasmer_backend_api::query::get_app(client, owner.clone(), name.clone())
.await?
.with_context(|| format!("Could not find app '{owner}/{name}'"))
}

View File

@ -23,7 +23,7 @@ impl AsyncCliCommand for CmdAppVersionActivate {
async fn run_async(self) -> Result<(), anyhow::Error> {
let client = self.env.client()?;
let app = wasmer_api::query::app_version_activate(&client, self.version).await?;
let app = wasmer_backend_api::query::app_version_activate(&client, self.version).await?;
let Some(version) = &app.active_version else {
anyhow::bail!("Failed to activate version: backend did not update version!");

View File

@ -33,7 +33,7 @@ impl AsyncCliCommand for CmdAppVersionGet {
let client = self.env.client()?;
let (_ident, app) = self.ident.load_app(&client).await?;
let version = wasmer_api::query::get_app_version(
let version = wasmer_backend_api::query::get_app_version(
&client,
app.owner.global_name,
app.name,

View File

@ -1,4 +1,4 @@
use wasmer_api::types::{DeployAppVersionsSortBy, GetDeployAppVersionsVars};
use wasmer_backend_api::types::{DeployAppVersionsSortBy, GetDeployAppVersionsVars};
use crate::{
commands::{app::util::AppIdentOpts, AsyncCliCommand},
@ -77,7 +77,8 @@ impl AsyncCliCommand for CmdAppVersionList {
let (_ident, app) = self.ident.load_app(&client).await?;
let versions = if self.all {
wasmer_api::query::all_app_versions(&client, app.owner.global_name, app.name).await?
wasmer_backend_api::query::all_app_versions(&client, app.owner.global_name, app.name)
.await?
} else {
let vars = GetDeployAppVersionsVars {
owner: app.owner.global_name,
@ -91,7 +92,7 @@ impl AsyncCliCommand for CmdAppVersionList {
};
let versions =
wasmer_api::query::get_deploy_app_versions(&client, vars.clone()).await?;
wasmer_backend_api::query::get_deploy_app_versions(&client, vars.clone()).await?;
versions
.edges

View File

@ -30,7 +30,8 @@ impl AsyncCliCommand for CmdAppVolumesCredentials {
let (_ident, app) = self.ident.load_app(&client).await?;
let creds =
wasmer_api::query::get_app_s3_credentials(&client, app.id.clone().into_inner()).await?;
wasmer_backend_api::query::get_app_s3_credentials(&client, app.id.clone().into_inner())
.await?;
match self.fmt.format {
CredsItemFormat::Rclone => {

View File

@ -28,7 +28,7 @@ impl AsyncCliCommand for CmdAppVolumesRotateSecrets {
let client = self.env.client()?;
let (_ident, app) = self.ident.load_app(&client).await?;
wasmer_api::query::rotate_s3_secrets(&client, app.id).await?;
wasmer_backend_api::query::rotate_s3_secrets(&client, app.id).await?;
// Don't print it here and leave it implied, so users can append the output
// of `wasmer app volumes credentials` without worrying about this message.

View File

@ -25,7 +25,8 @@ impl AsyncCliCommand for CmdAppVolumesList {
let (_ident, app) = self.ident.load_app(&client).await?;
let volumes =
wasmer_api::query::get_app_volumes(&client, &app.owner.global_name, &app.name).await?;
wasmer_backend_api::query::get_app_volumes(&client, &app.owner.global_name, &app.name)
.await?;
if volumes.is_empty() {
eprintln!("App {} has no volumes!", app.name);

View File

@ -10,7 +10,7 @@ use crate::{
};
use futures_util::{stream::FuturesUnordered, StreamExt};
use std::{path::PathBuf, time::Duration};
use wasmer_api::{types::Nonce, WasmerClient};
use wasmer_backend_api::{types::Nonce, WasmerClient};
#[derive(Debug, Clone)]
enum AuthorizationState {
@ -103,7 +103,7 @@ impl Login {
};
let Nonce { auth_url, .. } =
wasmer_api::query::create_nonce(client, "wasmer-cli".to_string(), server_url)
wasmer_backend_api::query::create_nonce(client, "wasmer-cli".to_string(), server_url)
.await?
.ok_or_else(|| {
anyhow::anyhow!("The backend did not return any nonce to auth the login!")
@ -166,29 +166,30 @@ impl Login {
async fn do_login(&self, env: &WasmerEnv) -> anyhow::Result<AuthorizationState> {
let client = env.client_unauthennticated()?;
let should_login = if let Some(user) = wasmer_api::query::current_user(&client).await? {
#[cfg(not(test))]
{
println!(
"You are already logged in as {} in registry {}.",
user.username.bold(),
env.registry_public_url()?.host_str().unwrap().bold()
);
let theme = dialoguer::theme::ColorfulTheme::default();
let dialog = dialoguer::Confirm::with_theme(&theme).with_prompt("Login again?");
let should_login =
if let Some(user) = wasmer_backend_api::query::current_user(&client).await? {
#[cfg(not(test))]
{
println!(
"You are already logged in as {} in registry {}.",
user.username.bold(),
env.registry_public_url()?.host_str().unwrap().bold()
);
let theme = dialoguer::theme::ColorfulTheme::default();
let dialog = dialoguer::Confirm::with_theme(&theme).with_prompt("Login again?");
dialog.interact()?
}
#[cfg(test)]
{
// prevent unused binding warning
_ = user;
dialog.interact()?
}
#[cfg(test)]
{
// prevent unused binding warning
_ = user;
false
}
} else {
true
};
false
}
} else {
true
};
if !should_login {
Ok(AuthorizationState::Cancelled)
@ -228,7 +229,7 @@ impl Login {
// This will automatically read the config again, picking up the new edits.
let client = env.client()?;
wasmer_api::query::current_user(&client)
wasmer_backend_api::query::current_user(&client)
.await?
.map(|v| v.username)
.ok_or_else(|| anyhow::anyhow!("Not logged in!"))

View File

@ -39,7 +39,7 @@ impl AsyncCliCommand for Logout {
.client()
.map_err(|_| anyhow::anyhow!("Not logged into registry {host_str}"))?;
let user = wasmer_api::query::current_user(&client)
let user = wasmer_backend_api::query::current_user(&client)
.await
.map_err(|e| anyhow::anyhow!("Not logged into registry {host_str}: {e}"))?
.ok_or_else(|| anyhow::anyhow!("Not logged into registry {host_str}"))?;
@ -92,7 +92,7 @@ impl AsyncCliCommand for Logout {
};
if should_revoke {
wasmer_api::query::revoke_token(&client, token).await?;
wasmer_backend_api::query::revoke_token(&client, token).await?;
println!(
"Token for user {} in registry {host_str} correctly revoked",
user.username.bold()

View File

@ -20,7 +20,7 @@ impl AsyncCliCommand for Whoami {
async fn run_async(self) -> Result<Self::Output, anyhow::Error> {
let client = self.env.client_unauthennticated()?;
let host_str = self.env.registry_public_url()?.host_str().unwrap().bold();
let user = wasmer_api::query::current_user(&client)
let user = wasmer_backend_api::query::current_user(&client)
.await?
.ok_or_else(|| anyhow::anyhow!("Not logged in registry {host_str}"))?;
println!(

View File

@ -273,7 +273,9 @@ impl GetOrSet {
config.registry.set_current_registry(&s.url).await;
let current_registry = config.registry.get_current_registry();
if let Ok(client) = env.client() {
if let Some(u) = wasmer_api::query::current_user(&client).await? {
if let Some(u) =
wasmer_backend_api::query::current_user(&client).await?
{
println!(
"Successfully logged into registry {current_registry:?} as user {u:?}"
);

View File

@ -19,7 +19,8 @@ impl AsyncCliCommand for CmdDomainGet {
async fn run_async(self) -> Result<(), anyhow::Error> {
let client = self.env.client()?;
if let Some(domain) = wasmer_api::query::get_domain_with_records(&client, self.name).await?
if let Some(domain) =
wasmer_backend_api::query::get_domain_with_records(&client, self.name).await?
{
println!("{}", self.fmt.format.render(&domain));
} else {

View File

@ -1,4 +1,4 @@
use wasmer_api::types::GetAllDomainsVariables;
use wasmer_backend_api::types::GetAllDomainsVariables;
use crate::{commands::AsyncCliCommand, config::WasmerEnv, opts::ListFormatOpts};
@ -21,7 +21,7 @@ impl AsyncCliCommand for CmdDomainList {
async fn run_async(self) -> Result<(), anyhow::Error> {
let client = self.env.client()?;
let domains = wasmer_api::query::get_all_domains(
let domains = wasmer_backend_api::query::get_all_domains(
&client,
GetAllDomainsVariables {
first: None,

View File

@ -27,7 +27,7 @@ impl AsyncCliCommand for CmdDomainRegister {
async fn run_async(self) -> Result<(), anyhow::Error> {
let client = self.env.client()?;
let domain = wasmer_api::query::register_domain(
let domain = wasmer_backend_api::query::register_domain(
&client,
self.name,
self.namespace,

View File

@ -39,7 +39,7 @@ impl AsyncCliCommand for CmdZoneFileGet {
async fn run_async(self) -> Result<(), anyhow::Error> {
let client = self.env.client()?;
if let Some(domain) =
wasmer_api::query::get_domain_zone_file(&client, self.domain_name).await?
wasmer_backend_api::query::get_domain_zone_file(&client, self.domain_name).await?
{
let zone_file_contents = domain.zone_file;
if let Some(zone_file_path) = self.zone_file_path {
@ -62,7 +62,7 @@ impl AsyncCliCommand for CmdZoneFileSync {
async fn run_async(self) -> Result<(), anyhow::Error> {
let data = std::fs::read(&self.zone_file_path).context("Unable to read file")?;
let zone_file_contents = String::from_utf8(data).context("Not a valid UTF-8 sequence")?;
let domain = wasmer_api::query::upsert_domain_from_zone_file(
let domain = wasmer_backend_api::query::upsert_domain_from_zone_file(
&self.env.client()?,
zone_file_contents,
!self.no_delete_missing_records,

View File

@ -396,7 +396,7 @@ async fn construct_manifest(
Some(n) => Some(n),
None => {
if let Ok(client) = env.client() {
if let Ok(Some(u)) = wasmer_api::query::current_user(&client).await {
if let Ok(Some(u)) = wasmer_backend_api::query::current_user(&client).await {
Some(u.username)
} else {
None

View File

@ -24,11 +24,11 @@ impl AsyncCliCommand for CmdNamespaceCreate {
async fn run_async(self) -> Result<(), anyhow::Error> {
let client = self.env.client()?;
let vars = wasmer_api::types::CreateNamespaceVars {
let vars = wasmer_backend_api::types::CreateNamespaceVars {
name: self.name.clone(),
description: self.description.clone(),
};
let namespace = wasmer_api::query::create_namespace(&client, vars).await?;
let namespace = wasmer_backend_api::query::create_namespace(&client, vars).await?;
println!("{}", self.fmt.get().render(&namespace));

View File

@ -22,7 +22,7 @@ impl AsyncCliCommand for CmdNamespaceGet {
async fn run_async(self) -> Result<(), anyhow::Error> {
let client = self.env.client()?;
let namespace = wasmer_api::query::get_namespace(&client, self.name)
let namespace = wasmer_backend_api::query::get_namespace(&client, self.name)
.await?
.context("namespace not found")?;

View File

@ -16,7 +16,7 @@ impl AsyncCliCommand for CmdNamespaceList {
async fn run_async(self) -> Result<(), anyhow::Error> {
let client = self.env.client()?;
let namespaces = wasmer_api::query::user_namespaces(&client).await?;
let namespaces = wasmer_backend_api::query::user_namespaces(&client).await?;
println!("{}", self.fmt.format.render(&namespaces));

View File

@ -11,7 +11,7 @@ use std::{
collections::BTreeMap,
path::{Path, PathBuf},
};
use wasmer_api::WasmerClient;
use wasmer_backend_api::WasmerClient;
use wasmer_config::package::{Manifest, NamedPackageIdent, PackageHash};
use wasmer_package::package::Package;
@ -51,7 +51,7 @@ pub(super) async fn upload(
let session_uri = {
let default_timeout_secs = Some(60 * 30);
let q = wasmer_api::query::get_signed_url_for_package_upload(
let q = wasmer_backend_api::query::get_signed_url_for_package_upload(
client,
default_timeout_secs,
Some(hash_str),

View File

@ -1,5 +1,5 @@
use futures::StreamExt;
use wasmer_api::{types::PackageVersionState, WasmerClient};
use wasmer_backend_api::{types::PackageVersionState, WasmerClient};
/// Different conditions that can be "awaited" when publishing a package.
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
@ -79,7 +79,7 @@ impl From<PublishWait> for WaitPackageState {
pub async fn wait_package(
client: &WasmerClient,
to_wait: PublishWait,
package_version_id: wasmer_api::types::Id,
package_version_id: wasmer_backend_api::types::Id,
timeout: humantime::Duration,
) -> anyhow::Result<()> {
if let PublishWait::None = to_wait {
@ -89,7 +89,8 @@ pub async fn wait_package(
let package_version_id = package_version_id.into_inner();
let mut stream =
wasmer_api::subscription::package_version_ready(client, &package_version_id).await?;
wasmer_backend_api::subscription::package_version_ready(client, &package_version_id)
.await?;
let mut state: WaitPackageState = to_wait.into();

View File

@ -109,7 +109,7 @@ impl PackageDownload {
let rt = tokio::runtime::Runtime::new()?;
let package = rt
.block_on(wasmer_api::query::get_package_version(
.block_on(wasmer_backend_api::query::get_package_version(
&client,
full_name.clone(),
version.clone(),
@ -147,7 +147,7 @@ impl PackageDownload {
let client = self.env.client_unauthennticated()?;
let rt = tokio::runtime::Runtime::new()?;
let pkg = rt.block_on(wasmer_api::query::get_package_release(&client, &hash.to_string()))?
let pkg = rt.block_on(wasmer_backend_api::query::get_package_release(&client, &hash.to_string()))?
.with_context(|| format!("Package with {hash} does not exist in the registry, or is not accessible"))?;
let ident = hash.to_string();

View File

@ -12,7 +12,7 @@ use crate::{
use colored::Colorize;
use is_terminal::IsTerminal;
use std::path::{Path, PathBuf};
use wasmer_api::WasmerClient;
use wasmer_backend_api::WasmerClient;
use wasmer_config::package::{Manifest, PackageIdent};
/// Publish (push and tag) a package to the registry.

View File

@ -7,7 +7,7 @@ use anyhow::Context;
use colored::Colorize;
use is_terminal::IsTerminal;
use std::path::{Path, PathBuf};
use wasmer_api::WasmerClient;
use wasmer_backend_api::WasmerClient;
use wasmer_config::package::{Manifest, PackageHash};
use wasmer_package::package::Package;
@ -78,7 +78,7 @@ impl PackagePush {
anyhow::bail!("No package namespace specified: use --namespace XXX");
}
let user = wasmer_api::query::current_user_with_namespaces(client, None).await?;
let user = wasmer_backend_api::query::current_user_with_namespaces(client, None).await?;
let owner = crate::utils::prompts::prompt_for_namespace(
"Choose a namespace to push the package to",
None,
@ -112,7 +112,7 @@ impl PackagePush {
}
async fn should_push(&self, client: &WasmerClient, hash: &PackageHash) -> anyhow::Result<bool> {
let res = wasmer_api::query::get_package_release(client, &hash.to_string()).await;
let res = wasmer_backend_api::query::get_package_release(client, &hash.to_string()).await;
tracing::info!("{:?}", res);
res.map(|p| p.is_none())
}
@ -140,7 +140,7 @@ impl PackagePush {
spinner_ok!(pb, "Package correctly uploaded");
let pb = make_spinner!(self.quiet, "Waiting for package to become available...");
match wasmer_api::query::push_package_release(
match wasmer_backend_api::query::push_package_release(
client,
name.as_deref(),
namespace,

View File

@ -13,7 +13,7 @@ use std::{
path::{Path, PathBuf},
str::FromStr,
};
use wasmer_api::WasmerClient;
use wasmer_backend_api::WasmerClient;
use wasmer_config::package::{
Manifest, NamedPackageId, NamedPackageIdent, PackageBuilder, PackageHash, PackageIdent,
};
@ -154,7 +154,7 @@ impl PackageTag {
client: &WasmerClient,
id: &NamedPackageId,
manifest: Option<&Manifest>,
package_release_id: &wasmer_api::types::Id,
package_release_id: &wasmer_backend_api::types::Id,
) -> anyhow::Result<()> {
tracing::info!(
"Tagging package with registry id {:?} and specifier {:?}",
@ -200,7 +200,7 @@ impl PackageTag {
None
};
let r = wasmer_api::query::tag_package_release(
let r = wasmer_backend_api::query::tag_package_release(
client,
maybe_description.as_deref(),
maybe_homepage.as_deref(),
@ -241,7 +241,7 @@ impl PackageTag {
client: &WasmerClient,
hash: &PackageHash,
check_package_exists: bool,
) -> anyhow::Result<wasmer_api::types::Id> {
) -> anyhow::Result<wasmer_backend_api::types::Id> {
let pb = make_spinner!(
self.quiet || check_package_exists,
"Checking if the package exists.."
@ -249,7 +249,9 @@ impl PackageTag {
tracing::debug!("Searching for package with hash: {hash}");
let pkg = match wasmer_api::query::get_package_release(client, &hash.to_string()).await? {
let pkg = match wasmer_backend_api::query::get_package_release(client, &hash.to_string())
.await?
{
Some(p) => p,
None => {
spinner_err!(pb, "The package is not in the registry!");
@ -366,7 +368,7 @@ impl PackageTag {
anyhow::bail!("No package namespace specified: use --namespace <package_namespace>");
}
let user = wasmer_api::query::current_user_with_namespaces(client, None).await?;
let user = wasmer_backend_api::query::current_user_with_namespaces(client, None).await?;
crate::utils::prompts::prompt_for_namespace("Choose a namespace", None, Some(&user))
}
@ -403,7 +405,7 @@ impl PackageTag {
format!("Checking if a version of {full_pkg_name} already exists..")
);
if let Some(registry_version) = wasmer_api::query::get_package_version(
if let Some(registry_version) = wasmer_backend_api::query::get_package_version(
client,
full_pkg_name.to_string(),
String::from("latest"),
@ -425,7 +427,7 @@ impl PackageTag {
// Must necessarily bump if there's a package with the chosen version with a different hash.
let must_bump = {
let maybe_pkg = wasmer_api::query::get_package_version(
let maybe_pkg = wasmer_backend_api::query::get_package_version(
client,
full_pkg_name.to_string(),
user_version.to_string(),
@ -590,7 +592,7 @@ impl PackageTag {
return Ok(false);
}
let pkg = wasmer_api::query::get_package_version(
let pkg = wasmer_backend_api::query::get_package_version(
client,
id.full_name.clone(),
id.version.to_string(),

View File

@ -1,7 +1,7 @@
//! Edge SSH command.
use anyhow::Context;
use wasmer_api::WasmerClient;
use wasmer_backend_api::WasmerClient;
use super::AsyncCliCommand;
use crate::{config::WasmerEnv, edge_config::EdgeConfig};
@ -122,7 +122,10 @@ async fn acquire_ssh_token(
/// Create a new token for SSH access through the backend API.
async fn create_ssh_token(client: &WasmerClient) -> Result<RawToken, anyhow::Error> {
wasmer_api::query::generate_deploy_config_token_raw(client, wasmer_api::query::TokenKind::SSH)
.await
.context("Could not create token for ssh access")
wasmer_backend_api::query::generate_deploy_config_token_raw(
client,
wasmer_backend_api::query::TokenKind::SSH,
)
.await
.context("Could not create token for ssh access")
}

View File

@ -3,7 +3,7 @@ use anyhow::{Context, Error};
use lazy_static::lazy_static;
use std::path::{Path, PathBuf};
use url::Url;
use wasmer_api::WasmerClient;
use wasmer_backend_api::WasmerClient;
lazy_static! {
pub static ref DEFAULT_WASMER_CLI_USER_AGENT: String =
@ -141,7 +141,7 @@ impl WasmerEnv {
let proxy = self.proxy()?;
let client = wasmer_api::WasmerClient::new_with_proxy(
let client = wasmer_backend_api::WasmerClient::new_with_proxy(
registry_url,
&DEFAULT_WASMER_CLI_USER_AGENT,
proxy,

View File

@ -4,7 +4,7 @@ pub use env::*;
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
use url::Url;
use wasmer_api::WasmerClient;
use wasmer_backend_api::WasmerClient;
pub static GLOBAL_CONFIG_FILE_NAME: &str = "wasmer.toml";
pub static DEFAULT_PROD_REGISTRY: &str = "https://registry.wasmer.io/graphql";
@ -123,7 +123,9 @@ fn endpoint_from_domain_name(domain_name: &str) -> String {
async fn test_if_registry_present(registry: &str) -> anyhow::Result<()> {
let client = WasmerClient::new(url::Url::parse(registry)?, &DEFAULT_WASMER_CLI_USER_AGENT)?;
wasmer_api::query::current_user(&client).await.map(|_| ())
wasmer_backend_api::query::current_user(&client)
.await
.map(|_| ())
}
#[derive(PartialEq, Eq, Copy, Clone)]

View File

@ -1,5 +1,5 @@
use comfy_table::Table;
use wasmer_api::types::{
use wasmer_backend_api::types::{
DeployApp, DeployAppVersion, Deployment, DnsDomain, DnsDomainWithRecords, Namespace,
};
@ -163,7 +163,7 @@ impl CliRender for DeployAppVersion {
}
}
impl CliRender for wasmer_api::types::AppVersionVolume {
impl CliRender for wasmer_backend_api::types::AppVersionVolume {
fn render_item_table(&self) -> String {
let mut table = Table::new();
table.add_rows([
@ -189,7 +189,7 @@ impl CliRender for wasmer_api::types::AppVersionVolume {
}
}
fn format_disk_size_opt(value: Option<wasmer_api::types::BigInt>) -> String {
fn format_disk_size_opt(value: Option<wasmer_backend_api::types::BigInt>) -> String {
let value = value.and_then(|x| {
let y: Option<u64> = x.0.try_into().ok();
y
@ -259,7 +259,7 @@ impl CliRender for Deployment {
}
}
impl CliRender for wasmer_api::types::NakedDeployment {
impl CliRender for wasmer_backend_api::types::NakedDeployment {
fn render_item_table(&self) -> String {
let mut table = Table::new();
table.add_rows([
@ -295,7 +295,7 @@ impl CliRender for wasmer_api::types::NakedDeployment {
}
}
impl CliRender for wasmer_api::types::AutobuildRepository {
impl CliRender for wasmer_backend_api::types::AutobuildRepository {
fn render_item_table(&self) -> String {
let mut table = Table::new();
table.add_rows([

View File

@ -2,7 +2,7 @@
//
// use anyhow::Context;
// use dialoguer::{theme::ColorfulTheme, Select};
// use wasmer_api::{types::UserWithNamespaces, WasmerClient};
// use wasmer_backend_api::{types::UserWithNamespaces, WasmerClient};
//
// use super::prompts::PackageCheckMode;
//
@ -77,7 +77,7 @@
// }
//
// pub struct PackageWizardOutput {
// pub api: Option<wasmer_api::types::Package>,
// pub api: Option<wasmer_backend_api::types::Package>,
// pub local_path: Option<PathBuf>,
// pub local_manifest: Option<wasmer_config::package::Manifest>,
// }

View File

@ -1,7 +1,7 @@
use anyhow::Context;
use colored::Colorize;
use dialoguer::{theme::ColorfulTheme, Select};
use wasmer_api::WasmerClient;
use wasmer_backend_api::WasmerClient;
use wasmer_config::package::NamedPackageIdent;
pub fn prompt_for_ident(message: &str, default: Option<&str>) -> Result<String, anyhow::Error> {
@ -90,7 +90,13 @@ pub async fn prompt_for_package(
default: Option<&str>,
check: Option<PackageCheckMode>,
client: Option<&WasmerClient>,
) -> Result<(NamedPackageIdent, Option<wasmer_api::types::Package>), anyhow::Error> {
) -> Result<
(
NamedPackageIdent,
Option<wasmer_backend_api::types::Package>,
),
anyhow::Error,
> {
loop {
let ident = prompt_for_package_ident(message, default)?;
@ -98,12 +104,16 @@ pub async fn prompt_for_package(
let api = client.expect("Check mode specified, but no API provided");
let pkg = if let Some(v) = ident.version_opt() {
wasmer_api::query::get_package_version(api, ident.full_name(), v.to_string())
.await
.context("could not query backend for package")?
.map(|p| p.package)
wasmer_backend_api::query::get_package_version(
api,
ident.full_name(),
v.to_string(),
)
.await
.context("could not query backend for package")?
.map(|p| p.package)
} else {
wasmer_api::query::get_package(api, ident.to_string())
wasmer_backend_api::query::get_package(api, ident.to_string())
.await
.context("could not query backend for package")?
};
@ -144,7 +154,7 @@ pub async fn prompt_for_package(
pub fn prompt_for_namespace(
message: &str,
default: Option<&str>,
user: Option<&wasmer_api::types::UserWithNamespaces>,
user: Option<&wasmer_backend_api::types::UserWithNamespaces>,
) -> Result<String, anyhow::Error> {
if let Some(user) = user {
let namespaces = user
@ -205,7 +215,8 @@ pub async fn prompt_new_app_name(
"WARN".bold().yellow()
)
} else if let Some(api) = &api {
let app = wasmer_api::query::get_app(api, namespace.to_string(), ident.clone()).await?;
let app = wasmer_backend_api::query::get_app(api, namespace.to_string(), ident.clone())
.await?;
eprint!("Checking name availability... ");
if app.is_some() {
eprintln!(
@ -237,7 +248,7 @@ pub async fn prompt_new_app_alias(
let ident = prompt_for_ident(message, default)?;
if let Some(api) = &api {
let app = wasmer_api::query::get_app_by_alias(api, ident.clone()).await?;
let app = wasmer_backend_api::query::get_app_by_alias(api, ident.clone()).await?;
eprintln!("Checking name availability...");
if app.is_some() {
eprintln!(