Example #1
0
        public override void ExecuteCmdlet()
        {
            CertificatePolicy certificatePolicy;

            if (InputObject != null)
            {
                VaultName = InputObject.VaultName.ToString();
                Name      = InputObject.Name.ToString();
            }

            try
            {
                certificatePolicy = this.DataServiceClient.GetCertificatePolicy(this.VaultName, this.Name);
            }
            catch (KeyVaultErrorException exception)
            {
                if (exception.Response.StatusCode != System.Net.HttpStatusCode.NotFound)
                {
                    throw;
                }

                certificatePolicy = null;
            }

            if (certificatePolicy != null)
            {
                this.WriteObject(PSKeyVaultCertificatePolicy.FromCertificatePolicy(certificatePolicy));
            }
        }
Example #2
0
        public override void ExecuteCmdlet()
        {
            if (ShouldProcess(Name, Properties.Resources.SetCertificatePolicy))
            {
                PSKeyVaultCertificatePolicy policy = new PSKeyVaultCertificatePolicy();

                switch (ParameterSetName)
                {
                case ExpandedRenewNumberParameterSet:
                case ExpandedRenewPercentageParameterSet:

                    // Validate input parameters
                    ValidateSubjectName();
                    ValidateDnsNames();
                    ValidateKeyUsage();
                    ValidateEkus();

                    policy = new PSKeyVaultCertificatePolicy
                    {
                        DnsNames        = DnsName,
                        KeyUsage        = KeyUsage,
                        Ekus            = Ekus,
                        Enabled         = !Disabled.IsPresent,
                        IssuerName      = IssuerName,
                        CertificateType = CertificateType,
                        RenewAtNumberOfDaysBeforeExpiry = RenewAtNumberOfDaysBeforeExpiry,
                        RenewAtPercentageLifetime       = RenewAtPercentageLifetime,
                        EmailAtNumberOfDaysBeforeExpiry = EmailAtNumberOfDaysBeforeExpiry,
                        EmailAtPercentageLifetime       = EmailAtPercentageLifetime,
                        SecretContentType = SecretContentType,
                        SubjectName       = SubjectName,
                        ValidityInMonths  = ValidityInMonths,
                        Kty        = KeyType,
                        Exportable = KeyNotExportable.IsPresent ? !KeyNotExportable.IsPresent : (bool?)null
                    };

                    if (ReuseKeyOnRenewal.HasValue)
                    {
                        policy.ReuseKeyOnRenewal = ReuseKeyOnRenewal.Value;
                    }

                    break;

                case ByValueParameterSet:
                    policy = InputObject;
                    break;
                }

                var resultantPolicy = DataServiceClient.UpdateCertificatePolicy(VaultName, Name, policy.ToCertificatePolicy());

                if (PassThru.IsPresent)
                {
                    this.WriteObject(PSKeyVaultCertificatePolicy.FromCertificatePolicy(resultantPolicy));
                }
            }
        }