swarmctl shares the create-agent, inference and permissions shapes with the controller
This commit is contained in:
parent
249aab6642
commit
0831b85b73
26 changed files with 675 additions and 434 deletions
50
swarm-controller-api/src/permissions.rs
Normal file
50
swarm-controller-api/src/permissions.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
//! `/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());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue