agents get a per-agent repo limit in their permissions record, orgs are locked
max_repos (default 0, 0..=100) lives in the agent's agent-permissions record and is edited on its permissions panel. The controller applies each agent's own value as max_repo_creation at CreateForgeUser and to existing accounts on change, restart and every five minutes; agent accounts may not create organizations.
This commit is contained in:
parent
dc0d08b7fb
commit
1edeb5c55d
1 changed files with 763 additions and 58 deletions
|
|
@ -91,8 +91,21 @@ pub struct AgentPermissions {
|
|||
/// `swarm_queue_client::agent_permissions::internet_mode`.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub internet_log: Option<bool>,
|
||||
/// How many repositories the agent's forge account may create, 0 to
|
||||
/// [`MAX_REPOS`]. Absent is [`DEFAULT_MAX_REPOS`]. Only the controller
|
||||
/// reads it: it sets the account's `max_repo_creation` from it. No hive
|
||||
/// or agent acts on it.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub max_repos: Option<u32>,
|
||||
}
|
||||
|
||||
/// What an agent whose record has no `max_repos` may create: no repositories.
|
||||
pub const DEFAULT_MAX_REPOS: u32 = 0;
|
||||
|
||||
/// The most `max_repos` may be set to. Forgejo reads `-1` as "the instance
|
||||
/// default", which is unlimited, so the range stops short of it on purpose.
|
||||
pub const MAX_REPOS: u32 = 100;
|
||||
|
||||
/// What a hive sends once: the permissions its meta repo held, by agent.
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Import {
|
||||
|
|
@ -218,4 +231,24 @@ mod tests {
|
|||
serde_json::from_str(r#"{"unrestricted_internet":false}"#).unwrap();
|
||||
assert_eq!(before.internet_log, None);
|
||||
}
|
||||
|
||||
/// The repository limit is left out when unset, so a record that never
|
||||
/// named it encodes as before; a negative number (Forgejo's "unlimited")
|
||||
/// does not decode.
|
||||
#[test]
|
||||
fn the_repo_limit_is_left_out_unless_set() {
|
||||
let three = AgentPermissions {
|
||||
max_repos: Some(3),
|
||||
..AgentPermissions::default()
|
||||
};
|
||||
let wire = r#"{"max_repos":3}"#;
|
||||
assert_eq!(serde_json::to_string(&three).unwrap(), wire);
|
||||
assert_eq!(
|
||||
serde_json::from_str::<AgentPermissions>(wire).unwrap(),
|
||||
three
|
||||
);
|
||||
let unset: AgentPermissions = serde_json::from_str("{}").unwrap();
|
||||
assert_eq!(unset.max_repos, None);
|
||||
assert!(serde_json::from_str::<AgentPermissions>(r#"{"max_repos":-1}"#).is_err());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue