/// <summary> /// Get a list of available application stacks /// </summary> /// <param name="bearerToken">Azure Bearer Token</param> /// <param name="operatingSystem">Operating system to fetch the stacks for</param> /// <returns>List of application stacks for the operating system specified, or an empty list</returns> public static async Task <IList <ApplicationStack> > GetApplicationStacks(string bearerToken, OSTypeNamesEnum operatingSystem) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (!Enum.IsDefined(typeof(OSTypeNamesEnum), operatingSystem)) { throw new ArgumentOutOfRangeException(nameof(operatingSystem)); } RestApiResponse response = await RestApiClient.GETWithContinuations <ApplicationStack>( bearerToken, $"https://management.azure.com/providers/Microsoft.Web/availableStacks?osTypeSelected={Enum.GetName(typeof(OSTypeNamesEnum), operatingSystem)}", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <ApplicationStack>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <ApplicationStack> >(response.Body).Values); }
/// <summary> /// Get all geographic locations (Azure Data Centers) that are accessible to a particular subscription /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <param name="id">Guid of the subscription</param> /// <returns>List of locations. Empty list if there was a problem</returns> public static async Task <List <SubscriptionLocation> > ListLocations(string bearerToken, Guid id) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if ((id == Guid.Empty) || (id == default)) { throw new ArgumentNullException(nameof(id)); } RestApiResponse response = await RestApiClient.GETWithContinuations <SubscriptionLocation>( bearerToken, $"https://management.azure.com/subscriptions/{id:d}/locations", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <SubscriptionLocation>()); } return(JsonConvert.DeserializeObject <List <SubscriptionLocation> >(response.Body)); }
/// <summary> /// Get a list of all disk images in the subscription /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <param name="subscription">Guid of the subscription</param> /// <param name="resourceGroupName">(Optional) Set only if you wish to filter by resource group</param> /// <returns>List of disk images. Empty list if there are none or there was a problem</returns> public static async Task <List <DiskImage> > List(string bearerToken, Guid subscription, string?resourceGroupName = null) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if ((subscription == Guid.Empty) || (subscription == default)) { throw new ArgumentNullException(nameof(subscription)); } RestApiResponse response = await RestApiClient.GETWithContinuations <DiskImage>( bearerToken, $"https://management.azure.com/subscriptions/{subscription.ToString("d")}{(string.IsNullOrWhiteSpace(resourceGroupName) ? "" : "/resourceGroups/" + resourceGroupName)}/providers/Microsoft.Compute/images", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <DiskImage>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <DiskImage> >(response.Body).Values); }
/// <summary> /// List existing App Service Domains /// </summary> /// <param name="bearerToken">The Azure bearer token</param> /// <param name="subscription">Subscription Id for authorization</param> /// <param name="resourceGroupName">(Optional) Name of the Azure resource group the Azure App Service Domains are homed in. /// If not provided (NULL), lists all domains in the subscription</param> /// <returns>List of App Service Domain metadata, or empty list if not found</returns> public static async Task <IList <AppServiceDomain> > List(string bearerToken, Guid subscription, string?resourceGroupName = null) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } StringBuilder requestUri = new StringBuilder(); requestUri.Append($"https://management.azure.com/subscriptions/{subscription:d}"); if (!string.IsNullOrWhiteSpace(resourceGroupName)) { requestUri.Append($"/resourceGroups/{resourceGroupName}"); } requestUri.Append("/providers/Microsoft.DomainRegistration/domains"); RestApiResponse response = await RestApiClient.GETWithContinuations <AppServiceDomain>( bearerToken, requestUri.ToString(), CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <AppServiceDomain>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <AppServiceDomain> >(response.Body).Values); }
/// <summary> /// Get a list of web apps that have been deleted /// </summary> /// <param name="bearerToken">Azure Bearer Token</param> /// <param name="subscription">Subscription Id for authorization</param> /// <param name="locationCode">(Optional) The location code (eg: "westus") where the app was hosted</param> /// <returns>List of deleted applications or empty list</returns> public static async Task <IList <DeletedWebApp> > GetDeletedWebApps(string bearerToken, Guid subscription, string?locationCode = null) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } StringBuilder requestUri = new StringBuilder(); requestUri.Append($"https://management.azure.com/subscriptions/{subscription:d}/providers/Microsoft.Web"); if (!string.IsNullOrWhiteSpace(locationCode)) { requestUri.Append($"/locations/{locationCode}"); } requestUri.Append("/deletedSites"); RestApiResponse response = await RestApiClient.GETWithContinuations <DeletedWebAppProperties>( bearerToken, requestUri.ToString(), CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <DeletedWebApp>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <DeletedWebApp> >(response.Body).Values); }
/// <summary> /// Get all SKUs available to a subscription /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <param name="subscription">Guid of the subscription</param> /// <returns>List of resource skus available. Empty list if there are none or there was a problem</returns> public static async Task <List <ComputeResourceSku> > GetAllAvailableSizes(string bearerToken, Guid subscription) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } RestApiResponse response = await RestApiClient.GETWithContinuations <ComputeResourceSku>( bearerToken, $"https://management.azure.com/subscriptions/{subscription.ToString("d")}/providers/Microsoft.Compute/skus", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <ComputeResourceSku>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <ComputeResourceSku> >(response.Body).Values); }
/// <summary> /// Get certificates associated with the given certificate order /// </summary> /// <param name="bearerToken">The Azure bearer token</param> /// <param name="subscription">Subscription Id for authorization</param> /// <param name="resourceGroupName">Name of the resource group the certificate exists in</param> /// <param name="orderNickname">A nickname for the order, specified during order creation</param> /// <returns>List of certificates or empty list</returns> public static async Task <IList <IssuedCertificate> > GetCertificates(string bearerToken, Guid subscription, string resourceGroupName, string orderNickname) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(resourceGroupName)) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (string.IsNullOrWhiteSpace(orderNickname)) { throw new ArgumentNullException(nameof(orderNickname)); } RestApiResponse response = await RestApiClient.GETWithContinuations <IssuedCertificate>( bearerToken, $"https://management.azure.com/subscriptions/{subscription:d}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{orderNickname}/certificates", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <IssuedCertificate>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <IssuedCertificate> >(response.Body).Values); }
/// <summary> /// Get a list of usage information /// </summary> /// <param name="bearerToken">The authorization bearer token</param> /// <param name="subscription">Subscription Guid</param> /// <param name="locationName">Internal/short name of the location (eg: "westus")</param> /// <returns>List of usages. Empty list if there was a problem.</returns> public static async Task <List <Usage> > GetUsages(string bearerToken, Guid subscription, string locationName) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(locationName)) { throw new ArgumentNullException(nameof(locationName)); } RestApiResponse response = await RestApiClient.GETWithContinuations <Usage>( bearerToken, $"https://management.azure.com/subscriptions/{subscription.ToString("d")}/providers/Microsoft.Compute/locations/{locationName}/usages", "2019-03-01", null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <Usage>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <Usage> >(response.Body).Values); }
/// <summary> /// Get a list of providers at tenant scope. /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <param name="fetchMetadata">If true, adds additional metadata (mutually exclusive with <paramref name="fetchAliases"/>)</param> /// <param name="fetchAliases">If true, adds type aliases to the metdata (mutually exclusive with <paramref name="fetchMetadata"/>)</param> /// <returns>List of resource providers. Will be an empty list if there was a problem or there are no resource providers.</returns> public static async Task <List <ResourceProvider> > List(string bearerToken, bool fetchMetadata = false, bool fetchAliases = false) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } Dictionary <string, string> query = new Dictionary <string, string>(); if (fetchMetadata) { query.Add("$expand", "metadata"); } else if (fetchAliases) { query.Add("$expand", "resourceTypes/aliases"); } RestApiResponse response = await RestApiClient.GETWithContinuations <ResourceProvider>( bearerToken, "https://management.azure.com/providers", CLIENT_API_VERSION, query, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <ResourceProvider>()); } return(JsonConvert.DeserializeObject <List <ResourceProvider> >(response.Body)); }
/// <summary> /// Get metadata for all app service plans in the provided resource group /// </summary> /// <param name="bearerToken">Azure bearer token</param> /// <param name="subscription">Subscription for authorization</param> /// <param name="resourceGroupName">Name of the resource group the plan is homed in</param> /// <param name="detailed">Set to TRUE to fetch additional metadata (sometimes may take longer)</param> /// <returns>List of plans or empty list</returns> public static async Task <IList <AppServicePlan> > GetAppServicePlans(string bearerToken, Guid subscription, string?resourceGroupName = null, bool detailed = false) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == default) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(resourceGroupName)) { throw new ArgumentNullException(nameof(resourceGroupName)); } RestApiResponse response = await RestApiClient.GETWithContinuations <AppServicePlan>( bearerToken, $"https://management.azure.com/subscriptions/{subscription:d}{(string.IsNullOrWhiteSpace(resourceGroupName) ? "" : $"/resourceGroups/{resourceGroupName}")}/providers/Microsoft.Web/serverfarms",
/// <summary> /// Get a list of tenants. /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <returns>List of tenants. Will be an empty list if there was a problem.</returns> public static async Task <List <Tenant> > List(string bearerToken) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } RestApiResponse response = await RestApiClient.GETWithContinuations <Tenant>( bearerToken, "https://management.azure.com/tenants", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <Tenant>()); } return(JsonConvert.DeserializeObject <List <Tenant> >(response.Body)); }
/// <summary> /// List storage accounts /// </summary> /// <param name="bearerToken">Azure bearer token</param> /// <param name="subscription">Subscription for authorization</param> /// <param name="resourceGroupName">Name of the resource group the account is placed in (optional)</param> /// <returns>List of storage accounts or empty list</returns> public static async Task <List <StorageAccount> > List(string bearerToken, Guid subscription, string?resourceGroupName = null) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } ResourceUri uri = new ResourceUri(subscription, resourceGroupName, "Microsoft.Storage", "storageAccounts"); RestApiResponse response = await RestApiClient.GETWithContinuations <StorageAccount>( bearerToken, uri.ToAbsoluteAzureRMEndpointUri(), CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <StorageAccount>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <StorageAccount> >(response.Body).Values); }