Skip to content

Commit 10d3c33

Browse files
committed
fix(cli): Fix app resolution - respect owner in config
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
1 parent 0bf8682 commit 10d3c33

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

lib/cli/src/commands/app/util.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub enum AppIdent {
2323
/// Backend app VERSION id like "dav_xxysw34234"
2424
AppVersionId(String),
2525
NamespacedName(String, String),
26-
Alias(String),
26+
Name(String),
2727
}
2828

2929
impl AppIdent {
@@ -40,9 +40,18 @@ impl AppIdent {
4040
.with_context(|| format!("Could not query for app version id '{}'", id))?;
4141
Ok(app)
4242
}
43-
AppIdent::Alias(name) => wasmer_api::query::get_app_by_alias(client, name.clone())
44-
.await?
45-
.with_context(|| format!("Could not find app with name '{name}'")),
43+
AppIdent::Name(name) => {
44+
// The API only allows to query by owner + name,
45+
// so default to the current user as the owner.
46+
// To to so the username must first be retrieved.
47+
let user = wasmer_api::query::current_user(client)
48+
.await?
49+
.context("not logged in")?;
50+
51+
wasmer_api::query::get_app(client, user.username, name.clone())
52+
.await?
53+
.with_context(|| format!("Could not find app with name '{name}'"))
54+
}
4655
AppIdent::NamespacedName(owner, name) => {
4756
wasmer_api::query::get_app(client, owner.clone(), name.clone())
4857
.await?
@@ -80,7 +89,7 @@ impl std::str::FromStr for AppIdent {
8089
}
8190
}
8291
} else {
83-
Ok(Self::Alias(s.to_string()))
92+
Ok(Self::Name(s.to_string()))
8493
}
8594
}
8695
}
@@ -160,8 +169,10 @@ impl AppIdentOpts {
160169

161170
let ident = if let Some(id) = &config.app_id {
162171
AppIdent::AppId(id.clone())
172+
} else if let Some(owner) = &config.owner {
173+
AppIdent::NamespacedName(owner.clone(), config.name.clone())
163174
} else {
164-
AppIdent::Alias(config.name.clone())
175+
AppIdent::Name(config.name.clone())
165176
};
166177

167178
Ok(ResolvedAppIdent::Config {
@@ -197,7 +208,7 @@ mod tests {
197208
);
198209
assert_eq!(
199210
AppIdent::from_str("lala").unwrap(),
200-
AppIdent::Alias("lala".to_string()),
211+
AppIdent::Name("lala".to_string()),
201212
);
202213

203214
assert_eq!(

0 commit comments

Comments
 (0)