Skip to content

Commit

Permalink
Merge pull request #137 from haroonf/upnamevalidation
Browse files Browse the repository at this point in the history
Validate containerapp name.
  • Loading branch information
StrawnSC authored Jul 18, 2022
2 parents e55116f + 8cce1f9 commit 284bd3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/containerapp/azext_containerapp/_up_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,18 @@ def _get_registry_details(cmd, app: "ContainerApp", source):
)


def _validate_containerapp_name(name):
is_valid = True
is_valid = is_valid and name.lower() == name
is_valid = is_valid and len(name) <= 32
is_valid = is_valid and '--' not in name
name = name.replace('-', '')
is_valid = is_valid and name.isalnum()
is_valid = is_valid and name[0].isalpha()
if not is_valid:
raise ValidationError(f"Invalid Container App name {name}. A name must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character and cannot have '--'. The length must not be more than 32 characters.")


# attempt to populate defaults for managed env, RG, ACR, etc
def _set_up_defaults(
cmd,
Expand Down
4 changes: 3 additions & 1 deletion src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2288,11 +2288,13 @@ def containerapp_up(cmd,
from ._up_utils import (_validate_up_args, _reformat_image, _get_dockerfile_content, _get_ingress_and_target_port,
ResourceGroup, ContainerAppEnvironment, ContainerApp, _get_registry_from_app,
_get_registry_details, _create_github_action, _set_up_defaults, up_output,
check_env_name_on_rg, get_token)
check_env_name_on_rg, get_token, _validate_containerapp_name)
from ._github_oauth import cache_github_token
HELLOWORLD = "mcr.microsoft.com/azuredocs/containerapps-helloworld"
dockerfile = "Dockerfile" # for now the dockerfile name must be "Dockerfile" (until GH actions API is updated)

_validate_containerapp_name(name)

register_provider_if_needed(cmd, CONTAINER_APPS_RP)
_validate_up_args(cmd, source, image, repo, registry_server)
validate_container_app_name(name)
Expand Down

0 comments on commit 284bd3d

Please sign in to comment.