public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.InputObject))
            {
                this.ResourceGroupName = this.InputObject.ResourceGroupName;
                this.Name = this.InputObject.Name;
            }

            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.Name = resourceIdentifier.ResourceName;
            }

            PSManagedHsm existingResource = null;

            try
            {
                existingResource = KeyVaultManagementClient.GetManagedHsm(this.Name, this.ResourceGroupName);
            }
            catch
            {
                existingResource = null;
            }

            if (existingResource == null)
            {
                throw new Exception(string.Format("A managed HSM with name '{0}' in resource group '{1}' does not exist. Please use New-AzManagedHsm to create a managed HSM with these properties.", this.Name, this.ResourceGroupName));
            }

            if (this.ShouldProcess(this.Name, string.Format("Updating managed HSM '{0}' in resource group '{1}'.", this.Name, this.ResourceGroupName)))
            {
                var result = KeyVaultManagementClient.UpdateManagedHsm(existingResource,
                                                                       new VaultCreationOrUpdateParameters
                {
                    Tags = Tag
                }, null);
                WriteObject(result);
            }
        }
Exemplo n.º 2
0
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.InputObject))
            {
                this.ResourceGroupName = this.InputObject.ResourceGroupName;
                this.Name = this.InputObject.Name;
            }

            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.Name = resourceIdentifier.ResourceName;
            }

            PSManagedHsm existingResource = null;

            try
            {
                existingResource = KeyVaultManagementClient.GetManagedHsm(this.Name, this.ResourceGroupName);
            }
            catch
            {
                existingResource = null;
            }

            if (existingResource == null)
            {
                throw new Exception(string.Format(Resources.HsmNotFound, this.Name, this.ResourceGroupName));
            }

            if (this.ShouldProcess(this.Name, string.Format(Resources.UpdateHsmShouldProcessMessage, this.Name, this.ResourceGroupName)))
            {
                var result = KeyVaultManagementClient.UpdateManagedHsm(existingResource,
                                                                       new VaultCreationOrUpdateParameters
                {
                    Tags = Tag
                }, null);
                WriteObject(result);
            }
        }
Exemplo n.º 3
0
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.InputObject))
            {
                this.ResourceGroupName = this.InputObject.ResourceGroupName;
                this.Name = this.InputObject.Name;
            }

            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.Name = resourceIdentifier.ResourceName;
            }

            PSManagedHsm existingResource = null;

            try
            {
                existingResource = KeyVaultManagementClient.GetManagedHsm(this.Name, this.ResourceGroupName);
            }
            catch
            {
                throw new Exception(string.Format(Resources.HsmNotFound, this.Name, this.ResourceGroupName));
            }

            if (this.ShouldProcess(this.Name, string.Format(Resources.UpdateHsmShouldProcessMessage, this.Name, this.ResourceGroupName)))
            {
                var result = KeyVaultManagementClient.UpdateManagedHsm(existingResource,
                                                                       new VaultCreationOrUpdateParameters
                {
                    // false is not accepted
                    EnablePurgeProtection = this.EnablePurgeProtection.IsPresent ? (true as bool?) : null,
                    PublicNetworkAccess   = this.PublicNetworkAccess,
                    Tags = this.Tag
                }, null);
                WriteObject(result);
            }
        }