GetResourceProviderFullName() private static method

Extracts the resource provider's full name - i.e portion of the non-wildcard prefix before the '/' Returns null if the nonWildCardPrefix does not contain a '/'
private static GetResourceProviderFullName ( string nonWildCardPrefix ) : string
nonWildCardPrefix string
return string
        /// <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());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a list of Provider operations in the case that the Actionstring input does not contain a wildcard
        /// </summary>
        private List <PSResourceProviderOperation> ProcessProviderOperationsWithoutWildCard(string actionString, Dictionary <string, string> resourceProvidersWithOperationsApi)
        {
            Dictionary <string, string> resourceProvidersToQuery = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);
            string providerFullName = GetAzureProviderOperationCommand.GetResourceProviderFullName(actionString);

            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);
            }

            List <PSResourceProviderOperation> operationsToDisplay = new List <PSResourceProviderOperation>();

            if (resourceProvidersToQuery.Count() > 0)
            {
                // Get all operations exposed by this single provider and find the one where the name matches the actionstring input
                ResourceIdentity identity = new ResourceIdentity()
                {
                    ResourceName = string.Empty,
                    ResourceType = "operations",
                    ResourceProviderNamespace  = resourceProvidersToQuery.Single().Key,
                    ResourceProviderApiVersion = resourceProvidersToQuery.Single().Value
                };

                IList <PSResourceProviderOperation> allResourceProviderOperations = this.ResourcesClient.ListPSProviderOperations(new List <ResourceIdentity>()
                {
                    identity
                });
                operationsToDisplay.AddRange(allResourceProviderOperations.Where(op => string.Equals(op.OperationName, actionString, StringComparison.InvariantCultureIgnoreCase)));
            }

            return(operationsToDisplay);
        }
        /// <summary>
        /// Gets a list of Provider operations in the case that the Actionstring input does not contain a wildcard
        /// </summary>
        private List <PSResourceProviderOperation> ProcessProviderOperationsWithoutWildCard(string actionString)
        {
            List <PSResourceProviderOperation> operationsToDisplay = new List <PSResourceProviderOperation>();
            string providerFullName = GetAzureProviderOperationCommand.GetResourceProviderFullName(actionString);

            if (!string.IsNullOrWhiteSpace(providerFullName))
            {
                // We have the full name of the provider. get operations metadata for this provider
                ProviderOperationsMetadata providerOperations = this.ResourcesClient.GetProviderOperationsMetadata(providerFullName);
                IEnumerable <PSResourceProviderOperation> flattenedProviderOperations = GetAzureProviderOperationCommand.GetPSOperationsFromProviderOperationsMetadata(providerOperations);
                operationsToDisplay.AddRange(flattenedProviderOperations.Where(op => string.Equals(op.Operation, actionString, StringComparison.OrdinalIgnoreCase)));
            }

            return(operationsToDisplay);
        }
Exemplo n.º 4
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);
        }