/// <summary> /// Gets the name of the remediation that is being acted upon. /// </summary> /// <param name="name">The provided remediation name</param> /// <param name="resourceId">The full resource ID of the remediation resource</param> /// <param name="inputObject">The remediation input object</param> protected string GetRemediationName(string name = null, string resourceId = null, PSRemediation inputObject = null) { string remediationName = null; if (!string.IsNullOrEmpty(name)) { remediationName = name; } else if (!string.IsNullOrEmpty(resourceId)) { remediationName = ResourceIdHelper.GetResourceName(resourceId: resourceId); if (remediationName == null) { throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.Error_InvalidResourceId, RemediationCmdletBase.RemediationsFullyQualifiedResourceType), paramName: "ResourceId"); } } else if (inputObject != null) { remediationName = inputObject.Name; } return(remediationName); }
/// <summary> /// Gets the root scope of the remediation that is being acted upon. /// </summary> /// <param name="scope">The full scope</param> /// <param name="resourceId">The full resource ID of the remediation resource</param> /// <param name="managementGroupId">The management group ID</param> /// <param name="resourceGroupName">The resource group name</param> /// <param name="inputObject">The remediation input object</param> protected string GetRootScope(string scope = null, string resourceId = null, string managementGroupId = null, string resourceGroupName = null, PSRemediation inputObject = null) { string rootScope = null; if (!string.IsNullOrEmpty(resourceId)) { rootScope = ResourceIdHelper.GetRootScope(resourceId: resourceId, fullyQualifiedResourceType: RemediationCmdletBase.RemediationsFullyQualifiedResourceType); if (rootScope == null) { throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.Error_InvalidResourceId, RemediationCmdletBase.RemediationsFullyQualifiedResourceType), paramName: "ResourceId"); } } else if (!string.IsNullOrEmpty(scope)) { rootScope = scope.TrimEnd('/'); } else if (!string.IsNullOrEmpty(managementGroupId)) { rootScope = ResourceIdHelper.GetManagementGroupScope(managementGroupId: managementGroupId); } else if (!string.IsNullOrEmpty(resourceGroupName)) { rootScope = ResourceIdHelper.GetResourceGroupScope(subscriptionId: this.DefaultContext.Subscription.Id, resourceGroupName: resourceGroupName); } else if (inputObject != null) { rootScope = ResourceIdHelper.GetRootScope(resourceId: inputObject.Id, fullyQualifiedResourceType: RemediationCmdletBase.RemediationsFullyQualifiedResourceType); } else { // Subscription based retrieval is the default, pulls the subscription ID from context rootScope = ResourceIdHelper.GetSubscriptionScope(subscriptionId: this.DefaultContext.Subscription.Id); } return(rootScope); }
/// <summary> /// Gets a resource group scope. /// </summary> /// <param name="subscriptionId">The subscription ID.</param> /// <param name="resourceGroupName">The name of the resource group.</param> public static string GetResourceGroupScope(string subscriptionId, string resourceGroupName) { return($"{ResourceIdHelper.GetSubscriptionScope(subscriptionId)}/resourceGroups/{resourceGroupName}"); }