From 198d5b5f905f059f014a5194b9bdeb650268dff7 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Thu, 9 Apr 2020 11:30:07 -0300 Subject: [PATCH 1/8] Add security context introspection Signed-off-by: Ivan Santiago Paunovic --- rclpy/rclpy/node.py | 9 +++ rclpy/src/rclpy/_rclpy.c | 116 +++++++++++++++++++++++++++++++++++++++ rclpy/test/test_node.py | 4 ++ 3 files changed, 129 insertions(+) diff --git a/rclpy/rclpy/node.py b/rclpy/rclpy/node.py index 8b6c8bc62..dfbdee54f 100644 --- a/rclpy/rclpy/node.py +++ b/rclpy/rclpy/node.py @@ -1644,6 +1644,15 @@ def get_node_names_and_namespaces(self) -> List[Tuple[str, str]]: with self.handle as capsule: return _rclpy.rclpy_get_node_names_and_namespaces(capsule) + def get_node_names_and_namespaces_with_security_contexts(self) -> List[Tuple[str, str, str]]: + """ + Get a list of names, namespaces and security contexts for discovered nodes. + + :return: List of tuples containing two strings: the node name and node namespace. + """ + with self.handle as capsule: + return _rclpy.rclpy_get_node_names_and_namespaces_with_security_contexts(capsule) + def _count_publishers_or_subscribers(self, topic_name, func): fq_topic_name = expand_topic_name(topic_name, self.get_name(), self.get_namespace()) validate_full_topic_name(fq_topic_name) diff --git a/rclpy/src/rclpy/_rclpy.c b/rclpy/src/rclpy/_rclpy.c index 196fb4809..3e776b5f4 100644 --- a/rclpy/src/rclpy/_rclpy.c +++ b/rclpy/src/rclpy/_rclpy.c @@ -3513,6 +3513,116 @@ rclpy_get_node_names_and_namespaces(PyObject * Py_UNUSED(self), PyObject * args) return pynode_names_and_namespaces; } +/// Get the list of nodes discovered by the provided node, with their respective security contexts. +/** + * Raises ValueError if pynode is not a node capsule + * Raises RuntimeError if there is an rcl error + * + * \param[in] pynode Capsule pointing to the node + * \return Python list of tuples where each tuple contains three strings: + * the node name,node namespace and the security context. + */ +static PyObject * +rclpy_get_node_names_and_namespaces_with_security_contexts( + PyObject * Py_UNUSED(self), PyObject * args) +{ + PyObject * pynode; + + if (!PyArg_ParseTuple(args, "O", &pynode)) { + return NULL; + } + + rcl_allocator_t allocator = rcl_get_default_allocator(); + rcl_node_t * node = rclpy_handle_get_pointer_from_capsule(pynode, "rcl_node_t"); + if (!node) { + return NULL; + } + rcutils_string_array_t node_names = rcutils_get_zero_initialized_string_array(); + rcutils_string_array_t node_namespaces = rcutils_get_zero_initialized_string_array(); + rcutils_string_array_t security_contexts = rcutils_get_zero_initialized_string_array(); + rcl_ret_t ret = rcl_get_node_names_with_security_contexts( + node, allocator, &node_names, &node_namespaces, &security_contexts); + if (ret != RCL_RET_OK) { + PyErr_Format( + RCLError, "Failed to get node names: %s", rcl_get_error_string().str); + rcl_reset_error(); + return NULL; + } + + rcutils_ret_t fini_names_ret; + rcutils_ret_t fini_namespaces_ret; + rcutils_ret_t fini_security_contexts_ret; + PyObject * pynode_names_and_namespaces = PyList_New(node_names.size); + if (!pynode_names_and_namespaces) { + goto cleanup; + } + size_t idx; + for (idx = 0; idx < node_names.size; ++idx) { + PyObject * pytuple = PyTuple_New(3); + if (!pytuple) { + goto cleanup; + } + PyObject * pynode_name = PyUnicode_FromString(node_names.data[idx]); + if (!pynode_name) { + Py_DECREF(pytuple); + goto cleanup; + } + // Steals the reference + PyTuple_SET_ITEM(pytuple, 0, pynode_name); + PyObject * pynode_namespace = PyUnicode_FromString(node_namespaces.data[idx]); + if (!pynode_namespace) { + Py_DECREF(pytuple); + goto cleanup; + } + // Steals the reference + PyTuple_SET_ITEM(pytuple, 1, pynode_namespace); + PyObject * pynode_security_contexts = PyUnicode_FromString(security_contexts.data[idx]); + if (!pynode_security_contexts) { + Py_DECREF(pytuple); + goto cleanup; + } + // Steals the reference + PyTuple_SET_ITEM(pytuple, 2, pynode_security_contexts); + // Steals the reference + PyList_SET_ITEM(pynode_names_and_namespaces, idx, pytuple); + } + +cleanup: + fini_names_ret = rcutils_string_array_fini(&node_names); + fini_namespaces_ret = rcutils_string_array_fini(&node_namespaces); + fini_security_contexts_ret = rcutils_string_array_fini(&security_contexts); + if (PyErr_Occurred()) { + Py_XDECREF(pynode_names_and_namespaces); + return NULL; + } + if (fini_names_ret != RCUTILS_RET_OK) { + PyErr_Format( + RCLError, + "Failed to destroy node_names: %s", rcl_get_error_string().str); + Py_DECREF(pynode_names_and_namespaces); + rcl_reset_error(); + return NULL; + } + if (fini_namespaces_ret != RCUTILS_RET_OK) { + PyErr_Format( + RCLError, + "Failed to destroy node_namespaces: %s", rcl_get_error_string().str); + Py_DECREF(pynode_names_and_namespaces); + rcl_reset_error(); + return NULL; + } + if (fini_security_contexts_ret != RCUTILS_RET_OK) { + PyErr_Format( + RCLError, + "Failed to destroy security_contexts: %s", rcl_get_error_string().str); + Py_DECREF(pynode_names_and_namespaces); + rcl_reset_error(); + return NULL; + } + + return pynode_names_and_namespaces; +} + /// Get a list of service names and types associated with the given node name. /** * Raises ValueError if pynode is not a node capsule @@ -5378,6 +5488,12 @@ static PyMethodDef rclpy_methods[] = { "rclpy_get_node_names_and_namespaces", rclpy_get_node_names_and_namespaces, METH_VARARGS, "Get node names and namespaces list from graph API." }, + { + "rclpy_get_node_names_and_namespaces_with_security_contexts", + rclpy_get_node_names_and_namespaces_with_security_contexts, + METH_VARARGS, + "Get node names, namespaces, and security contexts list from graph API." + }, { "rclpy_get_node_parameters", rclpy_get_node_parameters, METH_VARARGS, "Get the initial parameters for a node from the command line." diff --git a/rclpy/test/test_node.py b/rclpy/test/test_node.py index cca8d3885..e0e2f674b 100644 --- a/rclpy/test/test_node.py +++ b/rclpy/test/test_node.py @@ -177,6 +177,10 @@ def test_node_names_and_namespaces(self): # test that it doesn't raise self.node.get_node_names_and_namespaces() + def test_node_names_and_namespaces_with_security_contexts(self): + # test that it doesn't raise + self.node.get_node_names_and_namespaces_with_security_contexts() + def assert_qos_equal(self, expected_qos_profile, actual_qos_profile, *, is_publisher): # Depth and history are skipped because they are not retrieved. self.assertEqual( From 372c187782ec0d586b447d032c9915b34d75a032 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Fri, 10 Apr 2020 10:09:49 -0300 Subject: [PATCH 2/8] Correct documentation Signed-off-by: Ivan Santiago Paunovic --- rclpy/rclpy/node.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rclpy/rclpy/node.py b/rclpy/rclpy/node.py index dfbdee54f..1be498d7f 100644 --- a/rclpy/rclpy/node.py +++ b/rclpy/rclpy/node.py @@ -1648,7 +1648,8 @@ def get_node_names_and_namespaces_with_security_contexts(self) -> List[Tuple[str """ Get a list of names, namespaces and security contexts for discovered nodes. - :return: List of tuples containing two strings: the node name and node namespace. + :return: List of tuples containing three strings: the node name, node namespace + and security context. """ with self.handle as capsule: return _rclpy.rclpy_get_node_names_and_namespaces_with_security_contexts(capsule) From 4bb11e0012a655011a940d12e773b7d21389f8fa Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Fri, 10 Apr 2020 11:16:13 -0300 Subject: [PATCH 3/8] Improve code reuse Signed-off-by: Ivan Santiago Paunovic --- rclpy/src/rclpy/_rclpy.c | 157 ++++++++++++--------------------------- 1 file changed, 49 insertions(+), 108 deletions(-) diff --git a/rclpy/src/rclpy/_rclpy.c b/rclpy/src/rclpy/_rclpy.c index 3e776b5f4..14269b7d2 100644 --- a/rclpy/src/rclpy/_rclpy.c +++ b/rclpy/src/rclpy/_rclpy.c @@ -3423,17 +3423,8 @@ rclpy_shutdown(PyObject * Py_UNUSED(self), PyObject * args) Py_RETURN_NONE; } -/// Get the list of nodes discovered by the provided node -/** - * Raises ValueError if pynode is not a node capsule - * Raises RuntimeError if there is an rcl error - * - * \param[in] pynode Capsule pointing to the node - * \return Python list of tuples where each tuple contains the two strings: - * the node name and node namespace - */ static PyObject * -rclpy_get_node_names_and_namespaces(PyObject * Py_UNUSED(self), PyObject * args) +rclpy_get_node_names_impl(PyObject * args, bool use_security_contexts) { PyObject * pynode; @@ -3448,23 +3439,34 @@ rclpy_get_node_names_and_namespaces(PyObject * Py_UNUSED(self), PyObject * args) } rcutils_string_array_t node_names = rcutils_get_zero_initialized_string_array(); rcutils_string_array_t node_namespaces = rcutils_get_zero_initialized_string_array(); - rcl_ret_t ret = rcl_get_node_names(node, allocator, &node_names, &node_namespaces); + rcutils_string_array_t security_contexts = rcutils_get_zero_initialized_string_array(); + rcl_ret_t ret = RCL_RET_OK; + if (use_security_contexts) { + ret = rcl_get_node_names_with_security_contexts( + node, allocator, &node_names, &node_namespaces, &security_contexts); + } else { + ret = rcl_get_node_names( + node, allocator, &node_names, &node_namespaces); + } if (ret != RCL_RET_OK) { PyErr_Format( - RCLError, "Failed to get_node_names: %s", rcl_get_error_string().str); + RCLError, "Failed to get node names: %s", rcl_get_error_string().str); rcl_reset_error(); return NULL; } rcutils_ret_t fini_names_ret; rcutils_ret_t fini_namespaces_ret; + rcutils_ret_t fini_security_contexts_ret; PyObject * pynode_names_and_namespaces = PyList_New(node_names.size); if (!pynode_names_and_namespaces) { goto cleanup; } + + size_t tuple_size = use_security_contexts ? 3 : 2; size_t idx; for (idx = 0; idx < node_names.size; ++idx) { - PyObject * pytuple = PyTuple_New(2); + PyObject * pytuple = PyTuple_New(tuple_size); if (!pytuple) { goto cleanup; } @@ -3482,6 +3484,15 @@ rclpy_get_node_names_and_namespaces(PyObject * Py_UNUSED(self), PyObject * args) } // Steals the reference PyTuple_SET_ITEM(pytuple, 1, pynode_namespace); + if (use_security_contexts) { + PyObject * pynode_security_contexts = PyUnicode_FromString(security_contexts.data[idx]); + if (!pynode_security_contexts) { + Py_DECREF(pytuple); + goto cleanup; + } + // Steals the reference + PyTuple_SET_ITEM(pytuple, 2, pynode_security_contexts); + } // Steals the reference PyList_SET_ITEM(pynode_names_and_namespaces, idx, pytuple); } @@ -3489,6 +3500,7 @@ rclpy_get_node_names_and_namespaces(PyObject * Py_UNUSED(self), PyObject * args) cleanup: fini_names_ret = rcutils_string_array_fini(&node_names); fini_namespaces_ret = rcutils_string_array_fini(&node_namespaces); + fini_security_contexts_ret = rcutils_string_array_fini(&security_contexts); if (PyErr_Occurred()) { Py_XDECREF(pynode_names_and_namespaces); return NULL; @@ -3509,10 +3521,33 @@ rclpy_get_node_names_and_namespaces(PyObject * Py_UNUSED(self), PyObject * args) rcl_reset_error(); return NULL; } + if (fini_security_contexts_ret != RCUTILS_RET_OK) { + PyErr_Format( + RCLError, + "Failed to destroy security_contexts: %s", rcl_get_error_string().str); + Py_DECREF(pynode_names_and_namespaces); + rcl_reset_error(); + return NULL; + } return pynode_names_and_namespaces; } +/// Get the list of nodes discovered by the provided node +/** + * Raises ValueError if pynode is not a node capsule + * Raises RuntimeError if there is an rcl error + * + * \param[in] pynode Capsule pointing to the node + * \return Python list of tuples where each tuple contains the two strings: + * the node name and node namespace + */ +static PyObject * +rclpy_get_node_names_and_namespaces(PyObject * Py_UNUSED(self), PyObject * args) +{ + return rclpy_get_node_names_impl(args, false); +} + /// Get the list of nodes discovered by the provided node, with their respective security contexts. /** * Raises ValueError if pynode is not a node capsule @@ -3526,101 +3561,7 @@ static PyObject * rclpy_get_node_names_and_namespaces_with_security_contexts( PyObject * Py_UNUSED(self), PyObject * args) { - PyObject * pynode; - - if (!PyArg_ParseTuple(args, "O", &pynode)) { - return NULL; - } - - rcl_allocator_t allocator = rcl_get_default_allocator(); - rcl_node_t * node = rclpy_handle_get_pointer_from_capsule(pynode, "rcl_node_t"); - if (!node) { - return NULL; - } - rcutils_string_array_t node_names = rcutils_get_zero_initialized_string_array(); - rcutils_string_array_t node_namespaces = rcutils_get_zero_initialized_string_array(); - rcutils_string_array_t security_contexts = rcutils_get_zero_initialized_string_array(); - rcl_ret_t ret = rcl_get_node_names_with_security_contexts( - node, allocator, &node_names, &node_namespaces, &security_contexts); - if (ret != RCL_RET_OK) { - PyErr_Format( - RCLError, "Failed to get node names: %s", rcl_get_error_string().str); - rcl_reset_error(); - return NULL; - } - - rcutils_ret_t fini_names_ret; - rcutils_ret_t fini_namespaces_ret; - rcutils_ret_t fini_security_contexts_ret; - PyObject * pynode_names_and_namespaces = PyList_New(node_names.size); - if (!pynode_names_and_namespaces) { - goto cleanup; - } - size_t idx; - for (idx = 0; idx < node_names.size; ++idx) { - PyObject * pytuple = PyTuple_New(3); - if (!pytuple) { - goto cleanup; - } - PyObject * pynode_name = PyUnicode_FromString(node_names.data[idx]); - if (!pynode_name) { - Py_DECREF(pytuple); - goto cleanup; - } - // Steals the reference - PyTuple_SET_ITEM(pytuple, 0, pynode_name); - PyObject * pynode_namespace = PyUnicode_FromString(node_namespaces.data[idx]); - if (!pynode_namespace) { - Py_DECREF(pytuple); - goto cleanup; - } - // Steals the reference - PyTuple_SET_ITEM(pytuple, 1, pynode_namespace); - PyObject * pynode_security_contexts = PyUnicode_FromString(security_contexts.data[idx]); - if (!pynode_security_contexts) { - Py_DECREF(pytuple); - goto cleanup; - } - // Steals the reference - PyTuple_SET_ITEM(pytuple, 2, pynode_security_contexts); - // Steals the reference - PyList_SET_ITEM(pynode_names_and_namespaces, idx, pytuple); - } - -cleanup: - fini_names_ret = rcutils_string_array_fini(&node_names); - fini_namespaces_ret = rcutils_string_array_fini(&node_namespaces); - fini_security_contexts_ret = rcutils_string_array_fini(&security_contexts); - if (PyErr_Occurred()) { - Py_XDECREF(pynode_names_and_namespaces); - return NULL; - } - if (fini_names_ret != RCUTILS_RET_OK) { - PyErr_Format( - RCLError, - "Failed to destroy node_names: %s", rcl_get_error_string().str); - Py_DECREF(pynode_names_and_namespaces); - rcl_reset_error(); - return NULL; - } - if (fini_namespaces_ret != RCUTILS_RET_OK) { - PyErr_Format( - RCLError, - "Failed to destroy node_namespaces: %s", rcl_get_error_string().str); - Py_DECREF(pynode_names_and_namespaces); - rcl_reset_error(); - return NULL; - } - if (fini_security_contexts_ret != RCUTILS_RET_OK) { - PyErr_Format( - RCLError, - "Failed to destroy security_contexts: %s", rcl_get_error_string().str); - Py_DECREF(pynode_names_and_namespaces); - rcl_reset_error(); - return NULL; - } - - return pynode_names_and_namespaces; + return rclpy_get_node_names_impl(args, true); } /// Get a list of service names and types associated with the given node name. From 31ec2d9e118c4d6d9a7eb7c7fb3e564aec778561 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Fri, 10 Apr 2020 12:39:48 -0300 Subject: [PATCH 4/8] Add doc block Signed-off-by: Ivan Santiago Paunovic --- rclpy/src/rclpy/_rclpy.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rclpy/src/rclpy/_rclpy.c b/rclpy/src/rclpy/_rclpy.c index 14269b7d2..7629bddac 100644 --- a/rclpy/src/rclpy/_rclpy.c +++ b/rclpy/src/rclpy/_rclpy.c @@ -3423,6 +3423,18 @@ rclpy_shutdown(PyObject * Py_UNUSED(self), PyObject * args) Py_RETURN_NONE; } +/// Get the list of nodes discovered by the provided node +/** + * Raises ValueError if pynode is not a node capsule + * Raises RuntimeError if there is an rcl error + * + * \param[in] args arguments tuple, composed by only one argument: + * - node: Capsule pointing to the node + * \param[in] use_security_contexts specifies if the output includes the security context or not + * \return Python list of tuples, containing: + * node name, node namespace, and + * security_context if `use_security_contexts` is true. + */ static PyObject * rclpy_get_node_names_impl(PyObject * args, bool use_security_contexts) { From 145324bd2b51dcb77c9a4741242a1019d3508690 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Fri, 10 Apr 2020 15:46:30 -0300 Subject: [PATCH 5/8] nit Signed-off-by: Ivan Santiago Paunovic Co-Authored-By: Michel Hidalgo --- rclpy/src/rclpy/_rclpy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rclpy/src/rclpy/_rclpy.c b/rclpy/src/rclpy/_rclpy.c index 7629bddac..ac7d920b4 100644 --- a/rclpy/src/rclpy/_rclpy.c +++ b/rclpy/src/rclpy/_rclpy.c @@ -3567,7 +3567,7 @@ rclpy_get_node_names_and_namespaces(PyObject * Py_UNUSED(self), PyObject * args) * * \param[in] pynode Capsule pointing to the node * \return Python list of tuples where each tuple contains three strings: - * the node name,node namespace and the security context. + * node name, namespace and security context. */ static PyObject * rclpy_get_node_names_and_namespaces_with_security_contexts( From 8ed2e2ca1aa279f2474fee6d7eef8c7e3d3b8386 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Mon, 13 Apr 2020 10:36:38 -0300 Subject: [PATCH 6/8] Address peer review comments Signed-off-by: Ivan Santiago Paunovic --- rclpy/src/rclpy/_rclpy.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rclpy/src/rclpy/_rclpy.c b/rclpy/src/rclpy/_rclpy.c index ac7d920b4..e9d971a79 100644 --- a/rclpy/src/rclpy/_rclpy.c +++ b/rclpy/src/rclpy/_rclpy.c @@ -3475,10 +3475,9 @@ rclpy_get_node_names_impl(PyObject * args, bool use_security_contexts) goto cleanup; } - size_t tuple_size = use_security_contexts ? 3 : 2; size_t idx; for (idx = 0; idx < node_names.size; ++idx) { - PyObject * pytuple = PyTuple_New(tuple_size); + PyObject * pytuple = PyTuple_New(use_security_contexts ? 3 : 2); if (!pytuple) { goto cleanup; } From 94038e7ec7bf0bd97c7f9ce097e4ddc87e276032 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Mon, 13 Apr 2020 10:47:01 -0300 Subject: [PATCH 7/8] security_context ->enclave Signed-off-by: Ivan Santiago Paunovic --- rclpy/rclpy/node.py | 6 +++--- rclpy/src/rclpy/_rclpy.c | 44 ++++++++++++++++++++-------------------- rclpy/test/test_node.py | 4 ++-- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/rclpy/rclpy/node.py b/rclpy/rclpy/node.py index 1be498d7f..96aba302f 100644 --- a/rclpy/rclpy/node.py +++ b/rclpy/rclpy/node.py @@ -1644,15 +1644,15 @@ def get_node_names_and_namespaces(self) -> List[Tuple[str, str]]: with self.handle as capsule: return _rclpy.rclpy_get_node_names_and_namespaces(capsule) - def get_node_names_and_namespaces_with_security_contexts(self) -> List[Tuple[str, str, str]]: + def get_node_names_and_namespaces_with_enclaves(self) -> List[Tuple[str, str, str]]: """ Get a list of names, namespaces and security contexts for discovered nodes. :return: List of tuples containing three strings: the node name, node namespace - and security context. + and enclave. """ with self.handle as capsule: - return _rclpy.rclpy_get_node_names_and_namespaces_with_security_contexts(capsule) + return _rclpy.rclpy_get_node_names_and_namespaces_with_enclaves(capsule) def _count_publishers_or_subscribers(self, topic_name, func): fq_topic_name = expand_topic_name(topic_name, self.get_name(), self.get_namespace()) diff --git a/rclpy/src/rclpy/_rclpy.c b/rclpy/src/rclpy/_rclpy.c index e9d971a79..be0c813bb 100644 --- a/rclpy/src/rclpy/_rclpy.c +++ b/rclpy/src/rclpy/_rclpy.c @@ -3430,13 +3430,13 @@ rclpy_shutdown(PyObject * Py_UNUSED(self), PyObject * args) * * \param[in] args arguments tuple, composed by only one argument: * - node: Capsule pointing to the node - * \param[in] use_security_contexts specifies if the output includes the security context or not + * \param[in] get_enclaves specifies if the output includes the enclaves names or not * \return Python list of tuples, containing: * node name, node namespace, and - * security_context if `use_security_contexts` is true. + * enclave if `get_enclaves` is true. */ static PyObject * -rclpy_get_node_names_impl(PyObject * args, bool use_security_contexts) +rclpy_get_node_names_impl(PyObject * args, bool get_enclaves) { PyObject * pynode; @@ -3451,11 +3451,11 @@ rclpy_get_node_names_impl(PyObject * args, bool use_security_contexts) } rcutils_string_array_t node_names = rcutils_get_zero_initialized_string_array(); rcutils_string_array_t node_namespaces = rcutils_get_zero_initialized_string_array(); - rcutils_string_array_t security_contexts = rcutils_get_zero_initialized_string_array(); + rcutils_string_array_t enclaves = rcutils_get_zero_initialized_string_array(); rcl_ret_t ret = RCL_RET_OK; - if (use_security_contexts) { - ret = rcl_get_node_names_with_security_contexts( - node, allocator, &node_names, &node_namespaces, &security_contexts); + if (get_enclaves) { + ret = rcl_get_node_names_with_enclaves( + node, allocator, &node_names, &node_namespaces, &enclaves); } else { ret = rcl_get_node_names( node, allocator, &node_names, &node_namespaces); @@ -3469,7 +3469,7 @@ rclpy_get_node_names_impl(PyObject * args, bool use_security_contexts) rcutils_ret_t fini_names_ret; rcutils_ret_t fini_namespaces_ret; - rcutils_ret_t fini_security_contexts_ret; + rcutils_ret_t fini_enclaves_ret; PyObject * pynode_names_and_namespaces = PyList_New(node_names.size); if (!pynode_names_and_namespaces) { goto cleanup; @@ -3477,7 +3477,7 @@ rclpy_get_node_names_impl(PyObject * args, bool use_security_contexts) size_t idx; for (idx = 0; idx < node_names.size; ++idx) { - PyObject * pytuple = PyTuple_New(use_security_contexts ? 3 : 2); + PyObject * pytuple = PyTuple_New(get_enclaves ? 3 : 2); if (!pytuple) { goto cleanup; } @@ -3495,14 +3495,14 @@ rclpy_get_node_names_impl(PyObject * args, bool use_security_contexts) } // Steals the reference PyTuple_SET_ITEM(pytuple, 1, pynode_namespace); - if (use_security_contexts) { - PyObject * pynode_security_contexts = PyUnicode_FromString(security_contexts.data[idx]); - if (!pynode_security_contexts) { + if (get_enclaves) { + PyObject * pynode_enclaves = PyUnicode_FromString(enclaves.data[idx]); + if (!pynode_enclaves) { Py_DECREF(pytuple); goto cleanup; } // Steals the reference - PyTuple_SET_ITEM(pytuple, 2, pynode_security_contexts); + PyTuple_SET_ITEM(pytuple, 2, pynode_enclaves); } // Steals the reference PyList_SET_ITEM(pynode_names_and_namespaces, idx, pytuple); @@ -3511,7 +3511,7 @@ rclpy_get_node_names_impl(PyObject * args, bool use_security_contexts) cleanup: fini_names_ret = rcutils_string_array_fini(&node_names); fini_namespaces_ret = rcutils_string_array_fini(&node_namespaces); - fini_security_contexts_ret = rcutils_string_array_fini(&security_contexts); + fini_enclaves_ret = rcutils_string_array_fini(&enclaves); if (PyErr_Occurred()) { Py_XDECREF(pynode_names_and_namespaces); return NULL; @@ -3532,10 +3532,10 @@ rclpy_get_node_names_impl(PyObject * args, bool use_security_contexts) rcl_reset_error(); return NULL; } - if (fini_security_contexts_ret != RCUTILS_RET_OK) { + if (fini_enclaves_ret != RCUTILS_RET_OK) { PyErr_Format( RCLError, - "Failed to destroy security_contexts: %s", rcl_get_error_string().str); + "Failed to destroy enclaves string array: %s", rcl_get_error_string().str); Py_DECREF(pynode_names_and_namespaces); rcl_reset_error(); return NULL; @@ -3559,17 +3559,17 @@ rclpy_get_node_names_and_namespaces(PyObject * Py_UNUSED(self), PyObject * args) return rclpy_get_node_names_impl(args, false); } -/// Get the list of nodes discovered by the provided node, with their respective security contexts. +/// Get the list of nodes discovered by the provided node, with their respective enclaves. /** * Raises ValueError if pynode is not a node capsule * Raises RuntimeError if there is an rcl error * * \param[in] pynode Capsule pointing to the node * \return Python list of tuples where each tuple contains three strings: - * node name, namespace and security context. + * node name, node namespace, and enclave. */ static PyObject * -rclpy_get_node_names_and_namespaces_with_security_contexts( +rclpy_get_node_names_and_namespaces_with_enclaves( PyObject * Py_UNUSED(self), PyObject * args) { return rclpy_get_node_names_impl(args, true); @@ -5441,10 +5441,10 @@ static PyMethodDef rclpy_methods[] = { "Get node names and namespaces list from graph API." }, { - "rclpy_get_node_names_and_namespaces_with_security_contexts", - rclpy_get_node_names_and_namespaces_with_security_contexts, + "rclpy_get_node_names_and_namespaces_with_enclaves", + rclpy_get_node_names_and_namespaces_with_enclaves, METH_VARARGS, - "Get node names, namespaces, and security contexts list from graph API." + "Get node names, namespaces, and enclaves list from graph API." }, { "rclpy_get_node_parameters", rclpy_get_node_parameters, METH_VARARGS, diff --git a/rclpy/test/test_node.py b/rclpy/test/test_node.py index e0e2f674b..f377efa47 100644 --- a/rclpy/test/test_node.py +++ b/rclpy/test/test_node.py @@ -177,9 +177,9 @@ def test_node_names_and_namespaces(self): # test that it doesn't raise self.node.get_node_names_and_namespaces() - def test_node_names_and_namespaces_with_security_contexts(self): + def test_node_names_and_namespaces_with_enclaves(self): # test that it doesn't raise - self.node.get_node_names_and_namespaces_with_security_contexts() + self.node.get_node_names_and_namespaces_with_enclaves() def assert_qos_equal(self, expected_qos_profile, actual_qos_profile, *, is_publisher): # Depth and history are skipped because they are not retrieved. From c496d511fd86637205ca843637e15a0529fb5556 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Mon, 13 Apr 2020 12:23:36 -0300 Subject: [PATCH 8/8] Fix nit in doc string Signed-off-by: Ivan Santiago Paunovic Co-Authored-By: Michel Hidalgo --- rclpy/rclpy/node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rclpy/rclpy/node.py b/rclpy/rclpy/node.py index 96aba302f..fe0be343e 100644 --- a/rclpy/rclpy/node.py +++ b/rclpy/rclpy/node.py @@ -1646,7 +1646,7 @@ def get_node_names_and_namespaces(self) -> List[Tuple[str, str]]: def get_node_names_and_namespaces_with_enclaves(self) -> List[Tuple[str, str, str]]: """ - Get a list of names, namespaces and security contexts for discovered nodes. + Get a list of names, namespaces and enclaves for discovered nodes. :return: List of tuples containing three strings: the node name, node namespace and enclave.