Skip to content

Commit

Permalink
if topic is malformed, just do not set anything
Browse files Browse the repository at this point in the history
  • Loading branch information
petersilva committed Sep 18, 2024
1 parent 7367b52 commit bca8bb9
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions sarracenia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,25 +526,17 @@ def deriveTopics(msg,o,inbound_topic,separator='.'):
"""
msg_topic = inbound_topic.split(separator)
# topic validation... deal with DMS topic scheme. https://github.com/MetPX/sarracenia/issues/1017
if 'topicCopy' in o and o['topicCopy']:
topicOverride=True
else:
topicOverride=False
if 'relPath' in msg:
path_topic = o['topicPrefix'] + os.path.dirname(msg['relPath']).split('/')

if msg_topic != path_topic:
topicOverride=True

# set subtopic if possible.
if msg_topic[0:len(o['topicPrefix'])] == o['topicPrefix']:
msg['subtopic'] = msg_topic[len(o['topicPrefix']):]
else:
topicOverride=True

topicOverride = 'topicCopy' in o and o['topicCopy']
if topicOverride:
msg['topic'] = inbound_topic
msg['_deleteOnPost'] |= set( ['topic'] )
else:
# if the topic isn't as expected by Sarracenia, leave subtopic unset.
# set subtopic if possible.
if msg_topic[0:len(o['topicPrefix'])] == o['topicPrefix']:
msg['subtopic'] = msg_topic[len(o['topicPrefix']):]
msg['_deleteOnPost'] |= set(['subtopic'])


def dumps(msg) -> str:
Expand Down

0 comments on commit bca8bb9

Please sign in to comment.