Skip to content

Commit 883f52b

Browse files
tedhtchangwoop
authored andcommitted
validate project and repo names for apply and init commands (#1558)
Signed-off-by: ted chang <htchang@us.ibm.com>
1 parent 3112e33 commit 883f52b

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

sdk/python/feast/repo_operations.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import importlib
22
import os
33
import random
4+
import re
45
import sys
56
from datetime import timedelta
67
from importlib.abc import Loader
78
from pathlib import Path
89
from typing import List, NamedTuple, Set, Union
910

1011
import click
12+
from click.exceptions import BadParameter
1113

1214
from feast import Entity, FeatureTable
1315
from feast.feature_view import FeatureView
@@ -112,6 +114,12 @@ def apply_total(repo_config: RepoConfig, repo_path: Path):
112114
sys.path.append("")
113115
registry_config = repo_config.get_registry_config()
114116
project = repo_config.project
117+
if not_valid_name(project):
118+
print(
119+
f"{project} is not valid. Project name should only have "
120+
f"alphanumerical values and underscores."
121+
)
122+
sys.exit(1)
115123
registry = Registry(
116124
registry_path=registry_config.path,
117125
repo_path=repo_path,
@@ -267,6 +275,11 @@ def init_repo(repo_name: str, template: str):
267275

268276
from colorama import Fore, Style
269277

278+
if not_valid_name(repo_name):
279+
raise BadParameter(
280+
message="Name should be alphanumeric values and underscores",
281+
param_hint="PROJECT_DIRECTORY",
282+
)
270283
repo_path = Path(os.path.join(Path.cwd(), repo_name))
271284
repo_path.mkdir(exist_ok=True)
272285
repo_config_path = repo_path / "feature_store.yaml"
@@ -319,6 +332,11 @@ def init_repo(repo_name: str, template: str):
319332
click.echo()
320333

321334

335+
def not_valid_name(name: str) -> bool:
336+
"""Test project or repo names. True if names have characters other than alphanumeric values and underscores"""
337+
return re.compile(r"\W+").search(name) is not None
338+
339+
322340
def replace_str_in_file(file_path, match_str, sub_str):
323341
with open(file_path, "r") as f:
324342
contents = f.read()

0 commit comments

Comments
 (0)