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

[appservice-kube] az webapp create: Fix TypeError: 'NoneType' object is not subscriptable #4518

Merged
merged 8 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
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
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')
StrawnSC marked this conversation as resolved.
Show resolved Hide resolved

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