Skip to main content

zaun_client/bots/
source.rs

1//! Installs and updates from a registry: the package with the signed catalog it was listed in,
2//! so the host can confirm where the bot came from (`source` on the bot card).
3
4use zaun_community_protocol::command::bot::{self, GrantChoice, Install, InstallSource};
5use zaun_community_protocol::command::object::BotCard;
6use zaun_community_protocol::ids::{AttachmentId, BotId};
7
8use crate::error::Result;
9use crate::objects::Community;
10
11impl Community {
12    /// Owner only: [`install_bot`](Self::install_bot) with the registry `source` the package
13    /// was verified against: the uploaded `catalog.json`, its signature and, for a version not
14    /// in the catalog's `latest`, the uploaded history file. The host checks the source
15    /// offline against its own registry keys; one that does not verify installs as `direct`.
16    ///
17    /// # Errors
18    /// As [`install_bot`](Self::install_bot), and `BAD_REQUEST` for a source that repeats an
19    /// attachment or has a blank signature.
20    pub fn install_bot_from(
21        &self,
22        package: AttachmentId,
23        grants: Option<GrantChoice>,
24        role_position: Option<u32>,
25        source: InstallSource,
26    ) -> Result<BotCard> {
27        let body = Install {
28            package,
29            grants,
30            role_position,
31            source: Some(source),
32        };
33        self.client.command(self.id, None, body)
34    }
35
36    /// Owner only: [`update_bot`](Self::update_bot) with the registry `source` the new package
37    /// was verified against, as for [`install_bot_from`](Self::install_bot_from).
38    ///
39    /// # Errors
40    /// As [`install_bot_from`](Self::install_bot_from).
41    pub fn update_bot_from(
42        &self,
43        bot: BotId,
44        package: AttachmentId,
45        source: InstallSource,
46    ) -> Result<BotCard> {
47        let body = bot::Update {
48            bot_id: bot,
49            package,
50            source: Some(source),
51        };
52        self.client.command(self.id, None, body)
53    }
54}