Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate project and repo names for apply and init commands #1558

Merged
merged 1 commit into from
May 19, 2021
Merged
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
18 changes: 18 additions & 0 deletions sdk/python/feast/repo_operations.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import importlib
import os
import random
import re
import sys
from datetime import timedelta
from importlib.abc import Loader
from pathlib import Path
from typing import List, NamedTuple, Set, Union

import click
from click.exceptions import BadParameter

from feast import Entity, FeatureTable
from feast.feature_view import FeatureView
Expand Down Expand Up @@ -110,6 +112,12 @@ def apply_total(repo_config: RepoConfig, repo_path: Path):
sys.path.append("")
registry_config = repo_config.get_registry_config()
project = repo_config.project
if not_valid_name(project):
print(
f"{project} is not valid. Project name should only have "
f"alphanumerical values and underscores."
)
sys.exit(1)
registry = Registry(
registry_path=registry_config.path,
repo_path=repo_path,
Expand Down Expand Up @@ -262,6 +270,11 @@ def init_repo(repo_name: str, template: str):

from colorama import Fore, Style

if not_valid_name(repo_name):
raise BadParameter(
message="Name should be alphanumeric values and underscores",
param_hint="PROJECT_DIRECTORY",
)
repo_path = Path(os.path.join(Path.cwd(), repo_name))
repo_path.mkdir(exist_ok=True)
repo_config_path = repo_path / "feature_store.yaml"
Expand Down Expand Up @@ -314,6 +327,11 @@ def init_repo(repo_name: str, template: str):
click.echo()


def not_valid_name(name: str) -> bool:
"""Test project or repo names. True if names have characters other than alphanumeric values and underscores"""
return re.compile(r"\W+").search(name) is not None


def replace_str_in_file(file_path, match_str, sub_str):
with open(file_path, "r") as f:
contents = f.read()
Expand Down