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

standardize regex and messaging for names #2003

Merged
merged 5 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 15 additions & 13 deletions src/_nebari/subcommands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ class GitRepoEnum(str, enum.Enum):

class InitInputs(schema.Base):
cloud_provider: ProviderEnum = ProviderEnum.local
project_name: schema.letter_dash_underscore_pydantic = ""
project_name: schema.project_name_pydantic = ""
domain_name: typing.Optional[str] = None
namespace: typing.Optional[schema.letter_dash_underscore_pydantic] = "dev"
namespace: typing.Optional[schema.namespace_pydantic] = "dev"
auth_provider: AuthenticationEnum = AuthenticationEnum.password
auth_auto_provision: bool = False
repository: typing.Union[str, None] = None
Expand Down Expand Up @@ -473,8 +473,8 @@ def init(
"--project",
"-p",
callback=typer_validate_regex(
schema.namestr_regex,
"Project name must begin with a letter and consist of letters, numbers, dashes, or underscores.",
schema.project_name_regex,
"Project name must (1) consist of only letters, numbers, hyphens, and underscores, (2) begin and end with a letter, and (3) contain between 3 and 32 characters.",
),
),
domain_name: typing.Optional[str] = typer.Option(
Expand All @@ -486,8 +486,8 @@ def init(
namespace: str = typer.Option(
"dev",
callback=typer_validate_regex(
schema.namestr_regex,
"Namespace must begin with a letter and consist of letters, numbers, dashes, or underscores.",
schema.namespace_regex,
"Namespace must begin and end with a letter and consist of letters, dashes, or underscores.",
),
),
region: str = typer.Option(
Expand Down Expand Up @@ -677,13 +677,15 @@ def guided_init_wizard(ctx: typer.Context, guided_init: str):

name_guidelines = """
The project name must adhere to the following requirements:
- Letters from A to Z (upper and lower case) and numbers
- Maximum accepted length of the name string is 16 characters
- Letters from A to Z (upper and lower case), numbers, hyphens, and dashes
- Length from 3 to 32 characters
- Begin and end with a letter
"""
if inputs.cloud_provider == ProviderEnum.aws.value.lower():
name_guidelines += "- Should NOT start with the string `aws`\n"
elif inputs.cloud_provider == ProviderEnum.azure.value.lower():
name_guidelines += "- Should NOT contain `-`\n"

#if inputs.cloud_provider == ProviderEnum.aws.value.lower():
iameskild marked this conversation as resolved.
Show resolved Hide resolved
# name_guidelines += "- Should NOT start with the string `aws`\n"
#elif inputs.cloud_provider == ProviderEnum.azure.value.lower():
# name_guidelines += "- Should NOT contain `-`\n"

# PROJECT NAME
rich.print(
Expand All @@ -694,7 +696,7 @@ def guided_init_wizard(ctx: typer.Context, guided_init: str):
inputs.project_name = questionary.text(
"What project name would you like to use?",
qmark=qmark,
validate=questionary_validate_regex(schema.namestr_regex),
validate=questionary_validate_regex(schema.project_name_regex),
).unsafe_ask()

# DOMAIN NAME
Expand Down
12 changes: 8 additions & 4 deletions src/nebari/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
from _nebari.version import __version__, rounded_ver_parse

# Regex for suitable project names
namestr_regex = r"^[A-Za-z][A-Za-z\-_]*[A-Za-z]$"
letter_dash_underscore_pydantic = pydantic.constr(regex=namestr_regex)
project_name_regex = r"^[A-Za-z][A-Za-z0-9\-_]{1,30}[A-Za-z]$"
iameskild marked this conversation as resolved.
Show resolved Hide resolved
project_name_pydantic = pydantic.constr(regex=project_name_regex)

# Regex for suitable namespaces
namespace_regex = r"^[A-Za-z][A-Za-z\-_]*[A-Za-z]$"
namespace_pydantic = pydantic.constr(regex=namespace_regex)

email_regex = "^[^ @]+@[^ @]+\\.[^ @]+$"
email_pydantic = pydantic.constr(regex=email_regex)
Expand Down Expand Up @@ -38,8 +42,8 @@ def to_yaml(cls, representer, node):


class Main(Base):
project_name: letter_dash_underscore_pydantic
namespace: letter_dash_underscore_pydantic = "dev"
project_name: project_name_pydantic
namespace: namespace_pydantic = "dev"
provider: ProviderEnum = ProviderEnum.local
# In nebari_version only use major.minor.patch version - drop any pre/post/dev suffixes
nebari_version: str = __version__
Expand Down