From 793999c644d080343ead45705635e466ba7103f5 Mon Sep 17 00:00:00 2001 From: Andrey Strochuk <a.strochuk@picodata.io> Date: Fri, 6 Sep 2024 21:20:57 +0300 Subject: [PATCH] feat: add timeout() for AclOwned and DdlOwned --- sbroad-core/src/ir/node/acl.rs | 26 ++++++++++++++++++++++++++ sbroad-core/src/ir/node/ddl.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/sbroad-core/src/ir/node/acl.rs b/sbroad-core/src/ir/node/acl.rs index b75a9bc81..932414fcf 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 53f2b058b..fd3157337 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 { -- GitLab