diff --git a/sbroad-core/src/ir/node/acl.rs b/sbroad-core/src/ir/node/acl.rs index b75a9bc813e38a9b6c480f4c86c56cd25447bfb4..932414fcf78709ec9789b728f891ae70cb447b23 100644 --- a/sbroad-core/src/ir/node/acl.rs +++ b/sbroad-core/src/ir/node/acl.rs @@ -20,6 +20,32 @@ pub enum AclOwned { RevokePrivilege(RevokePrivilege), } +impl AclOwned { + /// Return ACL node timeout. + /// + /// # Errors + /// - timeout parsing error + pub fn timeout(&self) -> Result<f64, SbroadError> { + match self { + AclOwned::DropRole(DropRole { ref timeout, .. }) + | AclOwned::DropUser(DropUser { ref timeout, .. }) + | AclOwned::CreateRole(CreateRole { ref timeout, .. }) + | AclOwned::AlterUser(AlterUser { ref timeout, .. }) + | AclOwned::CreateUser(CreateUser { ref timeout, .. }) + | AclOwned::RevokePrivilege(RevokePrivilege { ref timeout, .. }) + | AclOwned::GrantPrivilege(GrantPrivilege { ref timeout, .. }) => timeout, + } + .to_smolstr() + .parse() + .map_err(|e| { + SbroadError::Invalid( + Entity::SpaceMetadata, + Some(format_smolstr!("timeout parsing error {e:?}")), + ) + }) + } +} + impl From<AclOwned> for SizeNode { fn from(value: AclOwned) -> Self { match value { diff --git a/sbroad-core/src/ir/node/ddl.rs b/sbroad-core/src/ir/node/ddl.rs index 53f2b058be454b0e9deb2a1dd7e372d04c0d9e3c..fd31573371c044098a3bc8460ca3d91c3d274a07 100644 --- a/sbroad-core/src/ir/node/ddl.rs +++ b/sbroad-core/src/ir/node/ddl.rs @@ -23,6 +23,35 @@ pub enum DdlOwned { SetTransaction(SetTransaction), } +impl DdlOwned { + /// Return DDL node timeout. + /// + /// # Errors + /// - timeout parsing error + pub fn timeout(&self) -> Result<f64, SbroadError> { + match self { + DdlOwned::CreateTable(CreateTable { ref timeout, .. }) + | DdlOwned::DropTable(DropTable { ref timeout, .. }) + | DdlOwned::CreateIndex(CreateIndex { ref timeout, .. }) + | DdlOwned::DropIndex(DropIndex { ref timeout, .. }) + | DdlOwned::SetParam(SetParam { ref timeout, .. }) + | DdlOwned::SetTransaction(SetTransaction { ref timeout, .. }) + | DdlOwned::AlterSystem(AlterSystem { ref timeout, .. }) + | DdlOwned::CreateProc(CreateProc { ref timeout, .. }) + | DdlOwned::DropProc(DropProc { ref timeout, .. }) + | DdlOwned::RenameRoutine(RenameRoutine { ref timeout, .. }) => timeout, + } + .to_smolstr() + .parse() + .map_err(|e| { + SbroadError::Invalid( + Entity::SpaceMetadata, + Some(format_smolstr!("timeout parsing error {e:?}")), + ) + }) + } +} + impl From<DdlOwned> for SizeNode { fn from(value: DdlOwned) -> Self { match value {