public override void ExecuteCmdlet() { var hostnameConfig = new PsApiManagementCustomHostNameConfiguration(); hostnameConfig.Hostname = Hostname; hostnameConfig.HostnameType = HostnameType; if (!string.IsNullOrWhiteSpace(KeyVaultId)) { hostnameConfig.KeyVaultId = KeyVaultId; hostnameConfig.CertificateSource = SdkModels.CertificateSource.KeyVault; if (!string.IsNullOrWhiteSpace(IdentityClientId)) { hostnameConfig.IdentityClientId = IdentityClientId; } } else if (!string.IsNullOrWhiteSpace(PfxPath)) { FileInfo localFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.PfxPath)); if (!localFile.Exists) { throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.SourceFileNotFound, this.PfxPath)); } byte[] certificate; using (var certStream = File.OpenRead(localFile.FullName)) { certificate = new byte[certStream.Length]; certStream.Read(certificate, 0, certificate.Length); } var encodedCertificate = Convert.ToBase64String(certificate); hostnameConfig.EncodedCertificate = encodedCertificate; hostnameConfig.CertificateSource = SdkModels.CertificateSource.Custom; if (PfxPassword != null) { hostnameConfig.CertificatePassword = PfxPassword.ConvertToString(); } } else if (HostNameCertificateInformation != null) { hostnameConfig.CertificateInformation = HostNameCertificateInformation; } else if (ManagedCertificate.IsPresent) { // managed certificate hostnameConfig.CertificateSource = SdkModels.CertificateSource.Managed; } else { throw new Exception("Missing Certificate configuration."); } hostnameConfig.DefaultSslBinding = DefaultSslBinding; hostnameConfig.NegotiateClientCertificate = NegotiateClientCertificate; WriteObject(hostnameConfig); }
public static HostnameConfiguration GetHostnameConfiguration( this PsApiManagementCustomHostNameConfiguration hostnameConfig) { if (hostnameConfig == null) { return(null); } var hostnameConfiguration = new HostnameConfiguration( Mappers.MapHostnameType(hostnameConfig.HostnameType), hostnameConfig.Hostname); if (!string.IsNullOrWhiteSpace(hostnameConfig.EncodedCertificate)) { hostnameConfiguration.EncodedCertificate = hostnameConfig.EncodedCertificate; } if (hostnameConfig.CertificatePassword != null) { hostnameConfiguration.CertificatePassword = hostnameConfig.CertificatePassword; } if (!string.IsNullOrWhiteSpace(hostnameConfig.KeyVaultId)) { hostnameConfiguration.KeyVaultId = hostnameConfig.KeyVaultId; } if (!string.IsNullOrWhiteSpace(hostnameConfig.IdentityClientId)) { hostnameConfiguration.IdentityClientId = hostnameConfig.IdentityClientId; } if (hostnameConfig.DefaultSslBinding.HasValue) { hostnameConfiguration.DefaultSslBinding = hostnameConfig.DefaultSslBinding.Value; } if (hostnameConfig.NegotiateClientCertificate.HasValue) { hostnameConfiguration.NegotiateClientCertificate = hostnameConfig.NegotiateClientCertificate.Value; } // if no new certificate is provided, then copy over details of existing certificate if (hostnameConfig.CertificateInformation != null && string.IsNullOrEmpty(hostnameConfig.EncodedCertificate)) { hostnameConfiguration.Certificate = hostnameConfig.CertificateInformation.GetCertificateInformation(); } return(hostnameConfiguration); }
public override void ExecuteCmdlet() { var hostnameConfig = new PsApiManagementCustomHostNameConfiguration(); hostnameConfig.Hostname = Hostname; hostnameConfig.HostnameType = HostnameType; if (!string.IsNullOrWhiteSpace(KeyVaultId)) { hostnameConfig.KeyVaultId = KeyVaultId; } else if (!string.IsNullOrWhiteSpace(PfxPath)) { byte[] certificate; using (var certStream = File.OpenRead(PfxPath)) { certificate = new byte[certStream.Length]; certStream.Read(certificate, 0, certificate.Length); } var encodedCertificate = Convert.ToBase64String(certificate); hostnameConfig.EncodedCertificate = encodedCertificate; if (PfxPassword != null) { hostnameConfig.CertificatePassword = PfxPassword.ConvertToString(); } } else if (HostNameCertificateInformation != null) { hostnameConfig.CertificateInformation = HostNameCertificateInformation; } else { throw new Exception("Missing Certificate configuration."); } hostnameConfig.DefaultSslBinding = DefaultSslBinding; hostnameConfig.NegotiateClientCertificate = NegotiateClientCertificate; WriteObject(hostnameConfig); }
public static HostnameConfiguration GetHostnameConfiguration( this PsApiManagementCustomHostNameConfiguration hostnameConfig) { if (hostnameConfig == null) { return(null); } var hostnameConfiguration = new HostnameConfiguration( Mappers.MapHostnameType(hostnameConfig.HostnameType), hostnameConfig.Hostname); if (!string.IsNullOrWhiteSpace(hostnameConfig.EncodedCertificate)) { hostnameConfiguration.EncodedCertificate = hostnameConfig.EncodedCertificate; } if (hostnameConfig.CertificatePassword != null) { hostnameConfiguration.CertificatePassword = hostnameConfig.CertificatePassword; } if (!string.IsNullOrWhiteSpace(hostnameConfig.KeyVaultId)) { hostnameConfiguration.KeyVaultId = hostnameConfig.KeyVaultId; } if (hostnameConfig.DefaultSslBinding.HasValue) { hostnameConfiguration.DefaultSslBinding = hostnameConfig.DefaultSslBinding.Value; } if (hostnameConfig.NegotiateClientCertificate.HasValue) { hostnameConfiguration.NegotiateClientCertificate = hostnameConfig.NegotiateClientCertificate.Value; } return(hostnameConfiguration); }