]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common/ceph/smb: add file with basic config classes
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 1 Apr 2026 22:22:54 +0000 (18:22 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 27 May 2026 18:26:53 +0000 (14:26 -0400)
Add a file with the basic configuration classes and functions needed to
set up a connection with the remote-control grpc server for SMB.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/python-common/ceph/smb/ctl/config.py [new file with mode: 0644]

diff --git a/src/python-common/ceph/smb/ctl/config.py b/src/python-common/ceph/smb/ctl/config.py
new file mode 100644 (file)
index 0000000..5d7147d
--- /dev/null
@@ -0,0 +1,58 @@
+"""Ceph SMB client config library"""
+
+import typing
+
+import abc
+import dataclasses
+import enum
+import pathlib
+
+from ._typing import Self
+
+
+class ChannelType(str, enum.Enum):
+    SECURE = 'secure'
+    INSECURE = 'insecure'
+
+
+class TLSLoader(abc.ABC):
+    def load(self) -> bytes:
+        raise NotImplementedError()
+
+
+@dataclasses.dataclass
+class TLSInline(TLSLoader):
+    """Configure TLS with inline cert data. Mainly for testing."""
+
+    data: typing.Union[str, bytes]
+
+    def load(self) -> bytes:
+        if isinstance(self.data, str):
+            return self.data.encode()
+        return self.data
+
+
+@dataclasses.dataclass
+class TLSPath(TLSLoader):
+    """Configure TLS using a path to cert data."""
+
+    path: pathlib.Path
+
+    @classmethod
+    def create(cls, path: typing.Union[str, pathlib.Path]) -> Self:
+        return cls(pathlib.Path(path))
+
+    def load(self) -> bytes:
+        with open(self.path, 'rb') as fh:
+            data = fh.read()
+        return data
+
+
+@dataclasses.dataclass
+class Config:
+    address: str
+    channel_type: ChannelType
+    tls_cert: typing.Optional[TLSLoader] = None
+    tls_key: typing.Optional[TLSLoader] = None
+    tls_ca_cert: typing.Optional[TLSLoader] = None
+    headers: typing.Optional[typing.Dict[str, str]] = None