| 1638 | } |
| 1639 | |
| 1640 | fn parse_driver_config_json(value: &str) -> Result<prost_types::Struct> { |
| 1641 | let parsed: serde_json::Value = serde_json::from_str(value) |
| 1642 | .into_diagnostic() |
| 1643 | .wrap_err("--driver-config-json must be valid JSON")?; |
| 1644 | |
| 1645 | let serde_json::Value::Object(fields) = parsed else { |
| 1646 | return Err(miette!( |
| 1647 | "--driver-config-json must be a JSON object keyed by driver name" |
| 1648 | )); |
| 1649 | }; |
| 1650 | |
| 1651 | Ok(prost_types::Struct { |
| 1652 | fields: fields |
| 1653 | .into_iter() |
| 1654 | .map(|(key, value)| json_to_protobuf_value(value).map(|value| (key, value))) |
| 1655 | .collect::<Result<_>>()?, |
| 1656 | }) |
| 1657 | } |
| 1658 | |
| 1659 | fn json_to_protobuf_value(value: serde_json::Value) -> Result<prost_types::Value> { |
| 1660 | use prost_types::{ListValue, Struct, Value, value::Kind}; |