Skip to content

Commit

Permalink
fix(cli): Fix app resolution - respect owner in config
Browse files Browse the repository at this point in the history
The backend refactor that removed global aliases was not fully reflected
in the CLI, breaking "wasmer app get" and similar commands that all back
the reading the local app.yaml file.

This commit

* Removes the `Alias` variant of AppIdent, since there conceptually are no global
  aliases anymore, just domains

* Makes the resolution respect the `owner` in the config

* Falls back to trying to get the app by name with the current user as
  the owner
  • Loading branch information
theduke committed Jun 8, 2024
1 parent 0bf8682 commit 10d3c33
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/cli/src/commands/app/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum AppIdent {
/// Backend app VERSION id like "dav_xxysw34234"
AppVersionId(String),
NamespacedName(String, String),
Alias(String),
Name(String),
}

impl AppIdent {
Expand All @@ -40,9 +40,18 @@ impl AppIdent {
.with_context(|| format!("Could not query for app version id '{}'", id))?;
Ok(app)
}
AppIdent::Alias(name) => wasmer_api::query::get_app_by_alias(client, name.clone())
.await?
.with_context(|| format!("Could not find app with name '{name}'")),
AppIdent::Name(name) => {
// 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)
.await?
.context("not logged in")?;

wasmer_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())
.await?
Expand Down Expand Up @@ -80,7 +89,7 @@ impl std::str::FromStr for AppIdent {
}
}
} else {
Ok(Self::Alias(s.to_string()))
Ok(Self::Name(s.to_string()))
}
}
}
Expand Down Expand Up @@ -160,8 +169,10 @@ impl AppIdentOpts {

let ident = if let Some(id) = &config.app_id {
AppIdent::AppId(id.clone())
} else if let Some(owner) = &config.owner {
AppIdent::NamespacedName(owner.clone(), config.name.clone())
} else {
AppIdent::Alias(config.name.clone())
AppIdent::Name(config.name.clone())
};

Ok(ResolvedAppIdent::Config {
Expand Down Expand Up @@ -197,7 +208,7 @@ mod tests {
);
assert_eq!(
AppIdent::from_str("lala").unwrap(),
AppIdent::Alias("lala".to_string()),
AppIdent::Name("lala".to_string()),
);

assert_eq!(
Expand Down

0 comments on commit 10d3c33

Please sign in to comment.