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

[Service Connector] Make Fabric SQL target work in interactive mode #30871

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
)
from ._addon_factory import AddonFactory
from knack.arguments import CLIArgumentType
from .action import AddCustomizedKeys, AddAdditionalConnectionStringProperties
from .action import AddAdditionalConnectionStringProperties, AddCustomizedKeys


def add_source_resource_block(context, source, enable_id=True, target=None):
Expand Down Expand Up @@ -184,8 +184,8 @@ def add_connstr_props_argument(context):
# linter: length '--additional-connection-string-properties' longer than 22, so use abbreviation
context.argument('connstr_props', options_list=['--connstr-props'],
action=AddAdditionalConnectionStringProperties, nargs='*',
help='The addtional connection string properties used to for building connection string.')

help='The additional connection string properties used to build connection string.')

def add_target_type_argument(context, source):
TARGET_TYPES = [
Expand Down Expand Up @@ -317,6 +317,7 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
add_customized_keys_argument(c)
add_opt_out_argument(c)
add_connstr_props_argument(c)

with self.argument_context('{} connection update {}'.format(source.value, target.value)) as c:
add_client_type_argument(c, source, target)
add_connection_name_argument(c, source)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class CLIENT_TYPE(Enum):

RESOURCE.ContainerApp: '/subscriptions/{subscription}/resourceGroups/{target_resource_group}/providers/Microsoft.App/containerApps/{target_app_name}',

RESOURCE.FabricSql: 'https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/SqlDatabases/{sql_id}'
RESOURCE.FabricSql: 'https://api.fabric.microsoft.com/v1/workspaces/{fabric_workspace_uuid}/SqlDatabases/{fabric_sql_db_uuid}'
}


Expand Down Expand Up @@ -670,6 +670,16 @@ class CLIENT_TYPE(Enum):
}
},
RESOURCE.FabricSql: {
'fabric_workspace_uuid': {
'options': ['--fabric-workspace-uuid'],
'help': 'UUID of Fabric workspace which contains the target SQL database',
'placeholder': 'TargetFabricWorkspaceUUID'
},
'fabric_sql_db_uuid': {
'options': ['--fabric-sql-database-uuid'],
'help': 'UUID of the target Fabric SQL database',
'placeholder': 'TargetFabricSQLDatabaseUUID'
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ def get_resource_regex(resource):
return regex


def check_required_args(resource, cmd_arg_values):
def check_required_args(resource, cmd_arg_values, is_azure_resource=True):
'''Check whether a resource's required arguments are in cmd_arg_values
'''
args = re.findall(r'\{([^\{\}]*)\}', resource)
args.remove('subscription')

if is_azure_resource:
args.remove('subscription')
for arg in args:
if not cmd_arg_values.get(arg, None):
return False
Expand Down Expand Up @@ -747,7 +749,7 @@ def apply_target_args(cmd, namespace, arg_values):
'''
target = get_target_resource_name(cmd)
resource = TARGET_RESOURCES.get(target)
if check_required_args(resource, arg_values):
if check_required_args(resource, arg_values, target not in [RESOURCE.FabricSql]):
namespace.target_id = resource.format(
subscription=get_subscription_id(cmd.cli_ctx),
**arg_values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ def connection_create(cmd, client, # pylint: disable=too-many-locals,too-many-s
appinsights=None, # Resource.AppInsights
target_app_name=None, # Resource.ContainerApp
connstr_props=None, # Resource.FabricSql
fabric_workspace_uuid=None, fabric_sql_database_uuid=None,
):
auth_action = 'optOutAllAuth' if (opt_out_list is not None and
OPT_OUT_OPTION.AUTHENTICATION.value in opt_out_list) else None
Expand Down Expand Up @@ -344,7 +345,9 @@ def connection_create(cmd, client, # pylint: disable=too-many-locals,too-many-s
customized_keys=customized_keys,
opt_out_list=opt_out_list,
app_config_id=app_config_id,
connstr_props=connstr_props)
connstr_props=connstr_props,
fabric_workspace_uuid=fabric_workspace_uuid,
fabrick_sql_database_uuid=fabric_sql_database_uuid)
raise CLIInternalError("Fail to install `serviceconnector-passwordless` extension. Please manually install it"
" with `az extension add --name serviceconnector-passwordless --upgrade`"
" and rerun the command")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,23 @@ def __init__(self, method_name):
)

@record_only()
@unittest.skip('Needs passwordless extension released')
def test_webapp_fabric_e2e(self):
self.kwargs.update({
'subscription': get_subscription_id(self.cli_ctx),
'source_resource_group': 'azure-service-connector',
'site': 'DotNetAppSqlDb20240704',
'database': 'clitest'
'source_resource_group': 'rg-Test',
'site': 'TonyFabricTest'
})
name = 'testfabricconn'
source_id = SOURCE_RESOURCES.get(RESOURCE.WebApp).format(**self.kwargs)
connection_id = source_id + "/providers/Microsoft.ServiceLinker/linkers/" + name
target_id = 'https://api.fabric.microsoft.com/v1/workspaces/13c65326-ecab-43f6-8a05-60927aaa4cec/SqlDatabases/4fdf6efe-23a9-4d74-8c4a-4ecc70c4d323'
server = 'tcp:renzo-srv-6ae35870-c362-44b9-8389-ada214a46bb5-51240650dd56.database.windows.net,1433'
database = 'AzureServiceConnectorTestSqlDb-4fdf6efe-23a9-4d74-8c4a-4ecc70c4d323'
target_id = 'https://api.fabric.microsoft.com/v1/workspaces/6fb24b6c-6d5e-4533-91e7-1cc745b8b0f4/SqlDatabases/92f30990-7ba7-426c-a98d-c7a7565b81d2'

# prepare
self.cmd('webapp identity remove --ids {}'.format(source_id))

# create
self.cmd('webapp connection create fabric-sql --connection {} --source-id {} --target-id {} \
--system-identity --client-type dotnet --opt-out publicnetwork \
--connstr-props "Server={}" \
"Database={}" '.format(name, source_id, target_id, server, database)
--system-identity --client-type dotnet'.format(name, source_id, target_id)
)

# list connection
Expand All @@ -65,8 +59,7 @@ def test_webapp_fabric_e2e(self):

# update
self.cmd('webapp connection create fabric-sql --connection {} --source-id {} --target-id {} \
--system-identity --client-type python --opt-out publicnetwork \
--connstr-props "Server={}" "Database={}" '.format(name, source_id, target_id, server, database),
--system-identity --client-type python'.format(name, source_id, target_id),
checks = [ self.check('clientType', 'python')])

# list configuration
Expand Down