mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-03 11:18:31 +00:00
Merge pull request #4822 from wasmerio/issue-4818-app-get-owner
fix(cli): Respect owner in app.yaml during app resolution
This commit is contained in:
@@ -164,7 +164,15 @@ pub async fn tag_package_release(
|
||||
.map(|r| r.tag_package_release)
|
||||
}
|
||||
|
||||
/// Get the currently logged in used, together with all accessible namespaces.
|
||||
/// Get the currently logged in user.
|
||||
pub async fn current_user(client: &WasmerClient) -> Result<Option<types::User>, anyhow::Error> {
|
||||
client
|
||||
.run_graphql(types::GetCurrentUser::build(()))
|
||||
.await
|
||||
.map(|x| x.viewer)
|
||||
}
|
||||
|
||||
/// Get the currently logged in user, together with all accessible namespaces.
|
||||
///
|
||||
/// You can optionally filter the namespaces by the user role.
|
||||
pub async fn current_user_with_namespaces(
|
||||
@@ -172,9 +180,9 @@ pub async fn current_user_with_namespaces(
|
||||
namespace_role: Option<types::GrapheneRole>,
|
||||
) -> Result<types::UserWithNamespaces, anyhow::Error> {
|
||||
client
|
||||
.run_graphql(types::GetCurrentUser::build(types::GetCurrentUserVars {
|
||||
namespace_role,
|
||||
}))
|
||||
.run_graphql(types::GetCurrentUserWithNamespaces::build(
|
||||
types::GetCurrentUserWithNamespacesVars { namespace_role },
|
||||
))
|
||||
.await?
|
||||
.viewer
|
||||
.context("not logged in")
|
||||
@@ -544,9 +552,11 @@ pub async fn user_accessible_apps(
|
||||
|
||||
// Get all aps in user-accessible namespaces.
|
||||
let namespace_res = client
|
||||
.run_graphql(types::GetCurrentUser::build(types::GetCurrentUserVars {
|
||||
namespace_role: None,
|
||||
}))
|
||||
.run_graphql(types::GetCurrentUserWithNamespaces::build(
|
||||
types::GetCurrentUserWithNamespacesVars {
|
||||
namespace_role: None,
|
||||
},
|
||||
))
|
||||
.await?;
|
||||
let active_user = namespace_res.viewer.context("not logged in")?;
|
||||
let namespace_names = active_user
|
||||
@@ -655,9 +665,11 @@ pub async fn user_namespaces(
|
||||
client: &WasmerClient,
|
||||
) -> Result<Vec<types::Namespace>, anyhow::Error> {
|
||||
let user = client
|
||||
.run_graphql(types::GetCurrentUser::build(types::GetCurrentUserVars {
|
||||
namespace_role: None,
|
||||
}))
|
||||
.run_graphql(types::GetCurrentUserWithNamespaces::build(
|
||||
types::GetCurrentUserWithNamespacesVars {
|
||||
namespace_role: None,
|
||||
},
|
||||
))
|
||||
.await?
|
||||
.viewer
|
||||
.context("not logged in")?;
|
||||
|
||||
@@ -41,14 +41,20 @@ mod queries {
|
||||
Viewer,
|
||||
}
|
||||
|
||||
#[derive(cynic::QueryFragment, Debug)]
|
||||
#[cynic(graphql_type = "Query")]
|
||||
pub struct GetCurrentUser {
|
||||
pub viewer: Option<User>,
|
||||
}
|
||||
|
||||
#[derive(cynic::QueryVariables, Debug)]
|
||||
pub struct GetCurrentUserVars {
|
||||
pub struct GetCurrentUserWithNamespacesVars {
|
||||
pub namespace_role: Option<GrapheneRole>,
|
||||
}
|
||||
|
||||
#[derive(cynic::QueryFragment, Debug)]
|
||||
#[cynic(graphql_type = "Query", variables = "GetCurrentUserVars")]
|
||||
pub struct GetCurrentUser {
|
||||
#[cynic(graphql_type = "Query", variables = "GetCurrentUserWithNamespacesVars")]
|
||||
pub struct GetCurrentUserWithNamespaces {
|
||||
pub viewer: Option<UserWithNamespaces>,
|
||||
}
|
||||
|
||||
@@ -447,7 +453,7 @@ mod queries {
|
||||
}
|
||||
|
||||
#[derive(cynic::QueryFragment, Debug, Clone, Serialize)]
|
||||
#[cynic(graphql_type = "User", variables = "GetCurrentUserVars")]
|
||||
#[cynic(graphql_type = "User", variables = "GetCurrentUserWithNamespacesVars")]
|
||||
pub struct UserWithNamespaces {
|
||||
pub id: cynic::Id,
|
||||
pub username: String,
|
||||
|
||||
@@ -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 {
|
||||
@@ -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?
|
||||
@@ -80,7 +89,7 @@ impl std::str::FromStr for AppIdent {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Ok(Self::Alias(s.to_string()))
|
||||
Ok(Self::Name(s.to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
@@ -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!(
|
||||
|
||||
Reference in New Issue
Block a user