Skip to content

Commit 83e8cd6

Browse files
committed
add sr_get_module_ds_access API
1 parent 77bc35d commit 83e8cd6

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

Diff for: cffi/cdefs.h

+3
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,6 @@ int sr_notif_subscribe_tree(sr_session_ctx_t *, const char *module_name, const c
292292
void *priv, sr_subscr_options_t, sr_subscription_ctx_t **);
293293

294294
int sr_notif_send_tree(sr_session_ctx_t *, struct lyd_node *notif, uint32_t timeout_ms, int wait);
295+
296+
typedef int... mode_t;
297+
int sr_get_module_ds_access(sr_conn_ctx_t *conn, const char *module_name, int mod_ds, char **owner, char **group, mode_t *perm);

Diff for: sysrepo/connection.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from _sysrepo import ffi, lib
1212
from .errors import SysrepoInternalError, check_call
1313
from .session import SysrepoSession, datastore_value
14-
from .util import str2c
14+
from .util import c2str, str2c
1515

1616

1717
LOG = logging.getLogger(__name__)
@@ -279,3 +279,30 @@ def enable_module_feature(self, name: str, feature_name: str) -> None:
279279
check_call(
280280
lib.sr_enable_module_feature, self.cdata, str2c(name), str2c(feature_name)
281281
)
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+
"""
296+
owner = ffi.new("char **owner")
297+
group = ffi.new("char **group")
298+
perm = ffi.new("mode_t *perm")
299+
check_call(
300+
lib.sr_get_module_ds_access,
301+
self.cdata,
302+
str2c(module_name),
303+
datastore_value(datastore),
304+
owner,
305+
group,
306+
perm,
307+
)
308+
return (c2str(owner[0]), c2str(group[0]), perm[0])

Diff for: tests/test_connection.py

+8
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,11 @@ def test_conn_enable_module_feature(self):
7777
data = [x for x in data if x["name"] == "sysrepo-example"][0]
7878
self.assertIn("feature", data)
7979
conn.remove_module("sysrepo-example")
80+
81+
def test_conn_get_module_infos(self):
82+
with sysrepo.SysrepoConnection() as conn:
83+
conn.install_module(YANG_FILE)
84+
owner, group, perm = conn.get_module_ds_access("sysrepo-example")
85+
self.assertTrue(len(owner) > 0)
86+
self.assertTrue(len(group) > 0)
87+
self.assertEqual(perm, 384)

0 commit comments

Comments
 (0)