fix(dashboard): a refused supplier SBOM keeps its reason however the error wraps it (#1025)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m45s
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 20m53s
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m45s
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 20m53s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
This commit is contained in:
1 parent
58b2269c7a
commit
4205815945
1 file changed
+16
-3
@@ -160,10 +160,14 @@ pub enum SbomCheck {
|
||||
/// by the agent's code.
|
||||
pub const SBOM_REFUSED: &str = "supplier_sbom_refused:";
|
||||
|
||||
/// The agent's code of a refused supplier SBOM upload, from its error.
|
||||
/// The agent's code of a refused supplier SBOM upload, from its error: the
|
||||
/// lowercase word after [`SBOM_REFUSED`], whatever the error wraps it in.
|
||||
pub fn sbom_refusal_code(error: &str) -> Option<&str> {
|
||||
let at = error.find(SBOM_REFUSED)? + SBOM_REFUSED.len();
|
||||
error[at..].split_whitespace().next()
|
||||
let rest = &error[error.find(SBOM_REFUSED)? + SBOM_REFUSED.len()..];
|
||||
let end = rest
|
||||
.find(|c: char| !(c.is_ascii_lowercase() || c == '_'))
|
||||
.unwrap_or(rest.len());
|
||||
(end > 0).then(|| &rest[..end])
|
||||
}
|
||||
|
||||
/// Check a supplier SBOM before any target holds it, **streamed** to the
|
||||
@@ -666,6 +670,7 @@ pub async fn upload_target_artifact(
|
||||
file: dioxus::fullstack::FileStream,
|
||||
) -> Result<TargetResponse, ServerFnError> {
|
||||
let filename = file.file_name().to_string();
|
||||
let sbom = kind == "supplier_sbom";
|
||||
let part =
|
||||
reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(file)).file_name(filename);
|
||||
let mut form = reqwest::multipart::Form::new()
|
||||
@@ -685,6 +690,8 @@ pub async fn upload_target_artifact(
|
||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
||||
if !resp.status().is_success() {
|
||||
return Err(ServerFnError::new(match resp.status().as_u16() {
|
||||
// A supplier SBOM has its own, smaller limit.
|
||||
413 if sbom => format!("{SBOM_REFUSED}too_large"),
|
||||
413 => "file is larger than the 512 MiB upload limit".to_string(),
|
||||
415 => UNSUPPORTED_ARCHIVE.to_string(),
|
||||
422 => format!("{SBOM_REFUSED}{}", refusal_code(resp).await),
|
||||
@@ -948,6 +955,12 @@ mod tests {
|
||||
sbom_refusal_code("error running server function: supplier_sbom_refused:empty"),
|
||||
Some("empty")
|
||||
);
|
||||
// However the error is wrapped, only the code is taken.
|
||||
assert_eq!(
|
||||
sbom_refusal_code(r#"ServerError("supplier_sbom_refused:unknown_format")"#),
|
||||
Some("unknown_format")
|
||||
);
|
||||
assert_eq!(sbom_refusal_code("supplier_sbom_refused:"), None);
|
||||
assert_eq!(
|
||||
sbom_refusal_code("upload rejected by the agent (500)"),
|
||||
None
|
||||
|
||||
Reference in new issue
Block a user