@@ -54,6 +54,9 @@ public static class CmdletHelpers
54
54
private static readonly Regex AppServicePlanResourceIdRegex =
55
55
new Regex ( @"^\/subscriptions\/(?<subscriptionName>[^\/]+)\/resourceGroups\/(?<resourceGroupName>[^\/]+)\/providers\/Microsoft.Web\/serverFarms\/(?<serverFarmName>[^\/]+)$" , RegexOptions . IgnoreCase ) ;
56
56
57
+ private static readonly Regex KeyVaultResourceIdRegex =
58
+ new Regex ( @"^\/subscriptions\/(?<subscriptionName>[^\/]+)\/resourceGroups\/(?<resourceGroupName>[^\/]+)\/providers\/Microsoft.KeyVault\/vaults\/(?<vaultName>[^\/]+)$" , RegexOptions . IgnoreCase ) ;
59
+
57
60
private static readonly Dictionary < string , int > WorkerSizes = new Dictionary < string , int > ( StringComparer . OrdinalIgnoreCase ) { { "Small" , 1 } , { "Medium" , 2 } , { "Large" , 3 } , { "ExtraLarge" , 4 } } ;
58
61
59
62
private const string ProductionSlotName = "Production" ;
@@ -178,7 +181,7 @@ internal static bool ShouldUseDeploymentSlot(string webSiteName, string slotName
178
181
179
182
return result ;
180
183
}
181
-
184
+
182
185
internal static HostingEnvironmentProfile CreateHostingEnvironmentProfile ( string subscriptionId , string resourceGroupName , string aseResourceGroupName , string aseName )
183
186
{
184
187
var rg = string . IsNullOrEmpty ( aseResourceGroupName ) ? resourceGroupName : aseResourceGroupName ;
@@ -222,7 +225,7 @@ internal static string BuildMetricFilter(DateTime? startTime, DateTime? endTime,
222
225
223
226
return filter ;
224
227
}
225
-
228
+
226
229
internal static bool TryParseWebAppMetadataFromResourceId ( string resourceId , out string resourceGroupName ,
227
230
out string webAppName , out string slotName , bool failIfSlot = false )
228
231
{
@@ -271,6 +274,10 @@ internal static bool TryParseAppServicePlanMetadataFromResourceId(string resourc
271
274
return false ;
272
275
}
273
276
277
+ internal static bool IsValidAKVResourceId ( string resourceId )
278
+ {
279
+ return KeyVaultResourceIdRegex . Match ( resourceId ) . Success ;
280
+ }
274
281
internal static string GetSkuName ( string tier , int workerSize )
275
282
{
276
283
string sku ;
@@ -309,7 +316,7 @@ internal static string GetSkuName(string tier, int workerSize)
309
316
310
317
internal static string GetSkuName ( string tier , string workerSize )
311
318
{
312
- return GetSkuName ( tier , WorkerSizes [ workerSize ] ) ;
319
+ return GetSkuName ( tier , WorkerSizes [ workerSize ] ) ;
313
320
}
314
321
315
322
internal static bool IsDeploymentSlot ( string name )
@@ -373,6 +380,11 @@ internal static string GetSubscriptionIdFromResourceId(string resourceId)
373
380
return new ResourceIdentifier ( resourceId ) . Subscription ;
374
381
}
375
382
383
+ internal static ResourceIdentifier GetResourceDetailsFromResourceId ( string resourceId )
384
+ {
385
+ return new ResourceIdentifier ( resourceId ) ;
386
+ }
387
+
376
388
internal static void ExtractWebAppPropertiesFromWebApp ( Site webapp , out string resourceGroupName , out string webAppName , out string slot )
377
389
{
378
390
resourceGroupName = GetResourceGroupFromResourceId ( webapp . Id ) ;
@@ -414,26 +426,23 @@ internal static Certificate[] GetCertificates(ResourceClient resourceClient, Web
414
426
return certificates . ToArray ( ) ;
415
427
}
416
428
417
- internal static string CheckServicePrincipalPermissions ( ResourceClient resourceClient , KeyVaultClient keyVaultClient , string resourceGroupName , string keyVault )
429
+ internal static string CheckServicePrincipalPermissions ( ResourceClient resourceClient , KeyVaultClient keyVaultClient , string resourceGroupName , string keyVault , string kvSubscriptionId )
418
430
{
419
- var perm1 = " " ;
420
- var kv2 = keyVaultClient . GetKeyVault ( resourceGroupName , keyVault ) ;
421
- foreach ( var policy in kv2 . Properties . AccessPolicies )
431
+ var kv = keyVaultClient . GetKeyVault ( resourceGroupName , keyVault , kvSubscriptionId ) ;
432
+ foreach ( var policy in kv . Properties . AccessPolicies )
422
433
{
423
434
if ( policy . ObjectId == ( "f8daea97-62e7-4026-becf-13c2ea98e8b4" ) )
424
435
{
425
436
foreach ( var perm in policy . Permissions . Secrets )
426
437
{
427
- if ( ( perm == "Get" ) || ( perm == "get" ) )
438
+ if ( perm . ToLower ( ) == "get" )
428
439
{
429
- perm1 = perm ;
430
- Console . WriteLine ( "Success" ) ;
431
- break ;
440
+ return perm ;
432
441
}
433
442
}
434
443
}
435
444
}
436
- return perm1 . ToString ( ) ;
445
+ return string . Empty ;
437
446
}
438
447
439
448
internal static SiteConfigResource ConvertToSiteConfigResource ( this SiteConfig config )
0 commit comments