Skip to content

Commit ba14c45

Browse files
sambacc: add a PermissionsConfig concept
The PermissionsConfig will be used to configure handling of share permissions (setting up initial perms, etc). Signed-off-by: John Mulligan <[email protected]>
1 parent 167b443 commit ba14c45

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

sambacc/config.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def gid_base(self) -> int:
131131
def shares(self) -> typing.Iterable[ShareConfig]:
132132
"""Iterate over share configs."""
133133
for sname in self.iconfig.get("shares", []):
134-
yield ShareConfig(self.gconfig, sname)
134+
yield ShareConfig(self.gconfig, sname, iconfig=self.iconfig)
135135

136136
def users(self) -> typing.Iterable[UserEntry]:
137137
all_users = self.gconfig.data.get("users", {}).get("all_entries", {})
@@ -227,9 +227,15 @@ def shares(self) -> typing.Iterable[ShareConfig]:
227227

228228

229229
class ShareConfig:
230-
def __init__(self, conf, sharename):
230+
def __init__(
231+
self,
232+
conf: GlobalConfig,
233+
sharename: str,
234+
iconfig: typing.Optional[dict] = None,
235+
) -> None:
231236
self.gconfig = conf
232237
self.name = sharename
238+
self.iconfig = iconfig or {}
233239

234240
def share_options(self) -> typing.Iterable[typing.Tuple[str, str]]:
235241
"""Iterate over share options."""
@@ -244,6 +250,24 @@ def path(self) -> typing.Optional[str]:
244250
except KeyError:
245251
return None
246252

253+
def permissions_config(self) -> PermissionsConfig:
254+
"""Return a permissions configuration for the share."""
255+
# each share can have it's own permissions config,
256+
# but if it does not it will default to the instance's
257+
# config
258+
try:
259+
share_perms = self.gconfig.data["shares"][self.name]["permissions"]
260+
return PermissionsConfig(share_perms)
261+
except KeyError:
262+
pass
263+
try:
264+
instance_perms = self.iconfig["permissions"]
265+
return PermissionsConfig(instance_perms)
266+
except KeyError:
267+
pass
268+
# use the internal defaults
269+
return PermissionsConfig({})
270+
247271

248272
class UserEntry:
249273
def __init__(self, iconf: InstanceConfig, urec: dict, num: int):
@@ -354,6 +378,25 @@ class DomainGroupEntry(GroupEntry):
354378
pass
355379

356380

381+
class PermissionsConfig:
382+
_method_key: str = "method"
383+
_status_xattr_key: str = "status_xattr"
384+
_default_method: str = "none"
385+
_default_status_xattr: str = "user.share-perms-status"
386+
387+
def __init__(self, pconf: dict[str, str]) -> None:
388+
self._pconf = pconf
389+
self.method: str = pconf.get(self._method_key, self._default_method)
390+
self.status_xattr: str = pconf.get(
391+
self._status_xattr_key, self._default_status_xattr
392+
)
393+
394+
@property
395+
def options(self) -> dict[str, str]:
396+
filter_keys = {self._method_key, self._status_xattr_key}
397+
return {k: v for k, v in self._pconf.items() if k not in filter_keys}
398+
399+
357400
def _shares_data(gconfig: GlobalConfig, iconfig: dict) -> list:
358401
try:
359402
shares = iconfig["shares"]

0 commit comments

Comments
 (0)