Skip to content

Commit

Permalink
[appservice-kube] az webapp create: Fix TypeError: 'NoneType' objec…
Browse files Browse the repository at this point in the history
…t is not subscriptable (#4518)

* fix plan create and webapp create

* bump version, include bug fix from #4493, fix style, fix webapp update bug, add basic regression tests

* remove deprecated 'az webapp update' params

* fix TypeError: 'NoneType' object is not subscriptable

* bump version

* better error message for nonextant customlocation

* fix name
  • Loading branch information
StrawnSC authored Mar 16, 2022
1 parent f923b94 commit d2674f4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/appservice-kube/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.1.6
++++++
* Fix TypeError on 'az webapp create'

0.1.5
++++++
* SSL bind bug fix
Expand Down
29 changes: 20 additions & 9 deletions src/appservice-kube/azext_appservice_kube/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,27 +463,38 @@ def _get_kube_env_from_custom_location(cmd, custom_location, resource_group):
custom_location_name = parsed_custom_location.get("name")
resource_group = parsed_custom_location.get("resource_group")

_check_custom_location_exists(cmd, custom_location_name, resource_group)

client = _get_kube_client(cmd)
kube_envs = client.list_by_subscription()

for kube in kube_envs:
parsed_custom_location_2 = None

if kube.extended_location and kube.extended_location.type == "CustomLocation":
parsed_custom_location_2 = parse_resource_id(kube.extended_location.name)

matched_name = parsed_custom_location_2["name"].lower() == custom_location_name.lower()
matched_rg = parsed_custom_location_2.get("resource_group").lower() == resource_group.lower()
if matched_name and matched_rg:
kube_environment_id = kube.id
break
if is_valid_resource_id(kube.extended_location.name):
candidate_custom_location = parse_resource_id(kube.extended_location.name)
matched_name = candidate_custom_location.get("name", "").lower() == custom_location_name.lower()
matched_rg = candidate_custom_location.get("resource_group", "").lower() == resource_group.lower()
if matched_name and matched_rg:
kube_environment_id = kube.id
break

if not kube_environment_id:
raise ResourceNotFoundError('Unable to find Kube Environment associated to the Custom Location')

return kube_environment_id


def _check_custom_location_exists(cmd, name, resource_group):
from azure.core.exceptions import ResourceNotFoundError as E
custom_location_client = customlocation_client_factory(cmd.cli_ctx)
try:
custom_location_client.custom_locations.get(resource_name=name, resource_group_name=resource_group)
except E as e:
custom_locations = [cl.id for cl in custom_location_client.custom_locations.list_by_subscription()]
logger.warning(f"\nPlease choose a custom location from your subscription: \n{custom_locations}\n")
raise e


def _get_custom_location_id_from_custom_location(cmd, custom_location_name, resource_group_name):
if is_valid_resource_id(custom_location_name):
return custom_location_name
Expand Down
2 changes: 1 addition & 1 deletion src/appservice-kube/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# TODO: Confirm this is the right version number you want and it matches your
# HISTORY.rst entry.
VERSION = '0.1.5'
VERSION = '0.1.6'

# The full list of classifiers is available at
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down

0 comments on commit d2674f4

Please sign in to comment.