From e706cb1f41ebac6c3280a17792a6d95ee21226a6 Mon Sep 17 00:00:00 2001 From: Avishay Alon Date: Mon, 29 Oct 2018 20:47:55 +0000 Subject: [PATCH 1/8] Support for easy integration with ros2 security features by starting CLI nodes with a consistent prefix. --- ros2cli/ros2cli/node/__init__.py | 2 ++ ros2cli/ros2cli/node/direct.py | 9 +++++---- ros2node/ros2node/api/__init__.py | 4 +--- ros2service/ros2service/verb/call.py | 3 ++- ros2topic/ros2topic/verb/pub.py | 3 ++- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ros2cli/ros2cli/node/__init__.py b/ros2cli/ros2cli/node/__init__.py index e69de29bb..237e142c2 100644 --- a/ros2cli/ros2cli/node/__init__.py +++ b/ros2cli/ros2cli/node/__init__.py @@ -0,0 +1,2 @@ +HIDDEN_NODE_PREFIX = '_' +CLI_NODE_NAME_PREFIX = 'ros2cli_node' diff --git a/ros2cli/ros2cli/node/direct.py b/ros2cli/ros2cli/node/direct.py index 6040da62c..c5b133a4b 100644 --- a/ros2cli/ros2cli/node/direct.py +++ b/ros2cli/ros2cli/node/direct.py @@ -16,9 +16,9 @@ import rclpy -# TODO(mikaelarguedas) revisit this once it's specified -HIDDEN_NODE_PREFIX = '_' - +#HIDDEN_NODE_PREFIX = '_' +#from ros2node.api import HIDDEN_NODE_PREFIX +from ros2cli.node import HIDDEN_NODE_PREFIX, CLI_NODE_NAME_PREFIX DEFAULT_TIMEOUT = 0.5 @@ -35,7 +35,8 @@ def timer_callback(): node_name_suffix = getattr( args, 'node_name_suffix', '_%d' % os.getpid()) - self.node = rclpy.create_node(HIDDEN_NODE_PREFIX + 'ros2cli_node' + node_name_suffix) + node_name_prefix = HIDDEN_NODE_PREFIX + CLI_NODE_NAME_PREFIX + self.node = rclpy.create_node(node_name_prefix + node_name_suffix) timeout = getattr(args, 'spin_time', DEFAULT_TIMEOUT) timer = self.node.create_timer(timeout, timer_callback) diff --git a/ros2node/ros2node/api/__init__.py b/ros2node/ros2node/api/__init__.py index 6fe5edb64..fb2003928 100644 --- a/ros2node/ros2node/api/__init__.py +++ b/ros2node/ros2node/api/__init__.py @@ -15,9 +15,7 @@ from collections import namedtuple from ros2cli.node.strategy import NodeStrategy - -# TODO(mikaelarguedas) revisit this once it's specified -HIDDEN_NODE_PREFIX = '_' +from ros2cli.node import HIDDEN_NODE_PREFIX NodeName = namedtuple('NodeName', ('name', 'namespace', 'full_name')) TopicInfo = namedtuple('Topic', ('name', 'types')) diff --git a/ros2service/ros2service/verb/call.py b/ros2service/ros2service/verb/call.py index cb2b18910..f85668370 100644 --- a/ros2service/ros2service/verb/call.py +++ b/ros2service/ros2service/verb/call.py @@ -21,6 +21,7 @@ from ros2service.verb import VerbExtension from ros2topic.api import set_msg_fields from ros2topic.api import SetFieldError +from ros2cli.node import CLI_NODE_NAME_PREFIX import yaml @@ -76,7 +77,7 @@ def requester(service_type, service_name, values, period): rclpy.init() - node = rclpy.create_node('requester_%s_%s' % (package_name, srv_name)) + node = rclpy.create_node(CLI_NODE_NAME_PREFIX + '_requester_%s_%s' % (package_name, srv_name)) cli = node.create_client(srv_module, service_name) diff --git a/ros2topic/ros2topic/verb/pub.py b/ros2topic/ros2topic/verb/pub.py index 0c80d2f5b..92a69ff4e 100644 --- a/ros2topic/ros2topic/verb/pub.py +++ b/ros2topic/ros2topic/verb/pub.py @@ -21,6 +21,7 @@ from ros2topic.api import TopicNameCompleter from ros2topic.api import TopicTypeCompleter from ros2topic.verb import VerbExtension +from ros2cli.node import CLI_NODE_NAME_PREFIX import yaml @@ -77,7 +78,7 @@ def publisher( if not isinstance(values_dictionary, dict): return 'The passed value needs to be a dictionary in YAML format' if not node_name: - node_name = 'publisher_%s' % (message_type.replace('/', '_'),) + node_name = CLI_NODE_NAME_PREFIX + '_publisher_%s' % (message_type.replace('/', '_'), ) rclpy.init() node = rclpy.create_node(node_name) From 122490d4d6f1506aca8145669754698daafd8404 Mon Sep 17 00:00:00 2001 From: Avishay Alon Date: Mon, 29 Oct 2018 21:41:33 +0000 Subject: [PATCH 2/8] Removing unneeded comment --- ros2cli/ros2cli/node/direct.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ros2cli/ros2cli/node/direct.py b/ros2cli/ros2cli/node/direct.py index c5b133a4b..5476823cd 100644 --- a/ros2cli/ros2cli/node/direct.py +++ b/ros2cli/ros2cli/node/direct.py @@ -16,8 +16,6 @@ import rclpy -#HIDDEN_NODE_PREFIX = '_' -#from ros2node.api import HIDDEN_NODE_PREFIX from ros2cli.node import HIDDEN_NODE_PREFIX, CLI_NODE_NAME_PREFIX DEFAULT_TIMEOUT = 0.5 From 2c493e347e8790d92a9f22775376758a8dfecf02 Mon Sep 17 00:00:00 2001 From: Avishay Alon Date: Fri, 16 Nov 2018 08:15:34 +0000 Subject: [PATCH 3/8] Making DirectNode visible (removing hidden node prefix) to have consistent node naming for ros2cli. --- ros2cli/ros2cli/node/__init__.py | 14 ++++++++++++++ ros2cli/ros2cli/node/direct.py | 5 ++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ros2cli/ros2cli/node/__init__.py b/ros2cli/ros2cli/node/__init__.py index 237e142c2..eb6e93216 100644 --- a/ros2cli/ros2cli/node/__init__.py +++ b/ros2cli/ros2cli/node/__init__.py @@ -1,2 +1,16 @@ +# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# TODO(mikaelarguedas) revisit this once it's specified HIDDEN_NODE_PREFIX = '_' CLI_NODE_NAME_PREFIX = 'ros2cli_node' diff --git a/ros2cli/ros2cli/node/direct.py b/ros2cli/ros2cli/node/direct.py index 5476823cd..9702782af 100644 --- a/ros2cli/ros2cli/node/direct.py +++ b/ros2cli/ros2cli/node/direct.py @@ -16,7 +16,7 @@ import rclpy -from ros2cli.node import HIDDEN_NODE_PREFIX, CLI_NODE_NAME_PREFIX +from ros2cli.node import CLI_NODE_NAME_PREFIX DEFAULT_TIMEOUT = 0.5 @@ -33,8 +33,7 @@ def timer_callback(): node_name_suffix = getattr( args, 'node_name_suffix', '_%d' % os.getpid()) - node_name_prefix = HIDDEN_NODE_PREFIX + CLI_NODE_NAME_PREFIX - self.node = rclpy.create_node(node_name_prefix + node_name_suffix) + self.node = rclpy.create_node(CLI_NODE_NAME_PREFIX + node_name_suffix) timeout = getattr(args, 'spin_time', DEFAULT_TIMEOUT) timer = self.node.create_timer(timeout, timer_callback) From 2d5892f09a62d1be556e1b7c9812616456c520f3 Mon Sep 17 00:00:00 2001 From: Avishay Alon Date: Thu, 13 Dec 2018 19:09:31 +0000 Subject: [PATCH 4/8] Start all CLI nodes as hidden. --- ros2cli/ros2cli/node/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros2cli/ros2cli/node/__init__.py b/ros2cli/ros2cli/node/__init__.py index eb6e93216..d3aedb5ec 100644 --- a/ros2cli/ros2cli/node/__init__.py +++ b/ros2cli/ros2cli/node/__init__.py @@ -13,4 +13,4 @@ # limitations under the License. # TODO(mikaelarguedas) revisit this once it's specified HIDDEN_NODE_PREFIX = '_' -CLI_NODE_NAME_PREFIX = 'ros2cli_node' +CLI_NODE_NAME_PREFIX = HIDDEN_NODE_PREFIX + 'ros2cli_node' From 0747f45d4e63d9cb568316f4ec4edf68bffbbee0 Mon Sep 17 00:00:00 2001 From: Avishay Alon Date: Thu, 13 Dec 2018 19:29:37 +0000 Subject: [PATCH 5/8] Shortening the default CLI node name prefix from '_ros2cli_node' to '_ros2cli' --- ros2cli/ros2cli/node/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros2cli/ros2cli/node/__init__.py b/ros2cli/ros2cli/node/__init__.py index d3aedb5ec..6a415f31f 100644 --- a/ros2cli/ros2cli/node/__init__.py +++ b/ros2cli/ros2cli/node/__init__.py @@ -13,4 +13,4 @@ # limitations under the License. # TODO(mikaelarguedas) revisit this once it's specified HIDDEN_NODE_PREFIX = '_' -CLI_NODE_NAME_PREFIX = HIDDEN_NODE_PREFIX + 'ros2cli_node' +CLI_NODE_NAME_PREFIX = HIDDEN_NODE_PREFIX + 'ros2cli' From 19ec2fdbedeb8c042959bccef2dc442a06f12645 Mon Sep 17 00:00:00 2001 From: Avishay Alon Date: Fri, 11 Jan 2019 00:12:54 +0000 Subject: [PATCH 6/8] Importing HIDDEN_NODE_PREFIX from rclpy, renaming CLI_NODE_NAME_PREFIX -> NODE_NAME_PREFIX. --- ros2cli/ros2cli/node/__init__.py | 5 ++--- ros2cli/ros2cli/node/direct.py | 4 ++-- ros2service/ros2service/verb/call.py | 4 ++-- ros2topic/ros2topic/verb/pub.py | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ros2cli/ros2cli/node/__init__.py b/ros2cli/ros2cli/node/__init__.py index 6a415f31f..cb5825f02 100644 --- a/ros2cli/ros2cli/node/__init__.py +++ b/ros2cli/ros2cli/node/__init__.py @@ -11,6 +11,5 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# TODO(mikaelarguedas) revisit this once it's specified -HIDDEN_NODE_PREFIX = '_' -CLI_NODE_NAME_PREFIX = HIDDEN_NODE_PREFIX + 'ros2cli' +from rclpy.node import HIDDEN_NODE_PREFIX +NODE_NAME_PREFIX = HIDDEN_NODE_PREFIX + 'ros2cli' diff --git a/ros2cli/ros2cli/node/direct.py b/ros2cli/ros2cli/node/direct.py index 9702782af..35fbc6d43 100644 --- a/ros2cli/ros2cli/node/direct.py +++ b/ros2cli/ros2cli/node/direct.py @@ -16,7 +16,7 @@ import rclpy -from ros2cli.node import CLI_NODE_NAME_PREFIX +from ros2cli.node import NODE_NAME_PREFIX DEFAULT_TIMEOUT = 0.5 @@ -33,7 +33,7 @@ def timer_callback(): node_name_suffix = getattr( args, 'node_name_suffix', '_%d' % os.getpid()) - self.node = rclpy.create_node(CLI_NODE_NAME_PREFIX + node_name_suffix) + self.node = rclpy.create_node(NODE_NAME_PREFIX + node_name_suffix) timeout = getattr(args, 'spin_time', DEFAULT_TIMEOUT) timer = self.node.create_timer(timeout, timer_callback) diff --git a/ros2service/ros2service/verb/call.py b/ros2service/ros2service/verb/call.py index f85668370..1cb8ade9b 100644 --- a/ros2service/ros2service/verb/call.py +++ b/ros2service/ros2service/verb/call.py @@ -21,7 +21,7 @@ from ros2service.verb import VerbExtension from ros2topic.api import set_msg_fields from ros2topic.api import SetFieldError -from ros2cli.node import CLI_NODE_NAME_PREFIX +from ros2cli.node import NODE_NAME_PREFIX import yaml @@ -77,7 +77,7 @@ def requester(service_type, service_name, values, period): rclpy.init() - node = rclpy.create_node(CLI_NODE_NAME_PREFIX + '_requester_%s_%s' % (package_name, srv_name)) + node = rclpy.create_node(NODE_NAME_PREFIX + '_requester_%s_%s' % (package_name, srv_name)) cli = node.create_client(srv_module, service_name) diff --git a/ros2topic/ros2topic/verb/pub.py b/ros2topic/ros2topic/verb/pub.py index 92a69ff4e..163e47d2e 100644 --- a/ros2topic/ros2topic/verb/pub.py +++ b/ros2topic/ros2topic/verb/pub.py @@ -21,7 +21,7 @@ from ros2topic.api import TopicNameCompleter from ros2topic.api import TopicTypeCompleter from ros2topic.verb import VerbExtension -from ros2cli.node import CLI_NODE_NAME_PREFIX +from ros2cli.node import NODE_NAME_PREFIX import yaml @@ -78,7 +78,7 @@ def publisher( if not isinstance(values_dictionary, dict): return 'The passed value needs to be a dictionary in YAML format' if not node_name: - node_name = CLI_NODE_NAME_PREFIX + '_publisher_%s' % (message_type.replace('/', '_'), ) + node_name = NODE_NAME_PREFIX + '_publisher_%s' % (message_type.replace('/', '_'), ) rclpy.init() node = rclpy.create_node(node_name) From 5fd12325e26533f3f54491da02704d077c1df4a6 Mon Sep 17 00:00:00 2001 From: Avishay Alon Date: Fri, 11 Jan 2019 00:17:24 +0000 Subject: [PATCH 7/8] ros2node - Importing HIDDEN_NODE_PREFIX from rclpy --- ros2node/ros2node/api/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros2node/ros2node/api/__init__.py b/ros2node/ros2node/api/__init__.py index fb2003928..020864194 100644 --- a/ros2node/ros2node/api/__init__.py +++ b/ros2node/ros2node/api/__init__.py @@ -15,7 +15,7 @@ from collections import namedtuple from ros2cli.node.strategy import NodeStrategy -from ros2cli.node import HIDDEN_NODE_PREFIX +from rclpy.node import HIDDEN_NODE_PREFIX NodeName = namedtuple('NodeName', ('name', 'namespace', 'full_name')) TopicInfo = namedtuple('Topic', ('name', 'types')) From 10c96147a4c829dc692ef20069ae993b6fbb8892 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Fri, 25 Jan 2019 20:05:50 +0000 Subject: [PATCH 8/8] Linter fixes. Signed-off-by: Chris Lalancette --- ros2node/ros2node/api/__init__.py | 2 +- ros2service/ros2service/verb/call.py | 2 +- ros2topic/ros2topic/verb/pub.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ros2node/ros2node/api/__init__.py b/ros2node/ros2node/api/__init__.py index 020864194..c005901e9 100644 --- a/ros2node/ros2node/api/__init__.py +++ b/ros2node/ros2node/api/__init__.py @@ -14,8 +14,8 @@ from collections import namedtuple -from ros2cli.node.strategy import NodeStrategy from rclpy.node import HIDDEN_NODE_PREFIX +from ros2cli.node.strategy import NodeStrategy NodeName = namedtuple('NodeName', ('name', 'namespace', 'full_name')) TopicInfo = namedtuple('Topic', ('name', 'types')) diff --git a/ros2service/ros2service/verb/call.py b/ros2service/ros2service/verb/call.py index 1cb8ade9b..d097adb2b 100644 --- a/ros2service/ros2service/verb/call.py +++ b/ros2service/ros2service/verb/call.py @@ -16,12 +16,12 @@ import time import rclpy +from ros2cli.node import NODE_NAME_PREFIX from ros2service.api import ServiceNameCompleter from ros2service.api import ServiceTypeCompleter from ros2service.verb import VerbExtension from ros2topic.api import set_msg_fields from ros2topic.api import SetFieldError -from ros2cli.node import NODE_NAME_PREFIX import yaml diff --git a/ros2topic/ros2topic/verb/pub.py b/ros2topic/ros2topic/verb/pub.py index 163e47d2e..00e77edb0 100644 --- a/ros2topic/ros2topic/verb/pub.py +++ b/ros2topic/ros2topic/verb/pub.py @@ -15,13 +15,13 @@ import time import rclpy +from ros2cli.node import NODE_NAME_PREFIX from ros2topic.api import import_message_type from ros2topic.api import set_msg_fields from ros2topic.api import SetFieldError from ros2topic.api import TopicNameCompleter from ros2topic.api import TopicTypeCompleter from ros2topic.verb import VerbExtension -from ros2cli.node import NODE_NAME_PREFIX import yaml