@@ -400,10 +400,11 @@ protected override AzureSqlDatabaseModel GetEntity()
400
400
}
401
401
402
402
/// get auth headers for cross-sub and cross-tenant restore operations
403
- string targetSubscriptionId = ModelAdapter . Context ? . Subscription . Id ;
404
- string sourceSubscriptionId = ParseSourceSubscriptionIdFromResourceId ( ResourceId ) ;
403
+ string targetSubscriptionId = ModelAdapter . Context ? . Subscription ? . Id ;
404
+ string sourceSubscriptionId = ParseSubscriptionIdFromResourceId ( ResourceId ) ;
405
+ bool isCrossSubscriptionRestore = false ;
405
406
Dictionary < string , List < string > > auxAuthHeader = null ;
406
- if ( ! string . IsNullOrEmpty ( ResourceId ) && targetSubscriptionId != sourceSubscriptionId )
407
+ if ( ! string . IsNullOrEmpty ( sourceSubscriptionId ) && ! string . IsNullOrEmpty ( targetSubscriptionId ) && ! targetSubscriptionId . Equals ( sourceSubscriptionId , StringComparison . OrdinalIgnoreCase ) )
407
408
{
408
409
List < string > resourceIds = new List < string > ( ) ;
409
410
resourceIds . Add ( ResourceId ) ;
@@ -412,32 +413,34 @@ protected override AzureSqlDatabaseModel GetEntity()
412
413
{
413
414
auxAuthHeader = new Dictionary < string , List < string > > ( auxHeaderDictionary ) ;
414
415
}
416
+
417
+ isCrossSubscriptionRestore = true ;
415
418
}
416
419
417
- return ModelAdapter . RestoreDatabase ( this . ResourceGroupName , restorePointInTime , ResourceId , model , sourceSubscriptionId , auxAuthHeader ) ;
420
+ return ModelAdapter . RestoreDatabase ( this . ResourceGroupName , restorePointInTime , ResourceId , model , isCrossSubscriptionRestore , auxAuthHeader ) ;
418
421
}
419
422
420
423
/// <summary>
421
- /// Parse source subscription id from ResourceId
424
+ /// Parse subscription id from ResourceId
422
425
/// </summary>
423
- /// <returns>Source Subscription Id</returns>
424
- private string ParseSourceSubscriptionIdFromResourceId ( string resourceId )
426
+ /// <returns>Subscription Id</returns>
427
+ private string ParseSubscriptionIdFromResourceId ( string resourceId )
425
428
{
426
- if ( string . IsNullOrEmpty ( resourceId ) )
429
+ string subscriptionId = null ;
430
+ if ( ! string . IsNullOrEmpty ( resourceId ) )
427
431
{
428
- return null ;
429
- }
430
-
431
- string [ ] words = resourceId . Split ( '/' ) ;
432
- string sourceSubscriptionId = "" ;
433
- for ( int i = 0 ; i < words . Length ; i ++ )
434
- {
435
- if ( words [ i ] == "subscriptions" )
432
+ string [ ] words = resourceId . Split ( '/' ) ;
433
+ for ( int i = 0 ; i < words . Length - 1 ; i ++ )
436
434
{
437
- sourceSubscriptionId = words [ i + 1 ] ;
435
+ if ( "subscriptions" . Equals ( words [ i ] , StringComparison . OrdinalIgnoreCase ) )
436
+ {
437
+ subscriptionId = words [ i + 1 ] ;
438
+ break ;
439
+ }
438
440
}
439
441
}
440
- return sourceSubscriptionId ;
442
+
443
+ return subscriptionId ;
441
444
}
442
445
}
443
446
}
0 commit comments