/// <summary>
        /// Update an existing Managed HSM.
        /// </summary>
        /// <param name="existingManagedHsm">existing Managed HSM</param>
        /// <param name="parameters">HSM update parameters</param>
        /// <param name="graphClient">the active directory client</param>
        /// <returns>the updated Managed HSM</returns>
        public PSManagedHsm UpdateManagedHsm(PSManagedHsm existingManagedHsm, VaultCreationOrUpdateParameters parameters, IMicrosoftGraphClient graphClient = null)
        {
            if (existingManagedHsm == null)
            {
                throw new ArgumentNullException("existingManagedHsm");
            }
            if (existingManagedHsm.OriginalManagedHsm == null)
            {
                throw new ArgumentNullException("existingManagedHsm.OriginalManagedHsm");
            }

            //Update the vault properties in the object received from server
            var properties = existingManagedHsm.OriginalManagedHsm.Properties;

            properties.EnablePurgeProtection = parameters.EnablePurgeProtection;

            var response = KeyVaultManagementClient.ManagedHsms.Update(
                resourceGroupName: existingManagedHsm.ResourceGroupName,
                name: existingManagedHsm.Name,
                parameters: new ManagedHsm
            {
                Location = existingManagedHsm.Location,
                Sku      = new ManagedHsmSku
                {
                    Name = (ManagedHsmSkuName)Enum.Parse(typeof(ManagedHsmSkuName), existingManagedHsm.Sku)
                },
                Tags       = TagsConversionHelper.CreateTagDictionary(parameters.Tags, validate: true),
                Properties = properties
            });

            return(new PSManagedHsm(response, graphClient));
        }
        /// <summary>
        /// Update an existing Managed HSM. Only Tags can be updated currently.
        /// </summary>
        /// <param name="existingManagedHsm">existing Managed HSM</param>
        /// <param name="parameters">HSM update parameters</param>
        /// <param name="adClient">the active directory client</param>
        /// <returns>the updated Managed HSM</returns>
        public PSManagedHsm UpdateManagedHsm(PSManagedHsm existingManagedHsm, VaultCreationOrUpdateParameters parameters, ActiveDirectoryClient adClient = null)
        {
            if (existingManagedHsm == null)
            {
                throw new ArgumentNullException("existingManagedHsm");
            }
            if (existingManagedHsm.OriginalManagedHsm == null)
            {
                throw new ArgumentNullException("existingManagedHsm.OriginalManagedHsm");
            }

            //Update the vault properties in the object received from server
            var properties = existingManagedHsm.OriginalManagedHsm.Properties;

            // None property is allowed to be updated currently,
            // Can be added here in the furture

            var response = KeyVaultManagementClient.ManagedHsms.Update(
                resourceGroupName: existingManagedHsm.ResourceGroupName,
                name: existingManagedHsm.Name,
                parameters: new ManagedHsm
            {
                Location = existingManagedHsm.Location,
                Sku      = new ManagedHsmSku
                {
                    Name = (ManagedHsmSkuName)Enum.Parse(typeof(ManagedHsmSkuName), existingManagedHsm.Sku)
                },
                Tags       = TagsConversionHelper.CreateTagDictionary(parameters.Tags, validate: true),
                Properties = properties
            });

            return(new PSManagedHsm(response, adClient));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update an existing Managed HSM.
        /// </summary>
        /// <param name="existingManagedHsm">existing Managed HSM</param>
        /// <param name="parameters">HSM update parameters</param>
        /// <param name="graphClient">the active directory client</param>
        /// <returns>the updated Managed HSM</returns>
        public PSManagedHsm UpdateManagedHsm(PSManagedHsm existingManagedHsm, VaultCreationOrUpdateParameters parameters, IMicrosoftGraphClient graphClient = null)
        {
            if (existingManagedHsm == null)
            {
                throw new ArgumentNullException("existingManagedHsm");
            }
            if (existingManagedHsm.OriginalManagedHsm == null)
            {
                throw new ArgumentNullException("existingManagedHsm.OriginalManagedHsm");
            }

            //Update the vault properties in the object received from server
            var properties = existingManagedHsm.OriginalManagedHsm.Properties;

            properties.EnablePurgeProtection = parameters.EnablePurgeProtection;
            if (!string.IsNullOrEmpty(parameters.PublicNetworkAccess))
            {
                properties.PublicNetworkAccess       = parameters.PublicNetworkAccess;
                properties.NetworkAcls.DefaultAction = PublicNetworkAccess.Enabled.ToString().Equals(parameters.PublicNetworkAccess) ?
                                                       NetworkRuleAction.Allow.ToString() : NetworkRuleAction.Deny.ToString();
            }
            var response = KeyVaultManagementClient.ManagedHsms.Update(
                resourceGroupName: existingManagedHsm.ResourceGroupName,
                name: existingManagedHsm.Name,
                parameters: new ManagedHsm
            {
                Location = existingManagedHsm.Location,
                Sku      = new ManagedHsmSku
                {
                    Name = (ManagedHsmSkuName)Enum.Parse(typeof(ManagedHsmSkuName), existingManagedHsm.Sku)
                },
                Tags       = TagsConversionHelper.CreateTagDictionary(parameters.Tags, validate: true),
                Properties = properties
            });

            return(new PSManagedHsm(response, graphClient));
        }