@@ -131,7 +131,7 @@ def gid_base(self) -> int:
131
131
def shares (self ) -> typing .Iterable [ShareConfig ]:
132
132
"""Iterate over share configs."""
133
133
for sname in self .iconfig .get ("shares" , []):
134
- yield ShareConfig (self .gconfig , sname )
134
+ yield ShareConfig (self .gconfig , sname , iconfig = self . iconfig )
135
135
136
136
def users (self ) -> typing .Iterable [UserEntry ]:
137
137
all_users = self .gconfig .data .get ("users" , {}).get ("all_entries" , {})
@@ -227,9 +227,15 @@ def shares(self) -> typing.Iterable[ShareConfig]:
227
227
228
228
229
229
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 :
231
236
self .gconfig = conf
232
237
self .name = sharename
238
+ self .iconfig = iconfig or {}
233
239
234
240
def share_options (self ) -> typing .Iterable [typing .Tuple [str , str ]]:
235
241
"""Iterate over share options."""
@@ -244,6 +250,24 @@ def path(self) -> typing.Optional[str]:
244
250
except KeyError :
245
251
return None
246
252
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
+
247
271
248
272
class UserEntry :
249
273
def __init__ (self , iconf : InstanceConfig , urec : dict , num : int ):
@@ -354,6 +378,25 @@ class DomainGroupEntry(GroupEntry):
354
378
pass
355
379
356
380
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
+
357
400
def _shares_data (gconfig : GlobalConfig , iconfig : dict ) -> list :
358
401
try :
359
402
shares = iconfig ["shares" ]
0 commit comments