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 f58b365 commit 25c4cb1
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,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_dds_security_part.py dds_security_part_mustache.xml combine_default_profiles.py agent.refs /
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>
12 changes: 10 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#!/bin/bash -e

unset FASTRTPS_DEFAULT_PROFILES_FILE

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

/parse_dds_security_part.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
24 changes: 12 additions & 12 deletions parse_agent_refs.py → parse_dds_security_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import sys, os
import pystache

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

env_keystore = os.environ.get("ROS_SECURITY_KEYSTORE")
env_enclave_override = os.environ.get("ROS_SECURITY_ENCLAVE_OVERRIDE")
Expand Down Expand Up @@ -36,17 +36,17 @@
with open(key_path, "r") as f:
key = f.read().rstrip()

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

agent_refs_data = pystache.render(tmpl, {'enclave_path': enclave_path, 'key_p11': key })
dds_security_part_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")
if os.path.exists(agent_refs_file):
os.remove(agent_refs_file)
# Remove old dds_security_part.xml if exists
dds_security_part_file = os.path.join(dds_security_part_path, "dds_security_part.xml")
if os.path.exists(dds_security_part_file):
os.remove(dds_security_part_file)

# Write new agent.refs with sros params
with open(agent_refs_file, 'w') as f:
f.write(agent_refs_data)
# Write new dds_security_part.xml with sros params for combining
with open(dds_security_part_file, 'w') as f:
f.write(dds_security_part_data)

0 comments on commit 25c4cb1

Please sign in to comment.