Skip to content

Commit

Permalink
fix(parameter): adds validation on tree names
Browse files Browse the repository at this point in the history
The tree names must be 3-50 characters and can contain
alphabets, digits, _ and - per the UI console. This commit
ensures that the same validation is applied in the CLI.

Wrike Ticket: https://www.wrike.com/open.htm?id=1182850340
  • Loading branch information
pallabpain committed Jan 23, 2024
1 parent 695875f commit 5870508
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion riocli/parameter/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def upload_configurations(
"""
Upload a directories as configuration parameters.
"""
trees = filter_trees(path, tree_names)
try:
trees = filter_trees(path, tree_names)
except Exception as e:
click.secho('{} {}'.format(Symbols.ERROR, e), fg=Colors.RED)
raise SystemExit(1)

click.secho('Following configuration trees will be uploaded')
click.secho()
Expand Down
9 changes: 9 additions & 0 deletions riocli/parameter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import filecmp
import json
import os
import re
import typing
from filecmp import dircmp

Expand All @@ -39,6 +40,9 @@ def filter_trees(
if tree_names and each not in tree_names:
continue

if not is_valid_tree_name(each):
raise Exception('Invalid tree name \'{}\'. Tree name must be 3-50 characters '
'and can contain letters, digits, _ and -'.format(each))
trees.append(each)

if tree_names and not trees:
Expand Down Expand Up @@ -91,3 +95,8 @@ def phase3(self) -> None:
self.common_files,
shallow=False)
self.same_files, self.diff_files, self.funny_files = f_comp


def is_valid_tree_name(name: str) -> bool:
"""Validates a config tree name"""
return bool(re.match(r'^[0-9A-Za-z][0-9A-Za-z._-]{0,49}$', name))

0 comments on commit 5870508

Please sign in to comment.