-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ros2 service crystal #71
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3d7cda1
Add generate permissions security command line
ross-desmond 7b7de3d
Proposed policy definition changes
ross-desmond 597f1bd
cmake security macro
ross-desmond 3c4f981
Addresses comments from pull-71
ross-desmond 81189cf
Modifies policy definition tables
ross-desmond a3d9de2
Fixes flake8 and copyright errors
ross-desmond 7a67e2f
Removes security helper for separate pull request
ross-desmond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Copyright 2016-2017 Open Source Robotics Foundation, Inc. | ||
# | ||
# 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. | ||
|
||
try: | ||
from argcomplete.completers import DirectoriesCompleter | ||
except ImportError: | ||
def DirectoriesCompleter(): | ||
return None | ||
try: | ||
from argcomplete.completers import FilesCompleter | ||
except ImportError: | ||
def FilesCompleter(*, allowednames, directories): | ||
return None | ||
|
||
from ros2cli.node.strategy import NodeStrategy | ||
from ros2cli.node.direct import DirectNode | ||
from sros2.api import get_subscriber_info | ||
from sros2.api import get_publisher_info | ||
from sros2.api import get_service_info | ||
from sros2.api import get_node_names | ||
from sros2.verb import VerbExtension | ||
from collections import defaultdict | ||
|
||
def formatTopics(topic_list, permission, topic_map): | ||
for topic in topic_list: | ||
topic_map[topic.name].append(permission) | ||
|
||
class GeneratePermissionsVerb(VerbExtension): | ||
"""Generate permissions.""" | ||
|
||
def add_arguments(self, parser, cli_name): | ||
|
||
arg = parser.add_argument( | ||
'POLICY_FILE_PATH', help='path of the permission yaml file') | ||
arg.completer = FilesCompleter( | ||
allowednames=('yaml'), directories=False) | ||
|
||
def main(self, *, args): | ||
node_names = [] | ||
with NodeStrategy(args) as node: | ||
node_names = get_node_names(node=node, include_hidden_nodes=False) | ||
policy_dict = {} | ||
with DirectNode(args) as node: | ||
for node_name in node_names: | ||
subscribers = get_subscriber_info(node=node, node_name=node_name) | ||
publishers = get_publisher_info(node=node, node_name=node_name) | ||
services = get_service_info(node=node, node_name=node_name) | ||
topic_map = defaultdict(list) | ||
formatTopics(publishers, 'publish', topic_map) | ||
formatTopics(subscribers, 'subscribe', topic_map) | ||
formatted_topic_map = {} | ||
for topic_name, permission_list in topic_map.items(): | ||
formatted_topic_map[topic_name] = {'allow' : permission_list} | ||
service_map = defaultdict(list) | ||
formatTopics(services, 'reply', service_map) | ||
formatted_services_map = {} | ||
for service, permission_list in service_map.items(): | ||
formatted_services_map[service] = {'allow' : permission_list} | ||
policy_dict[node_name.name] = {'topics' : formatted_topic_map} | ||
policy_dict[node_name.name]['services'] = formatted_services_map | ||
import yaml | ||
from io import open | ||
formatted_policy_dict = {'nodes' : policy_dict} | ||
if policy_dict: | ||
with open(args.POLICY_FILE_PATH, 'w') as stream: | ||
yaml.dump(formatted_policy_dict, stream, default_flow_style=False) | ||
else: | ||
print("No nodes found to generate policies") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change necessary? I think it would be better not include it to help keep the PR succinct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would help keep the PR succinct, but then there would be different ways of describing the security for services(-request, -response) vs topics (ps). It makes the parsing and description of the elements more verbose and robust.