Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions rust/agama-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ pub async fn run(subcommand: ConfigCommands, opts: GlobalOpts) -> anyhow::Result
destination.write(&json)?;

eprintln!();
validate(&http_client, CliInput::Full(json.clone())).await?;
validate(&http_client, CliInput::Full(json.clone()), false).await?;
Ok(())
}
ConfigCommands::Load { url_or_path } => {
let (http_client, monitor) = build_clients(api_url, opts.insecure).await?;
let store = SettingsStore::new(http_client.clone()).await?;
let url_or_path = url_or_path.unwrap_or(CliInput::Stdin);
let contents = url_or_path.read_to_string(opts.insecure)?;
let valid = validate(&http_client, CliInput::Full(contents.clone())).await?;
let valid = validate(&http_client, CliInput::Full(contents.clone()), false).await?;

if matches!(valid, ValidationOutcome::Valid) {
let result =
Expand All @@ -141,7 +141,7 @@ pub async fn run(subcommand: ConfigCommands, opts: GlobalOpts) -> anyhow::Result
ConfigCommands::Validate { url_or_path, local } => {
let _ = if !local {
let (http_client, _monitor) = build_clients(api_url, opts.insecure).await?;
validate(&http_client, url_or_path).await
validate(&http_client, url_or_path, false).await
} else {
validate_local(url_or_path, opts.insecure)
};
Expand Down Expand Up @@ -193,24 +193,19 @@ fn validate_local(url_or_path: CliInput, insecure: bool) -> anyhow::Result<Valid
}
}

async fn validate_silently(
async fn validate(
client: &BaseHTTPClient,
url_or_path: CliInput,
silent: bool,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I do not like that validate() takes care of printing anything. And adding a silent argument does not make it any better.

However, let's consider that for a future refactoring during the api-v2 adoption.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate this function. I was circling around it and tried several approaches and disliked them all :-/

) -> anyhow::Result<ValidationOutcome> {
let request = url_or_path.to_map();
let validity = ProfileHTTPClient::new(client.clone())
.validate(&request)
.await?;

Ok(validity)
}

async fn validate(
client: &BaseHTTPClient,
url_or_path: CliInput,
) -> anyhow::Result<ValidationOutcome> {
let validity = validate_silently(client, url_or_path).await?;
let _ = validation_msg(&validity);
if !silent {
let _ = validation_msg(&validity);
}

Ok(validity)
}
Expand Down Expand Up @@ -284,7 +279,7 @@ async fn generate(
from_json_or_jsonnet(client, url_or_path, insecure).await?
};

let validity = validate_silently(client, CliInput::Full(profile_json.clone())).await?;
let validity = validate(client, CliInput::Full(profile_json.clone()), true).await?;

if matches!(validity, ValidationOutcome::NotValid(_)) {
println!("{}", &profile_json);
Expand All @@ -298,7 +293,7 @@ async fn generate(
let config_json = serde_json::to_string_pretty(&model)?;

println!("{}", &config_json);
let validity = validate(client, CliInput::Full(config_json.clone())).await?;
let validity = validate(client, CliInput::Full(config_json.clone()), false).await?;

if matches!(validity, ValidationOutcome::NotValid(_)) {
eprintln!(
Expand Down Expand Up @@ -365,7 +360,7 @@ async fn edit(
// FIXME: invalid profile still gets loaded
let contents =
std::fs::read_to_string(&path).context(format!("Reading from file {:?}", path))?;
validate(&http_client, CliInput::Full(contents)).await?;
validate(&http_client, CliInput::Full(contents), false).await?;
return Ok(InstallSettings::from_file(
path,
&InstallationContext::from_env()?,
Expand Down
4 changes: 3 additions & 1 deletion rust/agama-lib/src/profile/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ impl ProfileHTTPClient {
/// to our web backend.
/// Return well-formed Agama JSON on success.
pub async fn from_autoyast(&self, url: &Uri<String>) -> anyhow::Result<String> {
let map = HashMap::new().insert(String::from("url"), url.to_string());
let mut map = HashMap::new();

map.insert(String::from("url"), url.to_string());

// FIXME: how to escape it?
let output: Box<serde_json::value::RawValue> =
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-server/src/profile/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl ProfileBody {
/// Expected format is a HashMap<String, String>, expecte keys are
/// path, url or profile
fn from_string(string: String) -> Self {
let map: HashMap<String, String> = serde_json::from_str(&string).unwrap();
let map: HashMap<String, String> = serde_json::from_str(&string).unwrap_or_default();

Self {
path: map.get("path").cloned(),
Expand Down
8 changes: 8 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Tue Nov 18 08:47:11 UTC 2025 - Michal Filka <mfilka@suse.com>

- Fixed passing arguments when "agama config generate" with an
AutoYast profile.
- Removed unhandled unwrap, reorganized validation result reporting
(gh#agama-project/agama#2893).

-------------------------------------------------------------------
Wed Nov 12 15:42:27 UTC 2025 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
Loading