From 1bed9d87ca455305f0bd5c12a3a7cc5b9b7315af Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Mon, 4 Mar 2024 17:16:08 +0000 Subject: [PATCH] doc(services): explain the Owned Path reason d'etre after trying to remove it --- selfprivacy_api/services/owned_path.py | 15 ++++++++++++++- selfprivacy_api/services/service.py | 22 +++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/selfprivacy_api/services/owned_path.py b/selfprivacy_api/services/owned_path.py index 6e85fb0..aa6e92e 100644 --- a/selfprivacy_api/services/owned_path.py +++ b/selfprivacy_api/services/owned_path.py @@ -14,8 +14,21 @@ class BindError(Exception): pass -# May be deprecated because of Binds class OwnedPath(BaseModel): + """ + A convenient interface for explicitly defining ownership of service folders. + One overrides Service.get_owned_paths() for this. + + Why this exists?: + One could use Bind to define ownership but then one would need to handle drive which + is unnecessary and produces code duplication. + + It is also somewhat semantically wrong to include Owned Path into Bind + instead of user and group. Because owner and group in Bind are applied to + the original folder on the drive, not to the binding path. But maybe it is + ok since they are technically both owned. Idk yet. + """ + path: str owner: str group: str diff --git a/selfprivacy_api/services/service.py b/selfprivacy_api/services/service.py index 576877c..9add2dc 100644 --- a/selfprivacy_api/services/service.py +++ b/selfprivacy_api/services/service.py @@ -411,11 +411,27 @@ class Service(ABC): @classmethod def owned_path(cls, path: str): - """A default guess on folder ownership""" + """Default folder ownership""" + service_name = cls.get_display_name() + + try: + owner = cls.get_user() + if owner is None: + # TODO: assume root? + # (if we do not want to do assumptions, maybe not declare user optional?) + raise LookupError(f"no user for service: {service_name}") + group = cls.get_group() + if group is None: + raise LookupError(f"no group for service: {service_name}") + except Exception as error: + raise LookupError( + f"when deciding a bind for folder {path} of service {service_name}, error: {str(error)}" + ) + return OwnedPath( path=path, - owner=cls.get_user(), - group=cls.get_group(), + owner=owner, + group=group, ) def pre_backup(self):