-
Notifications
You must be signed in to change notification settings - Fork 53
[WIP] Register common policies with the ament index #147
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
Open
mjcarroll
wants to merge
1
commit into
rolling
Choose a base branch
from
mjcarroll/register_policies
base: rolling
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,35 @@ | ||
| # Copyright 2019 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. | ||
|
|
||
| # | ||
| # Installed sros2 security policies and register with the ament resource index. | ||
| # | ||
| # :param ARGN: the policy files to install | ||
| # :type ARGN: list of strings | ||
| # | ||
| macro(sros2_cmake_install_policies) | ||
| if(${ARGC} GREATER 0) | ||
| _sros2_cmake_register_package_hook() | ||
| foreach(_policy_file ${ARGN}) | ||
| get_filename_component(_parent_folder "${_policy_file}" DIRECTORY) | ||
| install( | ||
| FILES ${_policy_file} | ||
| DESTINATION "share/${PROJECT_NAME}/${_parent_folder}" | ||
| ) | ||
| get_filename_component(_name "${_policy_file}" NAME) | ||
| list(APPEND _sros2_cmake_POLICY_FILES "${_parent_folder}/${_name}") | ||
| endforeach() | ||
| endif() | ||
| endmacro() | ||
|
|
This file contains hidden or 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,18 @@ | ||
| # Copyright 2019 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. | ||
|
|
||
| # register sros2 policies | ||
| ament_index_register_resource( | ||
| "sros2_policies" CONTENT "${_sros2_cmake_POLICY_FILES}") | ||
|
|
This file contains hidden or 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 hidden or 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,20 @@ | ||
| cmake_minimum_required(VERSION 3.5) | ||
| project(sros2_common_policies) | ||
|
|
||
| find_package(ament_cmake REQUIRED) | ||
| find_package(sros2_cmake REQUIRED) | ||
|
|
||
| if(BUILD_TESTING) | ||
| find_package(ament_lint_auto REQUIRED) | ||
| ament_lint_auto_find_test_dependencies() | ||
| endif() | ||
|
|
||
| sros2_cmake_install_policies( | ||
| policies/node.xml | ||
| policies/node/logging.xml | ||
| policies/node/parameters.xml | ||
| policies/node/time.xml | ||
| ) | ||
|
|
||
| ament_package( | ||
| ) |
This file contains hidden or 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,48 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import os | ||
|
|
||
| from ament_index_python import get_resource | ||
| from ament_index_python import get_resources | ||
| from ament_index_python import has_resource | ||
|
|
||
| from ament_index_python import get_package_share_directory | ||
|
|
||
| POLICIES_RESOURCE_TYPE = 'sros2_policies' | ||
|
|
||
| def get_package_names_with_policies(): | ||
| """Get the names of all packages that register policies in the ament index.""" | ||
| return list(get_resources(POLICIES_RESOURCE_TYPE).keys()) | ||
|
|
||
| def get_package_policies(*, package_name=None): | ||
| """ | ||
| Get all policies registered in the ament index for the given package. | ||
| :param package_name: whose policies are to be retrieved. | ||
| :return: a list of policy names. | ||
| """ | ||
| if not has_resource(POLICIES_RESOURCE_TYPE, package_name): | ||
| return [] | ||
| policies, _ = get_resource(POLICIES_RESOURCE_TYPE, package_name) | ||
| return policies.split(';') | ||
|
|
||
| def get_registered_policies(): | ||
| """ | ||
| Get all policies registered in the ament index. | ||
| :return: a list of (package name, policy file) tuples. | ||
| """ | ||
| return [ | ||
| (package_name, get_package_policies(package_name=package_name)) | ||
| for package_name in get_package_names_with_policies() | ||
| ] | ||
|
|
||
| if __name__ == "__main__": | ||
| policies = get_registered_policies() | ||
|
|
||
| for (package, policies) in get_registered_policies(): | ||
| print(package) | ||
| share_dir = get_package_share_directory(package) | ||
| for policy in policies: | ||
| print("\t" + policy) | ||
| print("\t" + os.path.join(share_dir, policy)) | ||
|
|
||
|
|
This file contains hidden or 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,21 @@ | ||
| <?xml version="1.0"?> | ||
| <package format="2"> | ||
| <name>sros2_common_policies</name> | ||
| <version>0.7.0</version> | ||
| <description>Common policies profiles for security nodes via SROS2</description> | ||
| <author email="michael@openrobotics.org">Michael Carroll</author> | ||
| <maintainer email="michael@openrobotics.org">Michael Carroll</maintainer> | ||
| <license>Apache 2.0</license> | ||
|
|
||
| <buildtool_depend>ament_cmake</buildtool_depend> | ||
|
|
||
| <build_depend>ament_cmake_test</build_depend> | ||
| <build_depend>sros2_cmake</build_depend> | ||
|
|
||
| <test_depend>ament_lint_auto</test_depend> | ||
| <test_depend>ament_lint_common</test_depend> | ||
|
|
||
| <export> | ||
| <build_type>ament_cmake</build_type> | ||
| </export> | ||
| </package> |
This file contains hidden or 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,6 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <profile xmlns:xi="http://www.w3.org/2003/XInclude"> | ||
| <sros2_policy package="sros2_common_policies" policy="node/logging.xml" /> | ||
| <sros2_policy package="sros2_common_policies" policy="node/time.xml" /> | ||
| <sros2_policy package="sros2_common_policies" policy="node/parameters.xml" /> | ||
| </profile> | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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,20 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <policy version="0.1.0" | ||
| xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
| <profiles> | ||
| <profile ns="/" node="talker"> | ||
| <xi:include href="common/node.xml" | ||
| xpointer="xpointer(/profile/*)"/> | ||
| <topics publish="ALLOW" > | ||
| <topic>chatter</topic> | ||
| </topics> | ||
| </profile> | ||
| <profile ns="/" node="listener"> | ||
| <xi:include href="common/node.xml" | ||
| xpointer="xpointer(/profile/*)"/> | ||
| <topics subscribe="ALLOW" > | ||
| <topic>chatter</topic> | ||
| </topics> | ||
| </profile> | ||
| </profiles> | ||
| </policy> |
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.
I think I'd prefer that assets inside the same package keep with using the conventional XML xinclude for importation, so that a preprocessor to recursively expand
<sros2_policy>tags would not be a requirement in reusing assets in the sros2 common package.