/// <summary> /// Processes the parameters to return a valid resource Id. /// </summary> /// <param name="subscriptionId">The subscription.</param> /// <param name="resourceGroupName">The resource group</param> /// <param name="parentResource">The parent resource in the format: '{resourceType}/{typeName}'</param> /// <param name="resourceType">The resource type string in the format: '{providerName}/{typeName}'</param> /// <param name="resourceName">The resource name in the format: '{resourceName}'</param> /// <returns></returns> public static string GetResourceId(Guid subscriptionId, string resourceGroupName, string parentResource, string resourceType, string resourceName) { var provider = ResourceIdUtility.GetProviderFromLegacyResourceTypeString(resourceType); resourceType = ResourceIdUtility.GetTypeFromLegacyResourceTypeString(resourceType); var parameters = new[] { subscriptionId.ToString(), resourceGroupName, provider, parentResource.Trim('/'), resourceType.Trim('/'), resourceName.Trim('/'), }; var parameteValues = parameters .Select(parameter => Uri.EscapeDataString(parameter)) .Cast <object>() .ToArray(); return(string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/{2}/{3}/{4}/{5}", parameteValues)); }
/// <summary> /// Gets either a resource type or resource Id based on the value of the <see cref="getResourceName"/> parameter. /// </summary> /// <param name="resourceId">The resource Id.</param> /// <param name="getResourceName">When set to true returns a resource name, otherwise a resource type.</param> /// <param name="includeProviderNamespace">Indicates if the provider namespace should be included in the resource name.</param> private static string GetExtensionResourceTypeOrName(string resourceId, bool getResourceName, bool includeProviderNamespace = true) { return(ResourceIdUtility.IsExtensionResourceId(resourceId) ? ResourceIdUtility.GetResourceTypeOrName(resourceId: resourceId, getResourceName: getResourceName, includeProviderNamespace: includeProviderNamespace, useLastSegment: true) : null); }
/// <summary> /// Gets a resource name /// </summary> /// <param name="resourceId">The resource Id.</param> public static string GetExtensionResourceName(string resourceId) { return(ResourceIdUtility.GetExtensionResourceTypeOrName(resourceId: resourceId, getResourceName: true)); }
/// <summary> /// Gets a resource type /// </summary> /// <param name="resourceId">The resource Id.</param> /// <param name="includeProviderNamespace">Indicates if the provider namespace should be included in the resource name.</param> public static string GetExtensionResourceType(string resourceId, bool includeProviderNamespace = true) { return(ResourceIdUtility.GetExtensionResourceTypeOrName(resourceId: resourceId, includeProviderNamespace: includeProviderNamespace, getResourceName: false)); }
/// <summary> /// Gets the extension provider namespace from the resource id. /// </summary> /// <param name="resourceId">The resource id.</param> public static string GetExtensionProviderNamespace(string resourceId) { return(ResourceIdUtility.IsExtensionResourceId(resourceId) ? ResourceIdUtility.GetNextSegmentAfter(resourceId: resourceId, segmentName: Constants.Providers, selectLastSegment: true) : null); }
/// <summary> /// Gets the deployment name /// </summary> /// <param name="resourceId">The resource Id.</param> public static string GetDeploymentName(string resourceId) { return(ResourceIdUtility.GetResourceTypeOrName(resourceId: resourceId, getResourceName: true, useLastSegment: true)); }
/// <summary> /// Gets the name of the resource group from the resource id. /// </summary> /// <param name="resourceId">The resource id.</param> public static string GetResourceGroupName(string resourceId) { return(ResourceIdUtility.GetNextSegmentAfter(resourceId: resourceId, segmentName: Constants.ResourceGroups)); }
/// <summary> /// Gets the subscription id from the resource id. /// </summary> /// <param name="resourceId">The resource id.</param> public static string GetSubscriptionId(string resourceId) { return(ResourceIdUtility.GetNextSegmentAfter(resourceId: resourceId, segmentName: Constants.Subscriptions)); }
/// <summary> /// Gets the management group id from the resource id. /// </summary> /// <param name="resourceId">The resource id.</param> public static string GetManagementGroupId(string resourceId) { return(resourceId.StartsWithInsensitively(Constants.ManagementGroupIdPrefix) ? ResourceIdUtility.GetNextSegmentAfter(resourceId: resourceId, segmentName: Constants.ManagementGroups) : null); }
/// <summary> /// Gets the provider namespace from the resource id. /// </summary> /// <param name="resourceId">The resource id.</param> public static string GetProviderNamespace(string resourceId) { return(ResourceIdUtility.GetNextSegmentAfter(resourceId: resourceId, segmentName: Constants.Providers)); }