GetNonWildcardPrefix() private static method

Extracts the portion of the actionstring before the first wildcard character (*)
private static GetNonWildcardPrefix ( string actionString ) : string
actionString string
return string
コード例 #1
0
        /// <summary>
        /// Get a list of Provider operations in the case that the Actionstring input contains a wildcard
        /// </summary>
        private List <PSResourceProviderOperation> ProcessProviderOperationsWithWildCard(string actionString)
        {
            // Filter the list of all operation names to what matches the wildcard
            WildcardPattern wildcard = new WildcardPattern(actionString, WildcardOptions.IgnoreCase | WildcardOptions.Compiled);

            List <ProviderOperationsMetadata> providers = new List <ProviderOperationsMetadata>();

            string nonWildCardPrefix = GetAzureProviderOperationCommand.GetNonWildcardPrefix(actionString);

            if (string.IsNullOrWhiteSpace(nonWildCardPrefix))
            {
                // 'Get-AzureRmProviderOperation *' or 'Get-AzureRmProviderOperation */virtualmachines/*'
                // get operations for all providers
                providers.AddRange(this.ResourcesClient.ListProviderOperationsMetadata());
            }
            else
            {
                // Some string exists before the wild card character - potentially the full name of the provider.
                string providerFullName = GetAzureProviderOperationCommand.GetResourceProviderFullName(nonWildCardPrefix);
                if (!string.IsNullOrWhiteSpace(providerFullName))
                {
                    // we have the full name of the provider. 'Get-AzureRmProviderOperation Microsoft.Sql/servers/*'
                    // only query for that provider
                    providers.Add(this.ResourcesClient.GetProviderOperationsMetadata(providerFullName));
                }
                else
                {
                    // We have only a partial name of the provider, say Microsoft.*/* or Microsoft.*/*/read.
                    // query for all providers and then do prefix match on the operations
                    providers.AddRange(this.ResourcesClient.ListProviderOperationsMetadata());
                }
            }

            return(providers.SelectMany(p => GetPSOperationsFromProviderOperationsMetadata(p)).Where(operation => wildcard.IsMatch(operation.Operation)).ToList());
        }
コード例 #2
0
        /// <summary>
        /// Filters the list of resource providers that support operations api to return a list of those providers that match the action string input
        /// </summary>
        private static Dictionary <string, string> FilterResourceProvidersToQueryForOperations(string actionString, Dictionary <string, string> resourceProvidersWithOperationsApi)
        {
            Dictionary <string, string> resourceProvidersToQuery = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);

            string nonWildCardPrefix = GetAzureProviderOperationCommand.GetNonWildcardPrefix(actionString);

            if (string.IsNullOrWhiteSpace(nonWildCardPrefix))
            {
                // 'Get-AzureSecurableAction *' or 'Get-AzureSecurableAction */virtualmachines/*'
                resourceProvidersToQuery = resourceProvidersWithOperationsApi;
            }
            else
            {
                // Some string exists before the wild card character - potentially the full name of the provider.
                string providerFullName = GetAzureProviderOperationCommand.GetResourceProviderFullName(nonWildCardPrefix);

                if (!string.IsNullOrWhiteSpace(providerFullName))
                {
                    string apiVersion;
                    if (resourceProvidersWithOperationsApi.TryGetValue(providerFullName, out apiVersion))
                    {
                        // We have the full name of the provider and it supports the operations api - so it can be queried
                        resourceProvidersToQuery.Add(providerFullName, apiVersion);
                    }
                }
                else
                {
                    // We have only a partial name of the provider, say Microsoft.*/* or Microsoft.*/*/read.
                    resourceProvidersToQuery = resourceProvidersWithOperationsApi
                                               .Where(kvp => kvp.Key.StartsWith(nonWildCardPrefix, StringComparison.InvariantCultureIgnoreCase))
                                               .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                }
            }

            return(resourceProvidersToQuery);
        }