|
2 | 2 | using System.Globalization; |
3 | 3 | using System.Net.Security; |
4 | 4 | using System.Text; |
| 5 | +using Npgsql.EntityFrameworkCore.PostgreSQL.Internal; |
5 | 6 |
|
6 | 7 | namespace Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal; |
7 | 8 |
|
@@ -242,12 +243,25 @@ public override void Validate(IDbContextOptions options) |
242 | 243 | var dataSource = DataSource |
243 | 244 | ?? options.FindExtension<CoreOptionsExtension>()?.ApplicationServiceProvider?.GetService<NpgsqlDataSource>(); |
244 | 245 |
|
245 | | - if (dataSource is not null |
246 | | - && (ProvideClientCertificatesCallback is not null |
247 | | - || RemoteCertificateValidationCallback is not null |
248 | | - || ProvidePasswordCallback is not null)) |
| 246 | + if (dataSource is not null) |
249 | 247 | { |
250 | | - throw new InvalidOperationException(); |
| 248 | + if (ProvideClientCertificatesCallback is not null) |
| 249 | + { |
| 250 | + throw new InvalidOperationException( |
| 251 | + "When passing an NpgsqlDataSource to UseNpgsql(), call 'ProvideClientCertificatesCallback' on NpgsqlDataSourceBuilder rather than in UseNpgsql()."); |
| 252 | + } |
| 253 | + |
| 254 | + if (RemoteCertificateValidationCallback is not null) |
| 255 | + { |
| 256 | + throw new InvalidOperationException( |
| 257 | + "When passing an NpgsqlDataSource to UseNpgsql(), call 'RemoteCertificateValidationCallback' on NpgsqlDataSourceBuilder rather than in UseNpgsql()."); |
| 258 | + } |
| 259 | + |
| 260 | + if (ProvidePasswordCallback is not null) |
| 261 | + { |
| 262 | + throw new InvalidOperationException( |
| 263 | + "When passing an NpgsqlDataSource to UseNpgsql(), 'ProviderPasswordCallback' cannot be used in UseNpgsql(). See https://www.npgsql.org/doc/security.html for configuring passwords and token rotation on NpgsqlDataSourceBuilder."); |
| 264 | + } |
251 | 265 | } |
252 | 266 |
|
253 | 267 | if (UseRedshift && _postgresVersion is not null) |
|
0 commit comments