Skip to content

Commit

Permalink
{ServiceConnector}: support function app in Service Connector passwor…
Browse files Browse the repository at this point in the history
…dless (#7202)
  • Loading branch information
xfz11 authored Jan 29, 2024
1 parent 7d8368b commit 90e4c37
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 26 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
===============
1.0.0
++++++
* Support function app

0.3.13
++++++
* AAD rebranding and make some improvements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=no-member, too-many-lines, anomalous-backslash-in-string, redefined-outer-name, no-else-raise, attribute-defined-outside-init

import struct
import sys
Expand Down Expand Up @@ -147,7 +148,7 @@ def enable_mi_for_db_linker(cmd, source_id, target_id, auth_info, client_type, c
return enable_mi_for_db_linker


# pylint: disable=no-self-use, unused-argument, too-many-instance-attributes
# pylint: disable=unused-argument, too-many-instance-attributes
def getTargetHandler(cmd, target_id, target_type, auth_info, client_type, connection_name, skip_prompt):
if target_type in {RESOURCE.Sql}:
return SqlHandler(cmd, target_id, target_type, auth_info, connection_name, skip_prompt)
Expand Down Expand Up @@ -505,7 +506,7 @@ def create_aad_user(self):
if not self.ip:
error_code = ''
error_res = re.search(
'\((\d{5})\)', str(e))
r'\((\d{5})\)', str(e))
if error_res:
error_code = error_res.group(1)
telemetry.set_exception(e, "Connect-Db-Fail-" + error_code)
Expand All @@ -523,7 +524,7 @@ def create_aad_user(self):
"Please confirm local environment can connect to database and try again.")
error_code = ''
error_res = re.search(
'\((\d{5})\)', str(e))
r'\((\d{5})\)', str(e))
if error_res:
error_code = error_res.group(1)
telemetry.set_exception(e, "Connect-Db-Fail-" + error_code)
Expand Down Expand Up @@ -693,7 +694,7 @@ def create_aad_user(self):
except AzureConnectionError as e:
logger.warning(e)
if 'password authentication failed' in str(e):
raise ValidationError('Please confirm current user as Microsoft Entra admin and try again.')
raise ValidationError('Please confirm current user as Microsoft Entra admin and try again.') from e
# allow local access
ip_address = self.ip or get_local_ip()
if not ip_address:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
RESOURCE.WebApp,
RESOURCE.ContainerApp,
RESOURCE.SpringCloud,
RESOURCE.SpringCloudDeprecated
RESOURCE.SpringCloudDeprecated,
RESOURCE.FunctionApp,
]

PASSWORDLESS_TARGET_RESOURCES = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def run_cli_cmd(cmd, retry=0, interval=0, should_retry_func=None):
except CLIInternalError as e:
error_code = 'Unknown'
error_res = re.search(
'\(([a-zA-Z]+)\)', str(e))
r'\(([a-zA-Z]+)\)', str(e))
if error_res:
error_code = error_res.group(1)
telemetry.set_exception(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string, namespace.command)
namespace.user_identity_auth_info = action

def get_action(self, values, option_string, command_name): # pylint: disable=no-self-use
def get_action(self, values, option_string, command_name):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
Expand Down Expand Up @@ -59,7 +59,7 @@ def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string, namespace.command)
namespace.system_identity_auth_info = action

def get_action(self, values, option_string, command_name): # pylint: disable=no-self-use
def get_action(self, values, option_string, command_name):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
Expand Down Expand Up @@ -87,7 +87,7 @@ def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string, namespace.command)
namespace.user_account_auth_info = action

def get_action(self, values, option_string, command_name): # pylint: disable=no-self-use
def get_action(self, values, option_string, command_name):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
Expand Down Expand Up @@ -117,7 +117,7 @@ def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string, namespace.command)
namespace.service_principal_auth_info_secret = action

def get_action(self, values, option_string, command_name): # pylint: disable=no-self-use
def get_action(self, values, option_string, command_name):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"azext.isPreview": true,
"azext.isPreview": false,
"azext.minCliCoreVersion": "2.53.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# --------------------------------------------------------------------------------------------


VERSION = '0.3.13'
VERSION = '1.0.0'
NAME = 'serviceconnector-passwordless'
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))
resource_group = 'servicelinker-cli-test-group'


@unittest.skip('Need environment prepared')
class Serviceconnector_passwordlessScenarioTest(ScenarioTest):

