rightkit_daemon/contract/
caller.rs1use crate::peer::PeerIdentity;
2use std::collections::BTreeSet;
3
4pub type Scope = String;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum Caller {
10 LocalApp { app: String, peer: PeerIdentity },
13 Device { id: String, scopes: BTreeSet<Scope> },
15}
16
17impl Caller {
18 pub fn local_app(app: impl Into<String>, peer: PeerIdentity) -> Self {
19 Caller::LocalApp {
20 app: app.into(),
21 peer,
22 }
23 }
24
25 pub fn device<I, S>(id: impl Into<String>, scopes: I) -> Self
26 where
27 I: IntoIterator<Item = S>,
28 S: Into<Scope>,
29 {
30 Caller::Device {
31 id: id.into(),
32 scopes: scopes.into_iter().map(Into::into).collect(),
33 }
34 }
35
36 pub fn peer(&self) -> Option<&PeerIdentity> {
38 match self {
39 Caller::LocalApp { peer, .. } => Some(peer),
40 Caller::Device { .. } => None,
41 }
42 }
43
44 pub fn label(&self) -> &str {
46 match self {
47 Caller::LocalApp { app, .. } => app,
48 Caller::Device { id, .. } => id,
49 }
50 }
51}