Skip to content

Commit

Permalink
Add raw permission type
Browse files Browse the repository at this point in the history
Update schema and transforms
as well as generating script

Signed-off-by: ruffsl <[email protected]>
  • Loading branch information
ruffsl committed Aug 7, 2019
1 parent 297b049 commit 0dca9b3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 20 deletions.
7 changes: 3 additions & 4 deletions sros2/scripts/dds_sql_to_sros2_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ def df_to_dds_policy(df):
__df = df.loc[namespace, name, :]
for mode in __df.index.get_level_values('mode').unique():
if not pd.isna(mode):
topics = etree.SubElement(profile, 'dds_topics')
topics = etree.SubElement(profile, 'raws')
topics.set(mode, "ALLOW")
for dds_topic in df['dds_topic'].loc[namespace, name, mode]:
topic = etree.SubElement(topics, 'dds_topic')
topic = etree.SubElement(topics, 'raw')
topic.text = dds_topic
return dds_policy

Expand All @@ -107,9 +107,8 @@ def dds_policy_to_sros2_policy(dds_policy):
etree.parse(
get_transport_template('dds', 'demangle.xsl')))

# TODO: update schema for dds_topics?
# Validate policy schema
# policy_xsd.assertValid(dds_policy)
policy_xsd.assertValid(dds_policy)

# Transform policy
sros2_policy = demangle_xsl(dds_policy)
Expand Down
11 changes: 11 additions & 0 deletions sros2/sros2/policy/schemas/policy.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<xs:complexType name="Profile">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="raws" minOccurs="1" type="RawExpressionList" />
<xs:element name="topics" minOccurs="1" type="TopicExpressionList" />
<xs:element name="services" minOccurs="1" type="ServicesExpressionList" />
<xs:element name="actions" minOccurs="1" type="ActionsExpressionList" />
Expand All @@ -34,6 +35,16 @@
<xs:attribute ref="xml:base" />
</xs:complexType>

<xs:complexType name="RawExpressionList">
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="raw" type="Expression" />
</xs:sequence>
<xs:attribute name="publish" type="RuleQualifier" use="optional" />
<xs:attribute name="relay" type="RuleQualifier" use="optional" />
<xs:attribute name="subscribe" type="RuleQualifier" use="optional" />
<xs:attribute ref="xml:base" />
</xs:complexType>

<xs:complexType name="TopicExpressionList">
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="topic" type="Expression" />
Expand Down
32 changes: 16 additions & 16 deletions sros2/sros2/policy/templates/dds/demangle.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -227,28 +227,28 @@
<xsl:param name="qualifier"/>

<xsl:if test="@publish = $qualifier">
<xsl:call-template name="dds_topics">
<xsl:call-template name="raws">
<xsl:with-param name="kind" select="'publish'"/>
<xsl:with-param name="qualifier" select="$qualifier"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="@subscribe = $qualifier">
<xsl:call-template name="dds_topics">
<xsl:call-template name="raws">
<xsl:with-param name="kind" select="'subscribe'"/>
<xsl:with-param name="qualifier" select="$qualifier"/>
</xsl:call-template>
</xsl:if>
</xsl:template>


<xsl:template name="dds_topics">
<xsl:template name="raws">
<xsl:param name="kind"/>
<xsl:param name="qualifier"/>

<xsl:for-each select="dds_topic">
<xsl:variable name="dds_topic_" select="text()" />
<xsl:variable name="prefix" select="substring-before($dds_topic_, '/')" />
<xsl:variable name="_dds_topic" select="substring-after($dds_topic_, $prefix)" />
<xsl:for-each select="raw">
<xsl:variable name="raw_" select="text()" />
<xsl:variable name="prefix" select="substring-before($raw_, '/')" />
<xsl:variable name="_raw" select="substring-after($raw_, $prefix)" />

<xsl:variable name="actions_"
select="document('')/xsl:stylesheet/
Expand All @@ -263,11 +263,11 @@
<xsl:variable name="action_match">
<xsl:for-each select="$actions_">
<xsl:variable name="suffix" select="
substring($_dds_topic,
string-length($_dds_topic) - string-length(@suffix) +1)" />
substring($_raw,
string-length($_raw) - string-length(@suffix) +1)" />
<xsl:if test="$suffix = @suffix">
<xsl:variable name="object" select="substring($_dds_topic, 1,
string-length($_dds_topic) - string-length($suffix))" />
<xsl:variable name="object" select="substring($_raw, 1,
string-length($_raw) - string-length($suffix))" />
<xsl:call-template name="actions">
<xsl:with-param name="action" select="$object"/>
<xsl:with-param name="kind" select="$kind"/>
Expand All @@ -282,11 +282,11 @@
<xsl:variable name="service_match">
<xsl:for-each select="$services_">
<xsl:variable name="suffix" select="
substring($_dds_topic,
string-length($_dds_topic) - string-length(@suffix) +1)" />
substring($_raw,
string-length($_raw) - string-length(@suffix) +1)" />
<xsl:if test="$suffix = @suffix">
<xsl:variable name="object" select="substring($_dds_topic, 1,
string-length($_dds_topic) - string-length($suffix))" />
<xsl:variable name="object" select="substring($_raw, 1,
string-length($_raw) - string-length($suffix))" />
<xsl:call-template name="services">
<xsl:with-param name="service" select="$object"/>
<xsl:with-param name="kind" select="$kind"/>
Expand All @@ -301,7 +301,7 @@
<xsl:variable name="topic_match">
<xsl:for-each select="$topics_">
<xsl:call-template name="topics">
<xsl:with-param name="topic" select="$_dds_topic"/>
<xsl:with-param name="topic" select="$_raw"/>
<xsl:with-param name="kind" select="$kind"/>
<xsl:with-param name="type" select="
$topics_[@prefix=$prefix and @suffix='']/@type"/>
Expand Down
33 changes: 33 additions & 0 deletions sros2/sros2/policy/templates/dds/permissions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<xsl:if test="@publish = $qualifier">
<xsl:apply-templates select="." mode="publish"/>
</xsl:if>
<xsl:if test="@relay = $qualifier">
<xsl:apply-templates select="." mode="relay"/>
</xsl:if>
<xsl:if test="@subscribe = $qualifier">
<xsl:apply-templates select="." mode="subscribe"/>
</xsl:if>
Expand All @@ -90,6 +93,36 @@
</xsl:if>
</xsl:template>

<xsl:template match="raws" mode="publish">
<publish>
<topics>
<xsl:for-each select="raw">
<topic><xsl:value-of select="text()"/></topic>
</xsl:for-each>
</topics>
</publish>
</xsl:template>

<xsl:template match="raws" mode="relay">
<relay>
<topics>
<xsl:for-each select="raw">
<topic><xsl:value-of select="text()"/></topic>
</xsl:for-each>
</topics>
</relay>
</xsl:template>

<xsl:template match="raws" mode="subscribe">
<subscribe>
<topics>
<xsl:for-each select="raw">
<topic><xsl:value-of select="text()"/></topic>
</xsl:for-each>
</topics>
</subscribe>
</xsl:template>

<xsl:template match="topics" mode="publish">
<publish>
<topics>
Expand Down

0 comments on commit 0dca9b3

Please sign in to comment.