Skip to content

Commit

Permalink
Utilize fog default dds profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
jnippula committed May 24, 2023
1 parent 2fbb462 commit 83e8e5a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ RUN ln -s /usr/local/lib/libmicroxrcedds_agent.so.2.2.0 /usr/local/lib/libmicrox
ENV PATH="/usr/local/bin:$PATH" \
LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"

COPY entrypoint.sh parse_agent_refs.py agent.refs.mustache agent.refs /
COPY entrypoint.sh parse_agent_refs.py combine_default_profiles.py dds_security_part_mustache.xml agent.refs /
4 changes: 2 additions & 2 deletions agent.refs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<profiles>
<participant profile_name="default_xrce_participant">
<participant profile_name="participant_profile_fog_sw">
<domainId>0</domainId>
<rtps>
<name>default_xrce_participant</name>
<name>participant_profile_fog_sw</name>
</rtps>
</participant>
</profiles>
59 changes: 59 additions & 0 deletions combine_default_profiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/python3

import sys, os
import shutil

agent_refs_path=""
if len(sys.argv) > 1:
agent_refs_path=sys.argv[1]

dds_security_part_file = os.path.join(agent_refs_path, "dds_security_part.xml")
default_profiles_file = os.path.join(agent_refs_path, "default_profiles.xml")
agent_refs_tmp_file = os.path.join(agent_refs_path, "agent.refs.tmp")
agent_refs_file = os.path.join(agent_refs_path, "agent.refs")

def cleanup_temporary_files():
# cleanup
if os.path.exists(agent_refs_tmp_file):
os.remove(agent_refs_tmp_file)
if os.path.exists(default_profiles_file):
os.remove(default_profiles_file)
if os.path.exists(dds_security_part_file):
os.remove(dds_security_part_file)


if not os.path.exists(dds_security_part_file):
print("No ROS2 security additions found for default profiles")
cleanup_temporary_files()
sys.exit(0)

sec_part_data = ""
with open(dds_security_part_file, "r") as f:
sec_part_data = f.read()

### Combine security part to original profiles data
keep_config = True
with open(default_profiles_file, "r") as in_f:
with open(agent_refs_tmp_file, "w") as out_f:
for line in in_f.readlines():
line_str = line.strip()
# Remove data_reader and data_writer configs
# as they conflicts with xrce client side configs
if line_str.startswith("<data_writer") or line_str.startswith("<data_reader"):
keep_config = False

if keep_config:
out_f.write(line)
if line_str.startswith("<rtps>"):
out_f.write(sec_part_data)

if line_str.startswith("</data_writer") or line_str.startswith("</data_reader"):
keep_config = True

# Replace original agent.refs with generated one
if os.path.exists(agent_refs_tmp_file):
if os.path.exists(agent_refs_file):
os.remove(agent_refs_file)
shutil.copyfile(agent_refs_tmp_file, agent_refs_file)

cleanup_temporary_files()
8 changes: 0 additions & 8 deletions agent.refs.mustache → dds_security_part_mustache.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
<profiles>
<participant profile_name="default_xrce_participant">
<domainId>0</domainId>
<rtps>
<name>default_xrce_participant</name>
<propertiesPolicy>
<properties>
<!-- Activate DDS:Auth:PKI-DH plugin -->
Expand Down Expand Up @@ -58,6 +53,3 @@
</property>
</properties>
</propertiesPolicy>
</rtps>
</participant>
</profiles>
10 changes: 9 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#!/bin/bash -e

unset FASTRTPS_DEFAULT_PROFILES_FILE

if [ "$FASTRTPS_DEFAULT_PROFILES_FILE" != "" ]; then
cp $FASTRTPS_DEFAULT_PROFILES_FILE /default_profiles.xml
else
cp agent.refs default_profiles.xml
fi

/parse_agent_refs.py
/combine_default_profiles.py

unset FASTRTPS_DEFAULT_PROFILES_FILE

_term() {
# FILL UP PROCESS SEARCH PATTERN HERE TO FIND PROPER PROCESS FOR SIGINT:
Expand Down
4 changes: 2 additions & 2 deletions parse_agent_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
with open(key_path, "r") as f:
key = f.read().rstrip()

agent_refs_must_file = os.path.join(agent_refs_path, "agent.refs.mustache")
agent_refs_must_file = os.path.join(agent_refs_path, "dds_security_part_mustache.xml")
with open(agent_refs_must_file, "r") as f:
tmpl = f.read()

agent_refs_data = pystache.render(tmpl, {'enclave_path': enclave_path, 'key_p11': key })

# Remove original agent.refs
agent_refs_file = os.path.join(agent_refs_path, "agent.refs")
agent_refs_file = os.path.join(agent_refs_path, "dds_security_part.xml")
if os.path.exists(agent_refs_file):
os.remove(agent_refs_file)

Expand Down

0 comments on commit 83e8e5a

Please sign in to comment.