Skip to content

Commit 2ca8abb

Browse files
gansachgansach
authored andcommitted
[datamigration]: Add support for blob to Sql MI identity migrations (Azure#8748)
* feat(datamigration): add support for managed identity auth in Blob to SqlMi migrations * docs(datamigration): update package versioning * fix(datamigration): fix azdev style issues * fix(datamigration): make os checking more robust * fix(datamigration): add pylint exceptions to fix az styledev * docs(datamigration): add examples --------- Co-authored-by: gansach <gasachdeva@microsoft.com>
1 parent 72b4df9 commit 2ca8abb

File tree

7 files changed

+73
-6
lines changed

7 files changed

+73
-6
lines changed

src/datamigration/HISTORY.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
Release History
44
===============
55

6+
=======
7+
1.0.0b5
8+
++++++
9+
* [PARAMETER UPDATE] `az datamigration sql-managed-instance create`: `--source-location` now supports Managed Identity for accessing Azure Blob.
10+
611
=======
712
1.0.0b4
813
++++++

src/datamigration/azext_datamigration/generated/_help.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,28 @@
194194
ceGroups/testrg/providers/Microsoft.Sql/managedInstances/instance" --source-database-name "aaa" \
195195
--source-sql-connection authentication="WindowsAuthentication" data-source="aaa" encrypt-connection=true \
196196
password="placeholder" trust-server-certificate=true user-name="bbb" --resource-group "testrg" --target-db-name "db1"
197+
- name: Create or update a Database Migration resource using Azure Blob storage (via System-Assigned Managed Identity) as the backup source.
198+
text: |-
199+
az datamigration sql-managed-instance create --managed-instance-name "managedInstance1" \
200+
--source-location '{\\"AzureBlob\\":{\\"storageAccountResourceId\\":\\"/subscriptions/1111-2222-3333-4444/resourceGroups/RG/prooviders\
201+
/Microsoft.Storage/storageAccounts/MyStorage\\",\\"authType\\":\\"ManagedIdentity\\",\\"identity\\":{\\"type\\":\\"SystemAssigned\\"},\\"blobContainerName\\":\\"ContainerName\
202+
-X\\"}}' --migration-service "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/testrg/providers/Micr\
203+
osoft.DataMigration/sqlMigrationServices/testagent" --offline-configuration last-backup-name="last_backup_file_name" \
204+
offline=true --scope "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/testrg/providers/Microsoft.Sql\
205+
/managedInstances/instance" --source-database-name "aaa" --source-sql-connection authentication="WindowsAuthentication"\
206+
data-source="aaa" encrypt-connection=true password="placeholder" trust-server-certificate=true user-name="bbb" \
207+
--resource-group "testrg" --target-db-name "db1"
208+
- name: Create or update a Database Migration resource using Azure Blob storage (via User-Assigned Managed Identity) as the backup source.
209+
text: |-
210+
az datamigration sql-managed-instance create --managed-instance-name "managedInstance1" \
211+
--source-location '{\\"AzureBlob\\":{\\"storageAccountResourceId\\":\\"/subscriptions/1111-2222-3333-4444/resourceGroups/RG/prooviders\
212+
/Microsoft.Storage/storageAccounts/MyStorage\\",\\"authType\\":\\"ManagedIdentity\\",\\"identity\\":{\\"type\\":\\"UserAssigned\\",\\"userAssignedIdentities\\":{\\"/subscriptions/00000000-1111-2222-3333-444444444444/resourcegroups/testrg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-uami\":{}}},\\"blobContainerName\\":\\"ContainerName\
213+
-X\\"}}' --migration-service "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/testrg/providers/Micr\
214+
osoft.DataMigration/sqlMigrationServices/testagent" --offline-configuration last-backup-name="last_backup_file_name" \
215+
offline=true --scope "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/testrg/providers/Microsoft.Sql\
216+
/managedInstances/instance" --source-database-name "aaa" --source-sql-connection authentication="WindowsAuthentication"\
217+
data-source="aaa" encrypt-connection=true password="placeholder" trust-server-certificate=true user-name="bbb" \
218+
--resource-group "testrg" --target-db-name "db1"
197219
"""
198220

199221
helps['datamigration sql-managed-instance cancel'] = """

src/datamigration/azext_datamigration/manual/_help.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,28 @@
163163
-X\\"}}' --migration-service "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/testrg/providers/Micr\
164164
osoft.DataMigration/sqlMigrationServices/testagent" --offline-configuration last-backup-name="last_backup_file_name" \
165165
offline=true --scope "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/testrg/providers/Microsoft.Sql\
166+
/managedInstances/instance" --source-database-name "aaa" --source-sql-connection authentication="WindowsAuthentication"\
167+
data-source="aaa" encrypt-connection=true password="placeholder" trust-server-certificate=true user-name="bbb" \
168+
--resource-group "testrg" --target-db-name "db1"
169+
- name: Create or update a Database Migration resource using Azure Blob storage (via System-Assigned Managed Identity) as the backup source.
170+
text: |-
171+
az datamigration sql-managed-instance create --managed-instance-name "managedInstance1" \
172+
--source-location '{\\"AzureBlob\\":{\\"storageAccountResourceId\\":\\"/subscriptions/1111-2222-3333-4444/resourceGroups/RG/prooviders\
173+
/Microsoft.Storage/storageAccounts/MyStorage\\",\\"authType\\":\\"ManagedIdentity\\",\\"identity\\":{\\"type\\":\\"SystemAssigned\\"},\\"blobContainerName\\":\\"ContainerName\
174+
-X\\"}}' --migration-service "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/testrg/providers/Micr\
175+
osoft.DataMigration/sqlMigrationServices/testagent" --offline-configuration last-backup-name="last_backup_file_name" \
176+
offline=true --scope "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/testrg/providers/Microsoft.Sql\
177+
/managedInstances/instance" --source-database-name "aaa" --source-sql-connection authentication="WindowsAuthentication"\
178+
data-source="aaa" encrypt-connection=true password="placeholder" trust-server-certificate=true user-name="bbb" \
179+
--resource-group "testrg" --target-db-name "db1"
180+
- name: Create or update a Database Migration resource using Azure Blob storage (via User-Assigned Managed Identity) as the backup source.
181+
text: |-
182+
az datamigration sql-managed-instance create --managed-instance-name "managedInstance1" \
183+
--source-location '{\\"AzureBlob\\":{\\"storageAccountResourceId\\":\\"/subscriptions/1111-2222-3333-4444/resourceGroups/RG/prooviders\
184+
/Microsoft.Storage/storageAccounts/MyStorage\\",\\"authType\\":\\"ManagedIdentity\\",\\"identity\\":{\\"type\\":\\"UserAssigned\\",\\"userAssignedIdentities\\":{\\"/subscriptions/00000000-1111-2222-3333-444444444444/resourcegroups/testrg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-uami\":{}}},\\"blobContainerName\\":\\"ContainerName\
185+
-X\\"}}' --migration-service "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/testrg/providers/Micr\
186+
osoft.DataMigration/sqlMigrationServices/testagent" --offline-configuration last-backup-name="last_backup_file_name" \
187+
offline=true --scope "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/testrg/providers/Microsoft.Sql\
166188
/managedInstances/instance" --source-database-name "aaa" --source-sql-connection authentication="WindowsAuthentication"\
167189
data-source="aaa" encrypt-connection=true password="placeholder" trust-server-certificate=true user-name="bbb" \
168190
--resource-group "testrg" --target-db-name "db1"

src/datamigration/azext_datamigration/manual/helper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def is_valid_guid(guid):
7070
def is_base64(s):
7171
try:
7272
return base64.b64encode(base64.b64decode(s)).decode() == s
73-
except Exception:
73+
except Exception: # pylint: disable=broad-except
7474
return False
7575

7676

@@ -372,7 +372,7 @@ def get_latest_nuget_org_version(package_id):
372372
service_index_response = None
373373
try:
374374
service_index_response = requests.get("https://api.nuget.org/v3/index.json")
375-
except Exception:
375+
except Exception: # pylint: disable=broad-except
376376
print("Unable to connect to NuGet.org to check for updates.")
377377

378378
if (service_index_response is None or
@@ -530,7 +530,7 @@ def is_valid_ir_key_format(key):
530530
if not is_valid_guid(key_parts[1]) or not is_base64(key_parts[-1]):
531531
return False
532532
return True
533-
except Exception:
533+
except Exception: # pylint: disable=broad-except
534534
return False
535535

536536

@@ -539,7 +539,7 @@ def is_valid_ir_key_format(key):
539539
# -----------------------------------------------------------------------------------------------------------------
540540
def check_whether_gateway_installed(name):
541541

542-
import winreg
542+
import winreg # pylint: disable=import-error
543543
# Connecting to key in registry
544544
accessRegistry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
545545

@@ -626,7 +626,7 @@ def register_ir(key, installed_ir_path=None):
626626
# -----------------------------------------------------------------------------------------------------------------
627627
def get_cmd_file_path():
628628

629-
import winreg
629+
import winreg # pylint: disable=import-error
630630
try:
631631
# Connecting to key in registry
632632
accessRegistry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)

src/datamigration/azext_datamigration/vendored_sdks/datamigration/models/_models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,18 @@ class AzureBlob(msrest.serialization.Model):
193193
:type account_key: str
194194
:param blob_container_name: Blob container name where backups are stored.
195195
:type blob_container_name: str
196+
:param auth_type: Authentication type for accessing Azure Blob.
197+
:type auth_type: str
198+
:param identity: Identity details for authentication.
199+
:type identity: object
196200
"""
197201

198202
_attribute_map = {
199203
'storage_account_resource_id': {'key': 'storageAccountResourceId', 'type': 'str'},
200204
'account_key': {'key': 'accountKey', 'type': 'str'},
201205
'blob_container_name': {'key': 'blobContainerName', 'type': 'str'},
206+
'auth_type': {'key': 'authType', 'type': 'str'},
207+
'identity': {'key': 'identity', 'type': 'object'},
202208
}
203209

204210
def __init__(
@@ -209,6 +215,8 @@ def __init__(
209215
self.storage_account_resource_id = kwargs.get('storage_account_resource_id', None)
210216
self.account_key = kwargs.get('account_key', None)
211217
self.blob_container_name = kwargs.get('blob_container_name', None)
218+
self.auth_type = kwargs.get('auth_type', None)
219+
self.identity = kwargs.get('identity', None)
212220

213221

214222
class BackupConfiguration(msrest.serialization.Model):

src/datamigration/azext_datamigration/vendored_sdks/datamigration/models/_models_py3.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,18 @@ class AzureBlob(msrest.serialization.Model):
222222
:type account_key: str
223223
:param blob_container_name: Blob container name where backups are stored.
224224
:type blob_container_name: str
225+
:param auth_type: Authentication type for accessing Azure Blob.
226+
:type auth_type: str
227+
:param identity: Identity details for authentication.
228+
:type identity: object
225229
"""
226230

227231
_attribute_map = {
228232
'storage_account_resource_id': {'key': 'storageAccountResourceId', 'type': 'str'},
229233
'account_key': {'key': 'accountKey', 'type': 'str'},
230234
'blob_container_name': {'key': 'blobContainerName', 'type': 'str'},
235+
'auth_type': {'key': 'authType', 'type': 'str'},
236+
'identity': {'key': 'identity', 'type': 'object'},
231237
}
232238

233239
def __init__(
@@ -236,12 +242,16 @@ def __init__(
236242
storage_account_resource_id: Optional[str] = None,
237243
account_key: Optional[str] = None,
238244
blob_container_name: Optional[str] = None,
245+
auth_type: Optional[str] = None,
246+
identity: Optional[Dict[str, Dict[str, dict]]] = None,
239247
**kwargs
240248
):
241249
super(AzureBlob, self).__init__(**kwargs)
242250
self.storage_account_resource_id = storage_account_resource_id
243251
self.account_key = account_key
244252
self.blob_container_name = blob_container_name
253+
self.auth_type = auth_type
254+
self.identity = identity
245255

246256

247257
class BackupConfiguration(msrest.serialization.Model):

src/datamigration/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from setuptools import setup, find_packages
1111

1212
# HISTORY.rst entry.
13-
VERSION = '1.0.0b4'
13+
VERSION = '1.0.0b5'
1414

1515
# The full list of classifiers is available at
1616
# https://pypi.python.org/pypi?%3Aaction=list_classifiers

0 commit comments

Comments
 (0)