Expand Down Expand Up @@ -52,7 +53,6 @@ def test_aad_webapp_sql(self):
self.cmd('webapp connection delete --id {} --yes'.format(connection_id))
self.cmd('sql db delete -y -g {target_resource_group} -s {server} -n {database}')


def test_aad_spring_mysqlflexible(self):
self.kwargs.update({
'subscription': get_subscription_id(self.cli_ctx),
Expand Down Expand Up @@ -84,15 +84,13 @@ def test_aad_spring_mysqlflexible(self):
# delete connection
self.cmd('spring connection delete --id {} --yes'.format(connection_id))


# create connection
self.cmd('spring connection create mysql-flexible --connection {} --source-id {} --target-id {} '
'--client-type springboot --system-identity mysql-identity-id={}'.format(name, source_id, target_id, mysql_identity_id))
# delete connection
self.cmd('spring connection delete --id {} --yes'.format(connection_id))
self.cmd('mysql flexible-server db delete -y -g {target_resource_group} --server-name {server} --database-name {database}')


def test_aad_containerapp_postgresflexible(self):
default_container_name = 'simple-hello-world-container'
self.kwargs.update({
Expand Down Expand Up @@ -121,7 +119,7 @@ def test_aad_containerapp_postgresflexible(self):
# create
self.cmd('containerapp connection create postgres-flexible --connection {} --source-id {} --target-id {} '
'--system-identity --client-type springboot -c {}'.format(name, source_id, target_id, default_container_name))
configs = self.cmd('containerapp connection list-configuration --id {}'.format(connection_id)).get_output_in_json();
self.cmd('containerapp connection list-configuration --id {}'.format(connection_id)).get_output_in_json()
# clean
self.cmd('containerapp connection delete --id {} --yes'.format(connection_id))
#
Expand All @@ -132,7 +130,6 @@ def test_aad_containerapp_postgresflexible(self):
# self.cmd('containerapp connection delete --id {} --yes'.format(connection_id))
# self.cmd('postgres flexible-server delete -y -g {target_resource_group} -n {server}')


def test_aad_webapp_postgressingle(self):
self.kwargs.update({
'subscription': "d82d7763-8e12-4f39-a7b6-496a983ec2f4",
Expand All @@ -159,8 +156,7 @@ def test_aad_webapp_postgressingle(self):
# create
self.cmd('webapp connection create postgres-flexible --connection {} --source-id {} --target-id {} '
'--system-identity --client-type springboot'.format(name, source_id, target_id))
configs = self.cmd('webapp connection list-configuration --id {}'.format(connection_id)).get_output_in_json();

self.cmd('webapp connection list-configuration --id {}'.format(connection_id)).get_output_in_json()

def test_local_postgresflexible_passwordless(self):
self.kwargs.update({
Expand Down Expand Up @@ -214,7 +210,6 @@ def test_local_postgresflexible_passwordless(self):
# delete connection
self.cmd('connection delete --id {} --yes'.format(connection_id))


def test_local_mysqlflexible_passwordless(self):
self.kwargs.update({
'subscription': get_subscription_id(self.cli_ctx),
Expand Down Expand Up @@ -264,7 +259,6 @@ def test_local_mysqlflexible_passwordless(self):
# delete connection
self.cmd('connection delete --id {} --yes'.format(connection_id))


def test_local_postgres_passwordless(self):
self.kwargs.update({
'subscription': get_subscription_id(self.cli_ctx),
Expand Down Expand Up @@ -314,7 +308,6 @@ def test_local_postgres_passwordless(self):
# delete connection
self.cmd('connection delete --id {} --yes'.format(connection_id))


def test_local_sql_passwordless(self):
self.kwargs.update({
'subscription': get_subscription_id(self.cli_ctx),
Expand All @@ -329,7 +322,7 @@ def test_local_sql_passwordless(self):

# create connection
self.cmd('connection create sql -g {} --connection {} --target-id {} '
'--user-account --client-type springboot'.format(resource_group, name, target_id, user, password))
'--user-account --client-type springboot'.format(resource_group, name, target_id))

# list connection
self.cmd('connection list -g {}'.format(resource_group))
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.13'
VERSION = '1.0.0'
try:
from azext_serviceconnector_passwordless.config import VERSION
except ImportError:
Expand Down

0 comments on commit 90e4c37

Please sign in to comment.