50 lines
1.7 KiB
Rust
50 lines
1.7 KiB
Rust
//! `/api/agents/{name}/permissions`, and the `permissions` of
|
|
//! `POST /api/agents`.
|
|
|
|
use hive_types::Permission;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// One agent's permissions. A field left out is not set by the swarm, and the
|
|
/// compiled-in default applies; an empty list grants nothing.
|
|
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[cfg_attr(feature = "schema", derive(utoipa::ToSchema))]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct Permissions {
|
|
/// Permission names, `snake_case`: `messaging`, `meta`, `inbox`,
|
|
/// `execution`, `web_tools`, `manage_root_agent`.
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
#[cfg_attr(
|
|
feature = "schema",
|
|
schema(value_type = Option<Vec<String>>, example = json!(["messaging", "meta", "inbox", "execution"]))
|
|
)]
|
|
pub permissions: Option<Vec<Permission>>,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::Permissions;
|
|
use hive_types::Permission;
|
|
|
|
#[test]
|
|
fn permissions_round_trip() {
|
|
for (value, wire) in [
|
|
(Permissions::default(), "{}"),
|
|
(
|
|
Permissions {
|
|
permissions: Some(vec![]),
|
|
},
|
|
r#"{"permissions":[]}"#,
|
|
),
|
|
(
|
|
Permissions {
|
|
permissions: Some(vec![Permission::Messaging, Permission::ManageRootAgent]),
|
|
},
|
|
r#"{"permissions":["messaging","manage_root_agent"]}"#,
|
|
),
|
|
] {
|
|
assert_eq!(serde_json::to_string(&value).unwrap(), wire);
|
|
assert_eq!(serde_json::from_str::<Permissions>(wire).unwrap(), value);
|
|
}
|
|
assert!(serde_json::from_str::<Permissions>(r#"{"permissions":["fly"]}"#).is_err());
|
|
}
|
|
}
|