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

[Synapse] az synapse ad-only-auth: New command group for supporting synapse azure ad only authentication #23227

Merged
merged 8 commits into from
Jul 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,9 @@ def cf_synapse_sql_script(cli_ctx, workspace_name):
return cf_synapse_client_artifacts_factory(cli_ctx, workspace_name).sql_script


def cf_synapse_client_azure_ad_only_authentications_factory(cli_ctx, *_):
return cf_synapse(cli_ctx).azure_ad_only_authentications


def cf_synapse_link_connection(cli_ctx, workspace_name):
return cf_synapse_client_artifacts_factory(cli_ctx, workspace_name).link_connection
35 changes: 35 additions & 0 deletions src/azure-cli/azure/cli/command_modules/synapse/manual/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,41 @@
--file 'path/test.sql'
"""

helps['synapse ad-only-auth'] = """
type: group
short-summary: Manage Azure Active Directly only Authentication settings for this Synapse workspace.
"""

helps['synapse ad-only-auth get'] = """
type: command
short-summary: Get a specific Azure Active Directly only Authentication property.
examples:
- name: Get a specific Azure Active Directly only Authentication property.
text: |-
az synapse ad-only-auth get --workspace-name testsynapseworkspace \\
-g testrg
"""

helps['synapse ad-only-auth enable'] = """
type: command
short-summary: Enable Azure Active Directly only Authentication for this Synapse workspace.
examples:
- name: Enable Azure Active Directly only Authentication for this Synapse workspace.
text: |-
az synapse ad-only-auth enable --workspace-name testsynapseworkspace \\
-g testresourcegroup
"""

helps['synapse ad-only-auth disable'] = """
type: command
short-summary: Disable Azure Active Directly only Authentication for this Synapse workspace.
examples:
- name: Disable Azure Active Directly only Authentication for this Synapse workspace.
text: |-
az synapse ad-only-auth disable --workspace-name testsynapseworkspace \\
-g testresourcegroup
"""

helps['synapse link-connection'] = """
type: group
short-summary: Manage Synapse's link connection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,11 @@ def load_arguments(self, _):
c.argument('output_folder', type=str, help='The name of the output folder')
c.argument('script_name', arg_type=name_type, help='The name of the KQL script.')

for scope in ['enable', 'disable']:
with self.argument_context('synapse ad-only-auth ' + scope) as c:
c.argument('workspace_name', arg_type=workspace_name_arg_type, help='The name of the workspace')
c.argument('resource_group_name', resource_group_name_type)

# synapse link connections
with self.argument_context('synapse link-connection list') as c:
c.argument('workspace_name', arg_type=workspace_name_arg_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def load_command_table(self, _):
from ._client_factory import cf_kusto_pool
from ._client_factory import cf_kusto_script
from ._client_factory import cf_kusto_scripts
from ._client_factory import cf_synapse_client_azure_ad_only_authentications_factory

def get_custom_sdk(custom_module, client_factory):
return CliCommandType(
Expand Down Expand Up @@ -207,6 +208,10 @@ def get_custom_sdk(custom_module, client_factory):
client_factory=cf_kusto_script,
)

synapse_adonlyauthentications_sdk = CliCommandType(
operations_tmpl='azure.mgmt.synapse.operations#AzureADOnlyAuthenticationsOperations.{}',
client_factory=cf_synapse_client_azure_ad_only_authentications_factory,
)
synapse_link_connection_sdk = CliCommandType(
operations_tmpl='azure.synapse.artifacts.operations#linkconnectionOperations.{}',
client_factory=None,
Expand Down Expand Up @@ -583,6 +588,13 @@ def get_custom_sdk(custom_module, client_factory):
g.custom_command('export', 'synapse_kusto_script_export')
g.custom_wait_command('wait', 'synapse_kusto_script_show')

with self.command_group('synapse ad-only-auth', command_type=synapse_adonlyauthentications_sdk,
custom_command_type=get_custom_sdk('adonlyauthentications', cf_synapse_client_azure_ad_only_authentications_factory),
client_factory=cf_synapse_client_azure_ad_only_authentications_factory) as g:
g.custom_command('enable', 'synapse_enable_adonly_auth')
g.custom_command('disable', 'synapse_disable_adonly_auth')
evelyn-ys marked this conversation as resolved.
Show resolved Hide resolved
g.command('get', 'list')

with self.command_group('synapse link-connection', synapse_link_connection_sdk,
custom_command_type=get_custom_sdk('artifacts', None)) as g:
g.custom_command('list', 'list_link_connection')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from azure.mgmt.synapse.models import AzureADOnlyAuthentication


def synapse_enable_adonly_auth(client, resource_group_name, workspace_name):
azure_ad_only_authentication_name = "default"
azure_ad_only_authentication_info = AzureADOnlyAuthentication(azure_ad_only_authentication=True)

return client.begin_create(resource_group_name, workspace_name,
azure_ad_only_authentication_name, azure_ad_only_authentication_info)


def synapse_disable_adonly_auth(client, resource_group_name, workspace_name):
azure_ad_only_authentication_name = "default"
azure_ad_only_authentication_info = AzureADOnlyAuthentication(azure_ad_only_authentication=False)

return client.begin_create(resource_group_name, workspace_name,
azure_ad_only_authentication_name, azure_ad_only_authentication_info)
Loading