From 5d5de15e0f97ab91523e666768ed406aacbf128a Mon Sep 17 00:00:00 2001 From: Marc 'risson' Schmitt Date: Sun, 1 Dec 2024 01:27:08 +0100 Subject: [PATCH] python impl Signed-off-by: Marc 'risson' Schmitt --- python-kadmin-rs/python/kadmin/__init__.py | 19 +++- python-kadmin-rs/python/kadmin/__init__.pyi | 10 ++ .../python/kadmin_local/__init__.py | 19 +++- .../python/kadmin_local/__init__.pyi | 10 ++ python-kadmin-rs/src/lib.rs | 91 +++++++++++++++++++ 5 files changed, 141 insertions(+), 8 deletions(-) diff --git a/python-kadmin-rs/python/kadmin/__init__.py b/python-kadmin-rs/python/kadmin/__init__.py index 97f0aea..d88fa8f 100644 --- a/python-kadmin-rs/python/kadmin/__init__.py +++ b/python-kadmin-rs/python/kadmin/__init__.py @@ -1,10 +1,21 @@ -from kadmin._lib import KAdmin, Policy, Principal, Params, DbArgs, __version__ +from kadmin._lib import ( + DbArgs, + KAdmin, + Params, + Policy, + Principal, + TlData, + TlDataEntry, + __version__, +) __all__ = ( - "__version__", + "DbArgs", "KAdmin", + "Params", "Policy", "Principal", - "Params", - "DbArgs", + "TlData", + "TlDataEntry", + "__version__", ) diff --git a/python-kadmin-rs/python/kadmin/__init__.pyi b/python-kadmin-rs/python/kadmin/__init__.pyi index 3f25125..7610364 100644 --- a/python-kadmin-rs/python/kadmin/__init__.pyi +++ b/python-kadmin-rs/python/kadmin/__init__.pyi @@ -58,6 +58,7 @@ class Policy: attributes: int max_life: datetime.timedelta | None max_renewable_life: datetime.timedelta | None + tl_data: TlData def modify(self, **kwargs) -> Policy: ... def delete(self) -> None: ... @@ -71,3 +72,12 @@ class Params: ... @final class DbArgs: ... + +@final +class TlDataEntry: + data_type: int + contents: list[int] + +@final +class TlData: + entries: list[TlDataEntry] diff --git a/python-kadmin-rs/python/kadmin_local/__init__.py b/python-kadmin-rs/python/kadmin_local/__init__.py index 3530145..27290fe 100644 --- a/python-kadmin-rs/python/kadmin_local/__init__.py +++ b/python-kadmin-rs/python/kadmin_local/__init__.py @@ -1,10 +1,21 @@ -from kadmin_local._lib import KAdmin, Policy, Principal, Params, DbArgs, __version__ +from kadmin_local._lib import ( + DbArgs, + KAdmin, + Params, + Policy, + Principal, + TlData, + TlDataEntry, + __version__, +) __all__ = ( - "__version__", + "DbArgs", "KAdmin", + "Params", "Policy", "Principal", - "Params", - "DbArgs", + "TlData", + "TlDataEntry", + "__version__", ) diff --git a/python-kadmin-rs/python/kadmin_local/__init__.pyi b/python-kadmin-rs/python/kadmin_local/__init__.pyi index 41c228e..ccb2b7d 100644 --- a/python-kadmin-rs/python/kadmin_local/__init__.pyi +++ b/python-kadmin-rs/python/kadmin_local/__init__.pyi @@ -37,6 +37,7 @@ class Policy: attributes: int max_life: datetime.timedelta | None max_renewable_life: datetime.timedelta | None + tl_data: TlData def modify(self, **kwargs) -> Policy: ... def delete(self) -> None: ... @@ -50,3 +51,12 @@ class Params: ... @final class DbArgs: ... + +@final +class TlDataEntry: + data_type: int + contents: list[int] + +@final +class TlData: + entries: list[TlDataEntry] diff --git a/python-kadmin-rs/src/lib.rs b/python-kadmin-rs/src/lib.rs index a56d438..1cda3c6 100644 --- a/python-kadmin-rs/src/lib.rs +++ b/python-kadmin-rs/src/lib.rs @@ -37,6 +37,7 @@ pub mod pykadmin { policy::Policy as KPolicy, principal::Principal as KPrincipal, sync::{KAdmin as KKAdmin, KAdminBuilder}, + tl_data::{TlData as KTlData, TlDataEntry as KTlDataEntry}, }; use pyo3::{ prelude::*, @@ -161,6 +162,67 @@ pub mod pykadmin { } } + /// A single TL-data entry + #[pyclass] + #[derive(Clone, Debug, Default)] + pub struct TlDataEntry { + /// TL-data type + /// + /// :type: int + #[pyo3(get, set)] + pub data_type: i16, + /// Entry contents + /// + /// :type: list[int] + #[pyo3(get, set)] + pub contents: Vec, + } + + impl From for TlDataEntry { + fn from(item: KTlDataEntry) -> Self { + Self { + data_type: item.data_type, + contents: item.contents, + } + } + } + + impl Into for TlDataEntry { + fn into(self) -> KTlDataEntry { + KTlDataEntry { + data_type: self.data_type, + contents: self.contents, + } + } + } + + /// TL-data entries + #[pyclass] + #[derive(Clone, Debug, Default)] + pub struct TlData { + /// TL-data entries + /// + /// :type: list[TlDataEntry] + #[pyo3(get, set)] + pub entries: Vec, + } + + impl From for TlData { + fn from(item: KTlData) -> Self { + Self { + entries: item.entries.into_iter().map(|e| e.into()).collect(), + } + } + } + + impl Into for TlData { + fn into(self) -> KTlData { + KTlData { + entries: self.entries.into_iter().map(|e| e.into()).collect(), + } + } + } + /// Interface to kadm5 /// /// This class has no constructor. Instead, use the `with_` methods @@ -296,6 +358,9 @@ pub mod pykadmin { if let Some(max_renewable_life) = kwargs.get_item("max_renewable_life")? { builder = builder.max_renewable_life(max_renewable_life.extract()?); } + if let Some(tl_data) = kwargs.get_item("tl_data")? { + builder = builder.tl_data(tl_data.extract::()?.into()); + } } Ok(Policy { inner: builder @@ -554,6 +619,9 @@ pub mod pykadmin { if let Some(max_renewable_life) = kwargs.get_item("max_renewable_life")? { modifier = modifier.max_renewable_life(max_renewable_life.extract()?); } + if let Some(tl_data) = kwargs.get_item("tl_data")? { + modifier = modifier.tl_data(tl_data.extract::()?.into()); + } Ok(Self { inner: modifier .modify(self.kadmin.deref()) @@ -859,6 +927,29 @@ pub mod pykadmin { let _ = std::mem::replace(&mut self.inner, policy); Ok(()) } + + /// Policy TL-data + /// + /// :getter: Get the TL-data + /// :setter: Set the TL-data. Completely overrides existing TL-data, make sure to re-use + /// the old ones + /// :type: TlData + #[getter] + pub fn get_tl_data(&self) -> TlData { + (*self.inner.tl_data()).clone().into() + } + + /// Ignored + #[setter] + pub fn set_tl_data(&mut self, tl_data: TlData) -> Result<()> { + let policy = self + .inner + .modifier() + .tl_data(tl_data.into()) + .modify(self.kadmin.deref())?; + let _ = std::mem::replace(&mut self.inner, policy); + Ok(()) + } } /// python-kadmin-rs exceptions