Skip to content

Commit

Permalink
make AppConfig.name optional in wasmer-config (#5305)
Browse files Browse the repository at this point in the history
  • Loading branch information
maminrayej authored Dec 17, 2024
2 parents 32923c8 + 73122f1 commit 5708ca8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "User-facing app.yaml config file for apps.\n\nNOTE: only used by the backend, Edge itself does not use this format, and uses [`super::AppVersionV1Spec`] instead.",
"type": "object",
"required": [
"name",
"package"
],
"properties": {
Expand Down Expand Up @@ -81,7 +80,10 @@
},
"name": {
"description": "Name of the app.",
"type": "string"
"type": [
"string",
"null"
]
},
"owner": {
"description": "Owner of the app.\n\nThis is either a username or a namespace.",
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/commands/app/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl CmdAppCreate {
#[inline]
fn get_app_config(&self, owner: &str, name: &str, package: &str) -> AppConfigV1 {
AppConfigV1 {
name: String::from(name),
name: Some(String::from(name)),
owner: Some(String::from(owner)),
package: PackageSource::from_str(package).unwrap(),
app_id: None,
Expand Down
17 changes: 14 additions & 3 deletions lib/cli/src/commands/app/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,20 @@ impl AsyncCliCommand for CmdAppDeploy {
let app = &opts.app;

let pretty_name = if let Some(owner) = &owner {
format!("{} ({})", app.name.bold(), owner.bold())
format!(
"{} ({})",
app.name
.as_ref()
.context("App name has to be specified")?
.bold(),
owner.bold()
)
} else {
app.name.bold().to_string()
app.name
.as_ref()
.context("App name has to be specified")?
.bold()
.to_string()
};

if !self.quiet {
Expand Down Expand Up @@ -629,7 +640,7 @@ pub async fn deploy_app(
client,
wasmer_backend_api::types::PublishDeployAppVars {
config: raw_config,
name: app.name.clone().into(),
name: app.name.clone().context("Expected an app name")?.into(),
owner: opts.owner.map(|o| o.into()),
make_default: Some(opts.make_default),
},
Expand Down
19 changes: 14 additions & 5 deletions lib/cli/src/commands/app/secrets/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub(crate) mod render;

use anyhow::Context;
use colored::Colorize;
use std::{
env::current_dir,
Expand Down Expand Up @@ -112,9 +112,15 @@ pub(super) async fn get_app_id(
let (app, _) = r;

let app_name = if let Some(owner) = &app.owner {
format!("{owner}/{}", app.name)
format!(
"{owner}/{}",
&app.name.clone().context("App name has to be specified")?
)
} else {
app.name.to_string()
app.name
.clone()
.context("App name has to be specified")?
.to_string()
};

let id = if let Some(id) = &app.app_id {
Expand All @@ -140,10 +146,13 @@ pub(super) async fn get_app_id(
if let Some(owner) = &app.owner {
eprintln!(
"Managing secrets related to app {} ({owner}).",
app.name.bold()
app.name.context("App name has to be specified")?.bold()
);
} else {
eprintln!("Managing secrets related to app {}.", app.name.bold());
eprintln!(
"Managing secrets related to app {}.",
app.name.context("App name has to be specified")?.bold()
);
}
}
return Ok(id);
Expand Down
7 changes: 5 additions & 2 deletions lib/cli/src/commands/app/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ 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())
AppIdent::NamespacedName(
owner.clone(),
config.name.clone().context("App name was not specified")?,
)
} else {
AppIdent::Name(config.name.clone())
AppIdent::Name(config.name.clone().context("App name was not specified")?)
};

Ok(ResolvedAppIdent::Config {
Expand Down
4 changes: 2 additions & 2 deletions lib/config/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub const HEADER_APP_VERSION_ID: &str = "x-edge-app-version-id";
)]
pub struct AppConfigV1 {
/// Name of the app.
pub name: String,
pub name: Option<String>,

/// App id assigned by the backend.
///
Expand Down Expand Up @@ -310,7 +310,7 @@ scheduled_tasks:
assert_eq!(
parsed,
AppConfigV1 {
name: "test".to_string(),
name: Some("test".to_string()),
app_id: None,
package: "ns/[email protected]".parse().unwrap(),
owner: None,
Expand Down

0 comments on commit 5708ca8

Please sign in to comment.