coil_runtime/wasm/host/
principal.rs1use super::*;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub enum ExtensionPrincipal {
5 Anonymous,
6 User(String),
7 ServiceAccount(String),
8}
9
10impl ExtensionPrincipal {
11 pub fn anonymous() -> Self {
12 Self::Anonymous
13 }
14
15 pub fn user(id: impl Into<String>) -> Self {
16 Self::User(id.into())
17 }
18
19 pub fn service_account(id: impl Into<String>) -> Self {
20 Self::ServiceAccount(id.into())
21 }
22
23 pub(super) fn to_wasm_principal(&self) -> Result<PrincipalRef, WasmModelError> {
24 match self {
25 Self::Anonymous => Ok(PrincipalRef::anonymous()),
26 Self::User(id) => PrincipalRef::user(id.clone()),
27 Self::ServiceAccount(id) => PrincipalRef::service_account(id.clone()),
28 }
29 }
30}