Skip to content

Commit

Permalink
Small fixes, implemented check_env_name_on_rg.
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroon Feisal committed Apr 29, 2022
1 parent 3e576de commit a1ce4dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/containerapp/azext_containerapp/_up_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ def validate_environment_location(cmd, location):

location_count = {}
for loc in locations:
location_count[loc] = sum(1 for e in env_list if e["location"] == loc)
location_count[loc] = len([e for e in env_list if e["location"] == loc])

disallowed_locations = []
for _, value in enumerate(location_count):
Expand All @@ -802,10 +802,7 @@ def validate_environment_location(cmd, location):
res_locations = list_environment_locations(cmd)
res_locations = [l for l in res_locations if l not in disallowed_locations]

allowed_locs = ""
for res_loc in res_locations:
allowed_locs += res_loc + ", "
allowed_locs = allowed_locs[:-2]
allowed_locs = ", ".join(res_locations)

if location:
try:
Expand Down Expand Up @@ -839,6 +836,8 @@ def list_environment_locations(cmd):


def check_env_name_on_rg(cmd, managed_env, resource_group_name, location):
if location:
_ensure_location_allowed(cmd, location, "Microsoft.App", "managedEnvironments")
if managed_env and resource_group_name and location:
env_def = None
try:
Expand All @@ -847,4 +846,4 @@ def check_env_name_on_rg(cmd, managed_env, resource_group_name, location):
pass
if env_def:
if location != env_def["location"]:
raise ValidationError("Environment {} already exists in resource group {} on location {}, cannot change location of existing environment to {}.".format(parse_resource_id(managed_env)["name"], resource_group_name, env_def["location"]), location)
raise ValidationError("Environment {} already exists in resource group {} on location {}, cannot change location of existing environment to {}.".format(parse_resource_id(managed_env)["name"], resource_group_name, env_def["location"], location))
4 changes: 3 additions & 1 deletion src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2015,12 +2015,14 @@ def containerapp_up(cmd,
service_principal_tenant_id=None):
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, AzureContainerRegistry)
_get_registry_details, _create_github_action, _set_up_defaults, up_output, AzureContainerRegistry,
check_env_name_on_rg)
HELLOWORLD = "mcr.microsoft.com/azuredocs/containerapps-helloworld"
dockerfile = "Dockerfile" # for now the dockerfile name must be "Dockerfile" (until GH actions API is updated)

_validate_up_args(source, image, repo)
validate_container_app_name(name)
check_env_name_on_rg(cmd, managed_env, resource_group_name, location)

image = _reformat_image(source, repo, image)
token = None if not repo else get_github_access_token(cmd, ["admin:repo_hook", "repo", "workflow"], token)
Expand Down

0 comments on commit a1ce4dd

Please sign in to comment.