|
4 | 4 | from contextlib import contextmanager |
5 | 5 | import logging |
6 | 6 | import signal |
7 | | -from typing import Dict, Optional, Sequence |
| 7 | +from typing import Dict, Optional, Sequence, Tuple |
8 | 8 |
|
9 | 9 | import libyang |
10 | 10 |
|
11 | 11 | from _sysrepo import ffi, lib |
12 | 12 | from .errors import SysrepoInternalError, check_call |
13 | 13 | from .session import SysrepoSession, datastore_value |
14 | | -from .util import str2c |
| 14 | +from .util import c2str, str2c |
15 | 15 |
|
16 | 16 |
|
17 | 17 | LOG = logging.getLogger(__name__) |
@@ -279,3 +279,31 @@ def enable_module_feature(self, name: str, feature_name: str) -> None: |
279 | 279 | check_call( |
280 | 280 | lib.sr_enable_module_feature, self.cdata, str2c(name), str2c(feature_name) |
281 | 281 | ) |
| 282 | + |
| 283 | + def get_module_ds_access( |
| 284 | + self, module_name: str, datastore: str = "running" |
| 285 | + ) -> Tuple[str, str, int]: |
| 286 | + """ |
| 287 | + Learn about module permissions. |
| 288 | +
|
| 289 | + :arg str module_name: |
| 290 | + Name of the module. |
| 291 | + :arg str datastore: |
| 292 | + Name of the datastore that will be operated on. |
| 293 | + :returns: |
| 294 | + The owner, group and permissions of the given module name. |
| 295 | + Owner and group are names, not numeric ids. |
| 296 | + """ |
| 297 | + owner = ffi.new("char **owner") |
| 298 | + group = ffi.new("char **group") |
| 299 | + perm = ffi.new("mode_t *perm") |
| 300 | + check_call( |
| 301 | + lib.sr_get_module_ds_access, |
| 302 | + self.cdata, |
| 303 | + str2c(module_name), |
| 304 | + datastore_value(datastore), |
| 305 | + owner, |
| 306 | + group, |
| 307 | + perm, |
| 308 | + ) |
| 309 | + return (c2str(owner[0]), c2str(group[0]), perm[0]) |
0 commit comments