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 Aug 10, 2023
1 parent 52155a7 commit 6ba6d7e
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ RUN apt-get update && apt-get install -y python3-pip && \
ENTRYPOINT /entrypoint.sh
COPY entrypoint.sh /entrypoint.sh
COPY parse_agent_refs.py /parse_agent_refs.py
COPY agent.refs.mustache /agent.refs.mustache
COPY combine_default_profiles.py /combine_default_profiles.py
COPY dds_security_part_mustache.xml /dds_security_part_mustache.xml
COPY agent.refs /agent.refs

COPY --from=builder /main_ws/ros-*-microxrce-agent_*_amd64.deb /microxrce-agent.deb
Expand Down
66 changes: 66 additions & 0 deletions combine_default_profiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/python3

import sys, os, re
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)

sec_part_data = ""
add_sec_part = False
if os.path.exists(dds_security_part_file):
add_sec_part = True
with open(dds_security_part_file, "r") as f:
sec_part_data = f.read()
else:
print("No ROS2 security additions found for default profiles")

### Combine original profiles data to agent.refs
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()

# Replace participant profile name
if line_str.startswith("<participant profile_name="):
line = re.sub(
'<participant profile_name="\S+"',
'<participant profile_name="default_xrce_participant"',
line)

# 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 add_sec_part and 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 6ba6d7e

Please sign in to comment.