Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/activator/activator.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ def parse_next_visit(http_request):

# Message format is determined by the nextvisit-start deployment.
data = json.loads(event.data)
return FannedOutVisit(**data)
visit = FannedOutVisit(**data)
_log.debug("Unpacked message as %r.", visit)
return visit


def _filter_messages(messages):
Expand Down
12 changes: 8 additions & 4 deletions python/activator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,21 @@ def _parse_config(config: str) -> collections.abc.Mapping:
# when the input is invalid. If pickier matching is needed in the
# future, use a separate regex for filelist instead of making node
# more complex.
node = re.compile(r'\s*\(survey="(?P<survey>[\w\s]*)"\)='
node = re.compile(r'\s*\(survey="(?P<survey>[^"\n=]*)"\)='
r'(?:\[(?P<filelist>[^]]*)\]|none)(?:\s+|$)',
re.IGNORECASE)

items = {}
pos = 0
match = node.match(config, pos)
while match:
if match['filelist'] is not None:
filenames = [file.strip() for file in match['filelist'].split(',')] \
if match['filelist'] else []
if match['filelist']: # exclude None and ""; latter gives unexpected behavior with split
filenames = []
for file in match['filelist'].split(','):
file = file.strip()
if "\n" in file:
raise ValueError(f"Unexpected newline in '{file}'.")
filenames.append(file)
items[match['survey']] = filenames
else:
items[match['survey']] = []
Expand Down
28 changes: 28 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ def test_space(self):
[os.path.normpath(os.path.join(getPackageDir("ap_pipe"), "pipe lines", "Isr.yaml"))]
)

def test_extrachars(self):
config = PipelinesConfig('(survey="stylish-modern-survey")=[/etc/pipelines/SingleFrame.yaml] '
'(survey="ScriptParams4,6")=[${AP_PIPE_DIR}/pipelines/Isr.yaml] '
'(survey="slash/and\backslash")=[Default.yaml] '
)
self.assertEqual(
config.get_pipeline_files(dataclasses.replace(self.visit, survey="stylish-modern-survey")),
[os.path.normpath(os.path.join("/etc", "pipelines", "SingleFrame.yaml"))]
)
self.assertEqual(
config.get_pipeline_files(dataclasses.replace(self.visit, survey="ScriptParams4,6")),
[os.path.normpath(os.path.join(getPackageDir("ap_pipe"), "pipelines", "Isr.yaml"))]
)
self.assertEqual(
config.get_pipeline_files(dataclasses.replace(self.visit, survey="slash/and\backslash")),
["Default.yaml"]
)

def test_none(self):
config = PipelinesConfig('(survey="TestSurvey")=[None shall pass/pipelines/SingleFrame.yaml] '
'(survey="Camera Test")=None '
Expand Down Expand Up @@ -156,6 +174,16 @@ def test_commas(self):
'(survey="CameraTest")=[${AP_PIPE_DIR}/pipelines/Isr.yaml] '
)

def test_bad_line_breaks(self):
with self.assertRaises(ValueError):
PipelinesConfig('''(survey="Test
Survey")=[/etc/pipelines/SingleFrame.yaml]'''
)
with self.assertRaises(ValueError):
PipelinesConfig('''(survey="TestSurvey")=[/etc/pipelines/
SingleFrame.yaml]'''
)

def test_unlabeled(self):
with self.assertRaises(ValueError):
PipelinesConfig('(survey="TestSurvey")=[/etc/pipelines/SingleFrame.yaml], '
Expand Down