Esempio n. 1
0
        public override void ExecuteCmdlet()
        {
            if (InputObject != null)
            {
                Name = InputObject.Name;
                ResourceGroupName = InputObject.ResourceGroupName;
                Location          = InputObject.Location;
            }
            else if (ResourceId != null)
            {
                var resourceIdentifier = new ResourceIdentifier(ResourceId);
                Name = resourceIdentifier.ResourceName;
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
            }

            if (InRemovedState.IsPresent && InRemovedState.ToBool())
            {
                ConfirmAction(
                    Force.IsPresent,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.PurgeManagedHsmWarning,
                        Name),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.PurgeManagedHsmWarningWhatIf,
                        Name),
                    Name,
                    () =>
                {
                    KeyVaultManagementClient.PurgeManagedHsm(
                        managedHsmName: Name,
                        location: Location);

                    if (PassThru)
                    {
                        WriteObject(true);
                    }
                });
            }
            else
            {
                // Get resource group name for Managed HSM
                ResourceGroupName = string.IsNullOrWhiteSpace(ResourceGroupName) ? GetResourceGroupName(Name, true) : ResourceGroupName;
                if (string.IsNullOrWhiteSpace(ResourceGroupName))
                {
                    throw new ArgumentException(string.Format(Resources.HsmNotFound, Name, ResourceGroupName));
                }

                ConfirmAction(
                    Force.IsPresent,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.RemoveHsmWarning,
                        Name),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.RemoveHsmWhatIfMessage,
                        Name),
                    Name,
                    () =>
                {
                    KeyVaultManagementClient.DeleteManagedHsm(
                        managedHsm: Name,
                        resourceGroupName: ResourceGroupName);

                    if (PassThru)
                    {
                        WriteObject(true);
                    }
                });
            }
        }