Skip to content

Commit 1cbc9bc

Browse files
committed
Bump version v2.23.0
1 parent 83a9617 commit 1cbc9bc

17 files changed

+1918
-1546
lines changed

.github/workflows/build-test-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ jobs:
4343
env:
4444
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4545
with:
46-
tag_name: v2.22.0-client-v2.17.0
47-
release_name: "AOT Client v2.17.0 NpgsqlRest v2.22.0"
46+
tag_name: v2.23.0-client-v2.18.0
47+
release_name: "AOT Client v2.18.0 NpgsqlRest v2.23.0"
4848
draft: true
4949
prerelease: true
5050

Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
using System.Security.Claims;
22

3-
namespace NpgsqlRest;
3+
namespace NpgsqlRest.Auth;
44

5-
public class NpgsqlRestAuthenticationOptions(
6-
string? defaultAuthenticationType = null,
7-
string? statusColumnName = "status",
8-
string? schemeColumnName = "scheme",
9-
string? messageColumnName = "message",
10-
bool useActiveDirectoryFederationServicesClaimTypes = true,
11-
string defaultNameClaimType = ClaimTypes.Name,
12-
string defaultRoleClaimType = ClaimTypes.Role,
13-
bool serializeAuthEndpointsResponse = false,
14-
bool obfuscateAuthParameterLogValues = true,
15-
string hashColumnName = "hash",
16-
string passwordParameterNameContains = "pass")
5+
public class NpgsqlRestAuthenticationOptions
176
{
187
/// <summary>
198
/// Authentication type used with the Login endpoints to set the authentication type for the new `ClaimsIdentity` created by the login.
@@ -22,7 +11,7 @@ public class NpgsqlRestAuthenticationOptions(
2211
///
2312
/// If the value is not set and the login endpoint is present, it will automatically get the database name from the connection string.
2413
/// </summary>
25-
public string? DefaultAuthenticationType { get; set; } = defaultAuthenticationType;
14+
public string? DefaultAuthenticationType { get; set; } = null;
2615

2716
/// <summary>
2817
/// The default column name to in the data reader which will be used to read the value to determine the success or failure of the login operation.
@@ -31,19 +20,19 @@ public class NpgsqlRestAuthenticationOptions(
3120
/// - If this column is not present, it must be either a boolean to indicate success or a numeric value to indicate the HTTP Status Code to return.
3221
/// - If this column is present and retrieves a numeric value, that value is assigned to the HTTP Status Code and the login will authenticate only when this value is 200.
3322
/// </summary>
34-
public string? StatusColumnName { get; set; } = statusColumnName;
23+
public string? StatusColumnName { get; set; } = "status";
3524

3625
/// <summary>
3726
/// The default column name to in the data reader which will be used to read the value of the authentication scheme of the login process.
3827
///
3928
/// If this column is not present in the login response the default authentication scheme is used. Return new value to use a different authentication scheme with the login endpoint.
4029
/// </summary>
41-
public string? SchemeColumnName { get; set; } = schemeColumnName;
30+
public string? SchemeColumnName { get; set; } = "scheme";
4231

4332
/// <summary>
4433
/// The default column name to in the data reader which will return a text message with the login status.
4534
/// </summary>
46-
public string? MessageColumnName { get; set; } = messageColumnName;
35+
public string? MessageColumnName { get; set; } = "message";
4736

4837
/// <summary>
4938
/// Any columns retrieved from the reader during login, which don't have a name in `StatusColumnName` or `SchemeColumnName` will be used to create a new identity `Claim`:
@@ -54,7 +43,7 @@ public class NpgsqlRestAuthenticationOptions(
5443
///
5544
/// For example, column name `NameIdentifier` or `name_identifier` (when transformed by the default name transformer) will match the key `NameIdentifier` which translates to this: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier
5645
/// </summary>
57-
public bool UseActiveDirectoryFederationServicesClaimTypes { get; set; } = useActiveDirectoryFederationServicesClaimTypes;
46+
public bool UseActiveDirectoryFederationServicesClaimTypes { get; set; } = true;
5847

5948
/// <summary>
6049
/// Claim type value used to retrieve the user name. The user name is exposed as the default name with the `Name` property on the user identity.
@@ -63,13 +52,13 @@ public class NpgsqlRestAuthenticationOptions(
6352
///
6453
/// The default is the Active Directory Federation Services Claim Type Role property with value [`http://schemas.microsoft.com/ws/2008/06/identity/claims/role`(https://learn.microsoft.com/en-us/dotnet/api/system.security.claims.claimtypes.role?view=net-8.0#system-security-claims-claimtypes-role)
6554
/// </summary>
66-
public string DefaultNameClaimType { get; set; } = defaultNameClaimType;
55+
public string DefaultNameClaimType { get; set; } = ClaimTypes.Name;
6756

6857
/// <summary>
6958
/// Claim type value used to define role-based security.
7059
/// Default is the Active Directory Federation Services Claim Type Role: http://schemas.microsoft.com/ws/2008/06/identity/claims/role
7160
/// </summary>
72-
public string DefaultRoleClaimType { get; set; } = defaultRoleClaimType;
61+
public string DefaultRoleClaimType { get; set; } = ClaimTypes.Role;
7362

7463
/// <summary>
7564
/// If true, return any response from auth endpoints (login and logout) if response hasn't been written by auth handler.
@@ -78,26 +67,26 @@ public class NpgsqlRestAuthenticationOptions(
7867
/// This option will also be ignored if message column is present (see MessageColumnName option).
7968
/// Default is false.
8069
/// </summary>
81-
public bool SerializeAuthEndpointsResponse { get; set; } = serializeAuthEndpointsResponse;
70+
public bool SerializeAuthEndpointsResponse { get; set; } = false;
8271

8372
/// <summary>
8473
/// Don't write real parameter values when logging parameters from auth endpoints and obfuscate instead.
8574
/// This prevents user credentials including password to end up in application logs.
8675
/// Default is true.
8776
/// </summary>
88-
public bool ObfuscateAuthParameterLogValues { get; set; } = obfuscateAuthParameterLogValues;
77+
public bool ObfuscateAuthParameterLogValues { get; set; } = true;
8978

9079
/// <summary>
9180
/// The default column name to in the data reader which will be used to read the value of the hash of the password.
9281
/// If this column is present, the value will be used to verify the password from the password parameter.
9382
/// Password parameter is the first parameter which name contains the value of PasswordParameterNameContains.
9483
/// If verification fails, the login will fail and the HTTP Status Code will be set to 404 Not Found.
9584
/// </summary>
96-
public string HashColumnName { get; set; } = hashColumnName;
85+
public string HashColumnName { get; set; } = "hash";
9786

9887
/// <summary>
9988
/// The default name of the password parameter. The first parameter which name contains this value will be used as the password parameter.
10089
/// This is used to verify the password from the password parameter when login endpoint returns a hash of the password (see HashColumnName).
10190
/// </summary>
102-
public string PasswordParameterNameContains { get; set; } = passwordParameterNameContains;
91+
public string PasswordParameterNameContains { get; set; } = "pass";
10392
}

NpgsqlRest/NpgsqlRestMetadata.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Npgsql;
22
using NpgsqlRest.Defaults;
3+
using NpgsqlRest.UploadHandlers;
34

45
namespace NpgsqlRest;
56

@@ -39,6 +40,9 @@ public static NpgsqlRestMetadata Build(NpgsqlRestOptions options, ILogger? logge
3940
Dictionary<string, NpgsqlRestMetadataEntry> lookup = [];
4041
Dictionary<string, NpgsqlRestMetadataEntry> overloads = [];
4142

43+
// Create default upload handlers from upload handler options
44+
options.UploadHandlers ??= UploadHandlerOptions.CreateUploadHandlers(options.DefaultUploadHandlerOptions);
45+
4246
var hasLogin = false;
4347
if (builder is not null)
4448
{

NpgsqlRest/NpgsqlRestOptions.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Extensions.Primitives;
22
using Npgsql;
3+
using NpgsqlRest.Auth;
34
using NpgsqlRest.Defaults;
45
using NpgsqlRest.UploadHandlers;
56

@@ -113,7 +114,7 @@ public NpgsqlRestOptions(NpgsqlDataSource dataSource)
113114
public ServiceProviderObject ServiceProviderMode { get; set; } = ServiceProviderObject.None;
114115

115116
/// <summary>
116-
/// Callback function that is executed just after the new endpoint is created. Receives routine into and new endpoint info as parameters and it is expected to return the same endpoint or `null`. It offers an opportunity to modify the endpoint based on custom logic or disable endpoints by returning `null` based on some custom logic. Default is `null`, which means this callback is not defined.
117+
/// Callback function that is executed just after the new endpoint is created. Set the RoutineEndpoint to null to disable endpoint.
117118
/// </summary>
118119
public Action<RoutineEndpoint?>? EndpointCreated { get; set; } = null;
119120

@@ -321,11 +322,20 @@ public NpgsqlRestOptions(NpgsqlDataSource dataSource)
321322
public IPasswordHasher PasswordHasher { get; set; } = new PasswordHasher();
322323

323324
/// <summary>
324-
/// Upload handlers dictionary map. If not specified otherwise, the first upload handler will be used for all upload requests.
325-
/// Routines can specify one or more preferred upload handlers in the comment annotations.
325+
/// Default upload handler options.
326+
/// Set this option to null to disable upload handlers or use this to modify upload handler options.
326327
/// </summary>
327-
public Dictionary<string, Func<IUploadHandler>>? UploadHandlers { get; set; } =
328-
UploadHandlerOptions.CreateUploadHandlers(new UploadHandlerOptions());
328+
public UploadHandlerOptions DefaultUploadHandlerOptions { get; set; } = new UploadHandlerOptions();
329+
330+
/// <summary>
331+
/// Upload handlers dictionary map.
332+
/// When the endpoint has set Upload to true, this dictionary will be used to find the upload handlers for the current request.
333+
/// Handler will be located by the key values from the endpoint UploadHandlers string array property if set or by the default upload handler (DefaultUploadHandler option).
334+
/// Set this option to null to use default upload handler from the UploadHandlerOptions property.
335+
/// Set this option to empty dictionary to disable upload handlers.
336+
/// Set this option to a dictionary with one or more upload handlers to enable your own custom upload handlers.
337+
/// </summary>
338+
public Dictionary<string, Func<IUploadHandler>>? UploadHandlers { get; set; } = null;
329339

330340
/// <summary>
331341
/// Default upload handler name. This value is used when the upload handlers are not specified.

NpgsqlRest/UploadHandlers/UploadHandlerOptions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
public class UploadHandlerOptions
44
{
5+
public bool UploadsEnabled { get; set; } = true;
56
public bool LargeObjectEnabled { get; set; } = true;
67
public string LargeObjectKey { get; set; } = "large_object";
78
public int LargeObjectHandlerBufferSize { get; set; } = 8192;
89

910
public bool FileSystemEnabled { get; set; } = true;
1011
public string FileSystemKey { get; set; } = "file_system";
11-
public string FileSystemHandlerPath { get; set; } = "/tmp/uploads";
12+
public string FileSystemHandlerPath { get; set; } = "./";
1213
public bool FileSystemHandlerUseUniqueFileName { get; set; } = true;
1314
public bool FileSystemHandlerCreatePathIfNotExists { get; set; } = true;
1415
public int FileSystemHandlerBufferSize { get; set; } = 8192;
@@ -19,6 +20,10 @@ public class UploadHandlerOptions
1920
{
2021
return null;
2122
}
23+
if (options.UploadsEnabled is false)
24+
{
25+
return null;
26+
}
2227
if (options.LargeObjectEnabled is false && options.FileSystemEnabled is false)
2328
{
2429
return null;

NpgsqlRestClient/App.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -443,17 +443,19 @@ public static (string defaultUploadHandler, Dictionary<string, Func<IUploadHandl
443443
}
444444

445445
string defaultUploadHandler = GetConfigStr("DefaultUploadHandler", uploadHandlersCfg) ?? "large_object";
446-
var options = new UploadHandlerOptions();
447-
options.LargeObjectEnabled = GetConfigBool("LargeObjectEnabled", uploadHandlersCfg, true);
448-
options.LargeObjectKey = GetConfigStr("LargeObjectKey", uploadHandlersCfg) ?? "large_object";
449-
options.LargeObjectHandlerBufferSize = GetConfigInt("LargeObjectHandlerBufferSize", uploadHandlersCfg) ?? 8192;
450-
451-
options.FileSystemEnabled = GetConfigBool("FileSystemEnabled", uploadHandlersCfg, true);
452-
options.FileSystemKey = GetConfigStr("FileSystemKey", uploadHandlersCfg) ?? "file_system";
453-
options.FileSystemHandlerPath = GetConfigStr("FileSystemHandlerPath", uploadHandlersCfg) ?? "/tmp/uploads";
454-
options.FileSystemHandlerUseUniqueFileName = GetConfigBool("FileSystemHandlerUseUniqueFileName", uploadHandlersCfg, true);
455-
options.FileSystemHandlerCreatePathIfNotExists = GetConfigBool("FileSystemHandlerCreatePathIfNotExists", uploadHandlersCfg, true);
456-
options.FileSystemHandlerBufferSize = GetConfigInt("FileSystemHandlerBufferSize", uploadHandlersCfg) ?? 8192;
446+
var options = new UploadHandlerOptions
447+
{
448+
LargeObjectEnabled = GetConfigBool("LargeObjectEnabled", uploadHandlersCfg, true),
449+
LargeObjectKey = GetConfigStr("LargeObjectKey", uploadHandlersCfg) ?? "large_object",
450+
LargeObjectHandlerBufferSize = GetConfigInt("LargeObjectHandlerBufferSize", uploadHandlersCfg) ?? 8192,
451+
452+
FileSystemEnabled = GetConfigBool("FileSystemEnabled", uploadHandlersCfg, true),
453+
FileSystemKey = GetConfigStr("FileSystemKey", uploadHandlersCfg) ?? "file_system",
454+
FileSystemHandlerPath = GetConfigStr("FileSystemHandlerPath", uploadHandlersCfg) ?? "/tmp/uploads",
455+
FileSystemHandlerUseUniqueFileName = GetConfigBool("FileSystemHandlerUseUniqueFileName", uploadHandlersCfg, true),
456+
FileSystemHandlerCreatePathIfNotExists = GetConfigBool("FileSystemHandlerCreatePathIfNotExists", uploadHandlersCfg, true),
457+
FileSystemHandlerBufferSize = GetConfigInt("FileSystemHandlerBufferSize", uploadHandlersCfg) ?? 8192
458+
};
457459

458460
return (defaultUploadHandler, UploadHandlerOptions.CreateUploadHandlers(options));
459461
}

NpgsqlRestClient/Program.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using static NpgsqlRestClient.App;
1111
using Npgsql;
1212

13-
1413
if (Arguments.Parse(args) is false)
1514
{
1615
return;
@@ -67,7 +66,7 @@
6766
await using var dataSource = new NpgsqlDataSourceBuilder(connectionString).Build();
6867
var logConnectionNoticeEventsMode = GetConfigEnum<PostgresConnectionNoticeLoggingMode?>("LogConnectionNoticeEventsMode", NpgsqlRestCfg) ?? PostgresConnectionNoticeLoggingMode.FirstStackFrameAndMessage;
6968

70-
var paramHandlers = CreateParametersHandlers();
69+
var (paramHandler, defaultParser) = CreateParametersHandlers();
7170
(string defaultUploadHandler, Dictionary<string, Func<IUploadHandler>>? uploadHandlers) = CreateUploadHandlers();
7271

7372
if (uploadHandlers is not null && uploadHandlers.Count > 1)
@@ -109,7 +108,7 @@
109108
RequestHeadersParameterName = GetConfigStr("RequestHeadersParameterName", NpgsqlRestCfg) ?? "_headers",
110109

111110
EndpointCreated = CreateEndpointCreatedHandler(),
112-
ValidateParameters = paramHandlers.paramHandler,
111+
ValidateParameters = paramHandler,
113112
ReturnNpgsqlExceptionMessage = GetConfigBool("ReturnNpgsqlExceptionMessage", NpgsqlRestCfg, true),
114113
PostgreSqlErrorCodeToHttpStatusCodeMapping = CreatePostgreSqlErrorCodeToHttpStatusCodeMapping(),
115114
BeforeConnectionOpen = BeforeConnectionOpen(connectionString),
@@ -126,7 +125,7 @@
126125
RefreshEndpointEnabled = GetConfigBool("Enabled", refreshOptionsCfg, false),
127126
RefreshPath = GetConfigStr("Path", refreshOptionsCfg) ?? "/api/npgsqlrest/refresh",
128127
RefreshMethod = GetConfigStr("Method", refreshOptionsCfg) ?? "GET",
129-
DefaultResponseParser = paramHandlers.defaultParser,
128+
DefaultResponseParser = defaultParser,
130129

131130
UploadHandlers = uploadHandlers,
132131
DefaultUploadHandler = defaultUploadHandler,

0 commit comments

Comments
 (0)