Skip to content

Commit

Permalink
{Service Connector} support webapp slot and rollback get identity ope…
Browse files Browse the repository at this point in the history
…ration (#6841)

* rollback az identity list

* fix

* Revert "fix"

This reverts commit a273080.

* support slot

* update history.rst

* lint
  • Loading branch information
xfz11 authored Oct 10, 2023
1 parent f5caab7 commit 9b6f591
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/serviceconnector-passwordless/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Release History
===============
0.3.12
++++++
* make some improvements and support slot.

0.3.11
++++++
* make some improvements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ def enable_mi_for_db_linker(cmd, source_id, target_id, auth_info, client_type, c
elif auth_info['auth_type'] == AUTHTYPES[AUTH_TYPE.UserIdentity]:
mi_client_id = auth_info.get('client_id')
mi_sub_id = auth_info.get('subscription_id')
umi_info_list = run_cli_cmd(
f'az rest -u /subscriptions/{mi_sub_id}/providers/Microsoft.ManagedIdentity/userAssignedIdentities?api-version=2023-01-31')
umi_info = [umi for umi in umi_info_list.get('value', []) if umi.get('properties', {}).get('clientId') == mi_client_id]
umi_info = run_cli_cmd(
f'az identity list --subscription {mi_sub_id} --query "[?clientId==\'{mi_client_id}\']"')
if umi_info is None or len(umi_info) == 0:
e = ResourceNotFoundError(
"No identity found for client id {}".format(mi_client_id))
Expand Down Expand Up @@ -993,23 +992,36 @@ def get_identity_pid(self):


class WebappHandler(SourceHandler):
def get_identity_name(self):
def __init__(self, source_id, source_type: RESOURCE):
super().__init__(source_id, source_type)
segments = parse_resource_id(self.source_id)
app_name = segments.get('name')
return app_name
self.app_name = segments.get('name')
self.slot_name = segments.get('child_name_1', None)

def get_identity_name(self):
if self.slot_name is not None:
return self.app_name + '/slots/' + self.slot_name
return self.app_name

def get_identity_pid(self):
logger.warning('Checking if WebApp enables System Identity...')
identity = run_cli_cmd(
'az webapp identity show --ids {}'.format(self.source_id))
'az webapp identity show --ids {}'.format(self.source_id)) if self.slot_name is None else run_cli_cmd(
'az webapp identity show --ids {} --slot {}'.format(self.source_id, self.slot_name))
if (identity is None or "SystemAssigned" not in identity.get('type')):
# assign system identity for spring-cloud
logger.warning('Enabling WebApp System Identity...')
run_cli_cmd(
'az webapp identity assign --ids {}'.format(self.source_id))
if self.slot_name is None:
run_cli_cmd(
'az webapp identity assign --ids {}'.format(self.source_id))

identity = run_cli_cmd(
'az webapp identity show --ids {}'.format(self.source_id), 15, 5, output_is_none)
identity = run_cli_cmd(
'az webapp identity show --ids {}'.format(self.source_id), 15, 5, output_is_none)
else:
run_cli_cmd(
'az webapp identity assign --ids {} --slot {}'.format(self.source_id, self.slot_name))
identity = run_cli_cmd(
'az webapp identity show --ids {} --slot {}'.format(self.source_id, self.slot_name), 15, 5, output_is_none)

if identity is None:
ex = CLIInternalError(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.46.0"
"azext.minCliCoreVersion": "2.53.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# --------------------------------------------------------------------------------------------


VERSION = '0.3.11'
VERSION = '0.3.12'
NAME = 'serviceconnector-passwordless'
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def connection_create_ext(cmd, client, # pylint: disable=too-many-locals,too-ma
# Resource.KubernetesCluster
cluster=None, scope=None, enable_csi=False,
customized_keys=None,
site=None, # Resource.WebApp
site=None, slot=None, # Resource.WebApp
spring=None, app=None, deployment='default', # Resource.SpringCloud
# Resource.*Postgres, Resource.*Sql*
server=None, database=None,
Expand All @@ -41,7 +41,7 @@ def connection_create_ext(cmd, client, # pylint: disable=too-many-locals,too-ma
new_addon, no_wait,
# Resource.KubernetesCluster
cluster, scope, enable_csi,
site,
site, slot,
spring, app, deployment,
server, database,
enable_mi_for_db_linker=get_enable_mi_for_db_linker_func(yes),
Expand Down
2 changes: 1 addition & 1 deletion src/serviceconnector-passwordless/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
logger.warn("Wheel is not available, disabling bdist_wheel hook")


VERSION = '0.3.11'
VERSION = '0.3.12'
try:
from azext_serviceconnector_passwordless.config import VERSION
except ImportError:
Expand Down

0 comments on commit 9b6f591

Please sign in to comment.