public IssuerBundle SetCertificateIssuer(
            string vaultName,
            string issuerName,
            string issuerProvider,
            string accountId,
            SecureString apiKey,
            KeyVaultCertificateOrganizationDetails organizationDetails)
        {
            if (string.IsNullOrEmpty(vaultName))
            {
                throw new ArgumentNullException("vaultName");
            }
            if (string.IsNullOrEmpty(issuerName))
            {
                throw new ArgumentNullException("issuerName");
            }
            if (string.IsNullOrEmpty(issuerProvider))
            {
                throw new ArgumentNullException("issuerProvider");
            }

            string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName);
            var    issuer       = new IssuerBundle
            {
                Provider            = issuerProvider,
                OrganizationDetails = organizationDetails == null ? null : organizationDetails.ToOrganizationDetails(),
            };

            if (!string.IsNullOrEmpty(accountId) || apiKey != null)
            {
                issuer.Credentials = new IssuerCredentials
                {
                    AccountId = accountId,
                    Password  = apiKey == null ? null : apiKey.ConvertToString(),
                };
            }

            IssuerBundle resultantIssuer;

            try
            {
                resultantIssuer = this.keyVaultClient.SetCertificateIssuerAsync(
                    vaultAddress,
                    issuerName,
                    issuer.Provider,
                    issuer.Credentials,
                    issuer.OrganizationDetails,
                    issuer.Attributes).GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                throw GetInnerException(ex);
            }

            return(resultantIssuer);
        }
        protected override void ProcessRecord()
        {
            if (ShouldProcess(string.Empty, Properties.Resources.CreateCertificateAdministrator))
            {
                var organizationDetails = new KeyVaultCertificateOrganizationDetails
                {
                    Id = Id,
                    AdministratorDetails = AdministratorDetails,
                };

                this.WriteObject(organizationDetails);
            }
        }
        internal static KeyVaultCertificateOrganizationDetails FromOrganizationalDetails(OrganizationDetails organizationalDetails)
        {
            if (organizationalDetails == null)
            {
                return(null);
            }

            var kvcOrganizationDetails = new KeyVaultCertificateOrganizationDetails
            {
                Id = organizationalDetails.Id,
                AdministratorDetails = KeyVaultCertificateAdministratorDetails.FromAdministratorDetails(organizationalDetails.AdminDetails),
            };

            return(kvcOrganizationDetails);
        }
        internal static KeyVaultCertificateOrganizationDetails FromOrganizationalDetails(OrganizationDetails organizationalDetails)
        {
            if (organizationalDetails == null)
            {
                return null;
            }

            var kvcOrganizationDetails = new KeyVaultCertificateOrganizationDetails
            {
                Id = organizationalDetails.Id,
                AdministratorDetails = KeyVaultCertificateAdministratorDetails.FromAdministratorDetails(organizationalDetails.AdminDetails),
            };

            return kvcOrganizationDetails;
        }
        internal static KeyVaultCertificateIssuer FromIssuer(IssuerBundle issuer)
        {
            if (issuer == null)
            {
                return(null);
            }

            var kvcIssuer = new KeyVaultCertificateIssuer
            {
                Name                = issuer.IssuerIdentifier.Name,
                IssuerProvider      = issuer.Provider,
                OrganizationDetails = KeyVaultCertificateOrganizationDetails.FromOrganizationalDetails(issuer.OrganizationDetails),
            };

            if (issuer.Credentials != null)
            {
                kvcIssuer.AccountId = issuer.Credentials.AccountId;
                kvcIssuer.ApiKey    = issuer.Credentials.Password == null ? null : issuer.Credentials.Password.ConvertToSecureString();
            }

            return(kvcIssuer);
        }
        public IssuerBundle SetCertificateIssuer(
            string vaultName,
            string issuerName,
            string issuerProvider,
            string accountId,
            SecureString apiKey,
            KeyVaultCertificateOrganizationDetails organizationDetails)
        {
            if (string.IsNullOrEmpty(vaultName))
                throw new ArgumentNullException("vaultName");
            if (string.IsNullOrEmpty(issuerName))
                throw new ArgumentNullException("issuerName");
            if (string.IsNullOrEmpty(issuerProvider))
                throw new ArgumentNullException("issuerProvider");

            string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName);
            var issuer = new IssuerBundle
            {
                Provider = issuerProvider,
                OrganizationDetails = organizationDetails == null ? null : organizationDetails.ToOrganizationDetails(),
            };

            if (!string.IsNullOrEmpty(accountId) || apiKey != null)
            {
                issuer.Credentials = new IssuerCredentials
                {
                    AccountId = accountId,
                    Password = apiKey == null ? null : apiKey.ConvertToString(),
                };
            }

            IssuerBundle resultantIssuer;
            try
            {
                resultantIssuer = this.keyVaultClient.SetCertificateIssuerAsync(
                    vaultAddress,
                    issuerName,
                    issuer.Provider,
                    issuer.Credentials,
                    issuer.OrganizationDetails,
                    issuer.Attributes).GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                throw GetInnerException(ex);
            }

            return resultantIssuer;
        }