@@ -412,12 +412,22 @@ public List<T> TopLevelWildcardFilter<T>(string resourceGroupName, string name,
412412
413413 if ( ! string . IsNullOrEmpty ( name ) )
414414 {
415- WildcardPattern pattern = new WildcardPattern ( name , WildcardOptions . IgnoreCase ) ;
416- output = output . Select ( t => new { Id = new ResourceIdentifier ( ( string ) GetPropertyValue ( t , idProperty ) ) , Resource = t } )
417- . Where ( p => IsMatch ( p . Id , "ResourceName" , pattern ) )
418- . Select ( r => r . Resource ) ;
415+ string [ ] parts = name . Split ( new [ ] { '/' } , StringSplitOptions . RemoveEmptyEntries ) ;
416+ List < WildcardPattern > patterns = new List < WildcardPattern > ( ) ;
417+ parts . ForEach ( p => patterns . Add ( new WildcardPattern ( p , WildcardOptions . IgnoreCase ) ) ) ;
418+ if ( parts . Length == 1 )
419+ {
420+ output = output . Select ( t => new { Id = new ResourceIdentifier ( ( string ) GetPropertyValue ( t , idProperty ) ) , Resource = t } )
421+ . Where ( p => IsMatch ( p . Id , "ResourceName" , patterns . Last ( ) ) )
422+ . Select ( r => r . Resource ) ;
423+ }
424+ else if ( parts . Length == 2 )
425+ {
426+ output = output . Select ( t => new { Id = new ResourceIdentifier ( ( string ) GetPropertyValue ( t , idProperty ) ) , Resource = t } )
427+ . Where ( p => IsMatch ( p . Id , "ResourceName" , patterns . Last ( ) ) && IsParentNameMatch ( p . Id , patterns . First ( ) ) )
428+ . Select ( r => r . Resource ) ;
429+ }
419430 }
420-
421431 }
422432 else
423433 {
@@ -466,6 +476,21 @@ private bool IsMatch<T>(T resource, string property, WildcardPattern pattern)
466476 return ! string . IsNullOrEmpty ( value ) && pattern . IsMatch ( value ) ;
467477 }
468478
479+ private bool IsParentNameMatch < T > ( T resource , WildcardPattern pattern )
480+ {
481+ string value = ( string ) GetPropertyValue ( resource , "ParentResource" ) ;
482+ if ( ! string . IsNullOrEmpty ( value ) )
483+ {
484+ int parentNameStartIdx = value . LastIndexOf ( '/' ) ;
485+ if ( parentNameStartIdx > 0 )
486+ {
487+ value = value . Substring ( parentNameStartIdx + 1 ) ;
488+ }
489+ return ! string . IsNullOrEmpty ( value ) && pattern . IsMatch ( value ) ;
490+ }
491+ return false ;
492+ }
493+
469494 public bool ShouldListBySubscription ( string resourceGroupName , string name )
470495 {
471496 if ( string . IsNullOrEmpty ( resourceGroupName ) )
0 commit comments