@@ -947,6 +947,7 @@ internal static class ConfigFileConstants
947947 internal static readonly string ScriptsToProcess = "ScriptsToProcess" ;
948948 internal static readonly string SessionType = "SessionType" ;
949949 internal static readonly string RoleCapabilities = "RoleCapabilities" ;
950+ internal static readonly string RoleCapabilityFiles = "RoleCapabilityFiles" ;
950951 internal static readonly string RunAsVirtualAccount = "RunAsVirtualAccount" ;
951952 internal static readonly string RunAsVirtualAccountGroups = "RunAsVirtualAccountGroups" ;
952953 internal static readonly string TranscriptDirectory = "TranscriptDirectory" ;
@@ -981,6 +982,7 @@ internal static class ConfigFileConstants
981982 new ConfigTypeEntry ( PowerShellVersion , new ConfigTypeEntry . TypeValidationCallback ( StringTypeValidationCallback ) ) ,
982983 new ConfigTypeEntry ( RequiredGroups , new ConfigTypeEntry . TypeValidationCallback ( HashtableTypeValidationCallback ) ) ,
983984 new ConfigTypeEntry ( RoleCapabilities , new ConfigTypeEntry . TypeValidationCallback ( StringArrayTypeValidationCallback ) ) ,
985+ new ConfigTypeEntry ( RoleCapabilityFiles , new ConfigTypeEntry . TypeValidationCallback ( StringArrayTypeValidationCallback ) ) ,
984986 new ConfigTypeEntry ( RoleDefinitions , new ConfigTypeEntry . TypeValidationCallback ( HashtableTypeValidationCallback ) ) ,
985987 new ConfigTypeEntry ( RunAsVirtualAccount , new ConfigTypeEntry . TypeValidationCallback ( BooleanTypeValidationCallback ) ) ,
986988 new ConfigTypeEntry ( RunAsVirtualAccountGroups , new ConfigTypeEntry . TypeValidationCallback ( StringArrayTypeValidationCallback ) ) ,
@@ -1391,6 +1393,7 @@ internal static class DISCUtils
13911393 private static readonly HashSet < string > s_allowedRoleCapabilityKeys = new HashSet < string > ( StringComparer . OrdinalIgnoreCase )
13921394 {
13931395 "RoleCapabilities" ,
1396+ "RoleCapabilityFiles" ,
13941397 "ModulesToImport" ,
13951398 "VisibleAliases" ,
13961399 "VisibleCmdlets" ,
@@ -1808,8 +1811,11 @@ private void MergeRoleRulesIntoConfigHash(Func<string, bool> roleVerifier)
18081811 }
18091812
18101813 // Takes the "RoleCapabilities" node in the config hash, and merges its values into the base configuration.
1814+ private const string PSRCExtension = ".psrc" ;
18111815 private void MergeRoleCapabilitiesIntoConfigHash ( )
18121816 {
1817+ List < string > psrcFiles = new List < string > ( ) ;
1818+
18131819 if ( _configHash . ContainsKey ( ConfigFileConstants . RoleCapabilities ) )
18141820 {
18151821 string [ ] roleCapabilities = TryGetStringArray ( _configHash [ ConfigFileConstants . RoleCapabilities ] ) ;
@@ -1821,18 +1827,51 @@ private void MergeRoleCapabilitiesIntoConfigHash()
18211827 string roleCapabilityPath = GetRoleCapabilityPath ( roleCapability ) ;
18221828 if ( String . IsNullOrEmpty ( roleCapabilityPath ) )
18231829 {
1824- string message = StringUtil . Format ( RemotingErrorIdStrings . CouldNotFindRoleCapability , roleCapability , roleCapability + ".psrc" ) ;
1830+ string message = StringUtil . Format ( RemotingErrorIdStrings . CouldNotFindRoleCapability , roleCapability , roleCapability + PSRCExtension ) ;
18251831 PSInvalidOperationException ioe = new PSInvalidOperationException ( message ) ;
18261832 ioe . SetErrorId ( "CouldNotFindRoleCapability" ) ;
18271833 throw ioe ;
18281834 }
18291835
1830- DISCPowerShellConfiguration roleCapabilityConfiguration = new DISCPowerShellConfiguration ( roleCapabilityPath , null ) ;
1831- IDictionary roleCapabilityConfigurationItems = roleCapabilityConfiguration . ConfigHash ;
1832- MergeConfigHashIntoConfigHash ( roleCapabilityConfigurationItems ) ;
1836+ psrcFiles . Add ( roleCapabilityPath ) ;
18331837 }
18341838 }
18351839 }
1840+
1841+ if ( ConfigHash . ContainsKey ( ConfigFileConstants . RoleCapabilityFiles ) )
1842+ {
1843+ string [ ] roleCapabilityFiles = TryGetStringArray ( ConfigHash [ ConfigFileConstants . RoleCapabilityFiles ] ) ;
1844+ if ( roleCapabilityFiles != null )
1845+ {
1846+ foreach ( var roleCapabilityFilePath in roleCapabilityFiles )
1847+ {
1848+ if ( ! Path . GetExtension ( roleCapabilityFilePath ) . Equals ( PSRCExtension , StringComparison . OrdinalIgnoreCase ) )
1849+ {
1850+ string message = StringUtil . Format ( RemotingErrorIdStrings . InvalidRoleCapabilityFileExtension , roleCapabilityFilePath ) ;
1851+ PSInvalidOperationException ioe = new PSInvalidOperationException ( message ) ;
1852+ ioe . SetErrorId ( "InvalidRoleCapabilityFileExtension" ) ;
1853+ throw ioe ;
1854+ }
1855+
1856+ if ( ! File . Exists ( roleCapabilityFilePath ) )
1857+ {
1858+ string message = StringUtil . Format ( RemotingErrorIdStrings . CouldNotFindRoleCapabilityFile , roleCapabilityFilePath ) ;
1859+ PSInvalidOperationException ioe = new PSInvalidOperationException ( message ) ;
1860+ ioe . SetErrorId ( "CouldNotFindRoleCapabilityFile" ) ;
1861+ throw ioe ;
1862+ }
1863+
1864+ psrcFiles . Add ( roleCapabilityFilePath ) ;
1865+ }
1866+ }
1867+ }
1868+
1869+ foreach ( var roleCapabilityFile in psrcFiles )
1870+ {
1871+ DISCPowerShellConfiguration roleCapabilityConfiguration = new DISCPowerShellConfiguration ( roleCapabilityFile , null ) ;
1872+ IDictionary roleCapabilityConfigurationItems = roleCapabilityConfiguration . ConfigHash ;
1873+ MergeConfigHashIntoConfigHash ( roleCapabilityConfigurationItems ) ;
1874+ }
18361875 }
18371876
18381877 // Merge a role / role capability hashtable into the master configuration hashtable
0 commit comments