From 11fa713e33a1a5cc6f2262c25f1ab69567aa6530 Mon Sep 17 00:00:00 2001 From: vnugent Date: Sat, 14 Sep 2024 16:09:23 -0400 Subject: Squashed commit of the following: commit 181f499c92ac7b772307e40d48d2a26ea45e156b Author: vnugent Date: Sat Sep 14 16:01:28 2024 -0400 taskfile prettier commit 0d47b4d25cf61d29c44a17ae491d775cf84938ab Author: vnugent Date: Wed Sep 11 16:43:36 2024 -0400 Managed library & package updates commit 940f151f2f4e708282deb5569cffe5b0935f5c3b Author: vnugent Date: Mon Sep 2 13:54:16 2024 -0400 expand config extensions, and update some sql provider usage commit b269019103acce18e0df8debd9f7bfdf203083b8 Merge: 87887c0 641bdbe Author: vnugent Date: Sun Jul 28 18:53:41 2024 -0400 Merge branch 'master' into develop --- Module.Taskfile.yaml | 24 +-- .../src/VNLib.Plugins.Extensions.Data.csproj | 2 +- .../VNLib.Plugins.Extensions.Loading.Sql.csproj | 2 +- .../src/AssemblyLoader.cs | 12 +- .../src/ConfigurationExtensions.cs | 216 +++++++++++++++++++-- .../src/IAsyncBackgroundWork.cs | 11 +- .../src/MYSqlExport.cs | 38 ++-- .../src/SQLiteExport.cs | 29 +-- ...ib.Plugins.Extensions.Loading.Sql.SQLite.csproj | 2 +- .../src/SqlServerExport.cs | 61 +++--- ...Plugins.Extensions.Loading.Sql.SQLServer.csproj | 2 +- 11 files changed, 293 insertions(+), 106 deletions(-) diff --git a/Module.Taskfile.yaml b/Module.Taskfile.yaml index 0d4cd95..bf9f580 100644 --- a/Module.Taskfile.yaml +++ b/Module.Taskfile.yaml @@ -11,9 +11,9 @@ version: '3' vars: - INT_DIR: '{{.SCRATCH_DIR}}/obj/{{.MODULE_NAME}}/' - MS_ARGS: '/p:RunAnalyzersDuringBuild=false /p:IntermediateOutputPath="{{.INT_DIR}}" /p:UseCommonOutputDirectory=true /p:BuildInParallel=true /p:MultiProcessorCompilation=true /p:ErrorOnDuplicatePublishOutputFiles=false' - PACK_OUT: '{{.OUTPUT_DIR}}/{{.HEAD_SHA}}/pkg' + INT_DIR: '{{ .SCRATCH_DIR }}/obj/{{ .MODULE_NAME }}/' + MS_ARGS: '/p:RunAnalyzersDuringBuild=false /p:IntermediateOutputPath="{{ .INT_DIR }}" /p:UseCommonOutputDirectory=true /p:BuildInParallel=true /p:MultiProcessorCompilation=true /p:ErrorOnDuplicatePublishOutputFiles=false' + PACK_OUT: '{{ .OUTPUT_DIR }}/{{ .HEAD_SHA }}/pkg' tasks: @@ -22,14 +22,14 @@ tasks: cmds: - git reset --hard #clean up any local changes - git remote update - - git pull origin {{.BRANCH_NAME}} --verify-signatures + - git pull origin {{ .BRANCH_NAME }} --verify-signatures #re-write semver after hard reset - dotnet-gitversion.exe /updateprojectfiles #called by build pipeline to build module build: cmds: - - echo "building module {{.MODULE_NAME}}" + - echo "building module {{ .MODULE_NAME }}" #build debug mode first - task: build_debug @@ -38,10 +38,10 @@ tasks: publish: cmds: #git archive in the module directory - - git archive --format {{.ARCHIVE_FILE_FORMAT}} --output {{.ARCHIVE_FILE_NAME}} HEAD + - git archive --format {{ .ARCHIVE_FILE_FORMAT }} --output {{ .ARCHIVE_FILE_NAME }} HEAD #push packages to the sleet feed (feed path is vnbuild global) - - sleet push "{{.PACK_OUT}}/debug/" --source debug --config "{{.SLEET_CONFIG_PATH}}" --force - - sleet push "{{.PACK_OUT}}/release/" --source release --config "{{.SLEET_CONFIG_PATH}}" --force + - sleet push "{{ .PACK_OUT }}/debug/" --source debug --config "{{ .SLEET_CONFIG_PATH }}" --force + - sleet push "{{ .PACK_OUT }}/release/" --source release --config "{{ .SLEET_CONFIG_PATH }}" --force #called by build pipeline to clean module clean: @@ -56,12 +56,12 @@ tasks: build_debug: internal: true cmds: - - dotnet publish -c debug {{.MS_ARGS}} - - dotnet pack -c debug {{.MS_ARGS}} -o "{{.PACK_OUT}}/debug/" + - dotnet publish -c debug {{ .MS_ARGS }} + - dotnet pack -c debug {{ .MS_ARGS }} -o "{{ .PACK_OUT }}/debug/" build_release: internal: true cmds: - - dotnet publish -c release {{.MS_ARGS}} - - dotnet pack -c release {{.MS_ARGS}} -o "{{.PACK_OUT}}/release/" + - dotnet publish -c release {{ .MS_ARGS }} + - dotnet pack -c release {{ .MS_ARGS }} -o "{{ .PACK_OUT }}/release/" \ No newline at end of file diff --git a/lib/VNLib.Plugins.Extensions.Data/src/VNLib.Plugins.Extensions.Data.csproj b/lib/VNLib.Plugins.Extensions.Data/src/VNLib.Plugins.Extensions.Data.csproj index 94e7137..9ccb39a 100644 --- a/lib/VNLib.Plugins.Extensions.Data/src/VNLib.Plugins.Extensions.Data.csproj +++ b/lib/VNLib.Plugins.Extensions.Data/src/VNLib.Plugins.Extensions.Data.csproj @@ -48,7 +48,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/lib/VNLib.Plugins.Extensions.Loading.Sql/src/VNLib.Plugins.Extensions.Loading.Sql.csproj b/lib/VNLib.Plugins.Extensions.Loading.Sql/src/VNLib.Plugins.Extensions.Loading.Sql.csproj index d622a05..7e5f058 100644 --- a/lib/VNLib.Plugins.Extensions.Loading.Sql/src/VNLib.Plugins.Extensions.Loading.Sql.csproj +++ b/lib/VNLib.Plugins.Extensions.Loading.Sql/src/VNLib.Plugins.Extensions.Loading.Sql.csproj @@ -40,7 +40,7 @@ - + diff --git a/lib/VNLib.Plugins.Extensions.Loading/src/AssemblyLoader.cs b/lib/VNLib.Plugins.Extensions.Loading/src/AssemblyLoader.cs index 49ef4b3..2d47af5 100644 --- a/lib/VNLib.Plugins.Extensions.Loading/src/AssemblyLoader.cs +++ b/lib/VNLib.Plugins.Extensions.Loading/src/AssemblyLoader.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Extensions.Loading @@ -48,19 +48,19 @@ namespace VNLib.Plugins.Extensions.Loading public sealed class AssemblyLoader : ManagedLibrary, IDisposable { private readonly CancellationTokenRegistration _reg; - private readonly Lazy _instance; + private readonly LazyInitializer _instance; private bool disposedValue; /// /// The instance of the loaded type /// - public T Resource => _instance.Value; + public T Resource => _instance.Instance; private AssemblyLoader(string assemblyPath, AssemblyLoadContext parentContext, CancellationToken unloadToken) :base(assemblyPath, parentContext) { //Init lazy type loader - _instance = new(LoadTypeFromAssembly, LazyThreadSafetyMode.PublicationOnly); + _instance = new(LoadTypeFromAssembly); //Register dispose _reg = unloadToken.Register(Dispose); } @@ -96,7 +96,7 @@ namespace VNLib.Plugins.Extensions.Loading if (disposing) { //If the instance is disposable, call its dispose method on unload - if (_instance.IsValueCreated && _instance.Value is IDisposable disposable) + if (_instance.IsLoaded && _instance.Instance is IDisposable disposable) { disposable.Dispose(); } @@ -138,7 +138,7 @@ namespace VNLib.Plugins.Extensions.Loading /// internal static AssemblyLoader Load(string assemblyName, AssemblyLoadContext loadContext, CancellationToken unloadToken) { - _ = loadContext ?? throw new ArgumentNullException(nameof(loadContext)); + ArgumentNullException.ThrowIfNull(loadContext); //Make sure the file exists if (!FileOperations.FileExists(assemblyName)) diff --git a/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs b/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs index e838822..30711fa 100644 --- a/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs +++ b/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs @@ -198,7 +198,6 @@ namespace VNLib.Plugins.Extensions.Loading return value; } - /// /// Gets a required configuration property from the specified configuration scope /// and deserializes the json type. @@ -211,7 +210,11 @@ namespace VNLib.Plugins.Extensions.Loading /// public static T GetRequiredProperty(this IConfigScope config, string property) { - return GetRequiredProperty(config, property, static p => p.Deserialize()!); + return GetRequiredProperty( + config, + property, + static p => p.Deserialize()! + ); } /// @@ -244,6 +247,107 @@ namespace VNLib.Plugins.Extensions.Loading return false; } + /// + /// Attempts to get a configuration property from the specified configuration scope + /// and deserializes the json type. + /// output value + /// + /// + /// + /// The name of the configuration element to get + /// The output value to set + /// A value that indicates if the property was found + /// + public static bool TryGetProperty(this IConfigScope config, string property, out T? value) + { + return TryGetProperty( + config, + property, + static p => p.Deserialize(), + out value + ); + } + + /// + /// Attempts to get a configuration property from the specified configuration scope + /// and returns the string value if found, or null if not found. + /// output value + /// + /// + /// The name of the configuration element to get + /// The output value to set + /// A value that indicates if the property was found + /// + public static bool TryGetProperty(this IConfigScope config, string property, out string? value) + { + return TryGetProperty( + config, + property, + static p => p.GetString(), + out value + ); + } + + /// + /// Attempts to get a configuration property from the specified configuration scope + /// and returns the int32 value if found, or null if not found. + /// output value + /// + /// + /// The name of the configuration element to get + /// The output value to set + /// A value that indicates if the property was found + /// + public static bool TryGetProperty(this IConfigScope config, string property, out int? value) + { + return TryGetProperty( + config, + property, + static p => p.GetInt32(), + out value + ); + } + + /// + /// Attempts to get a configuration property from the specified configuration scope + /// and returns the uint32 value if found, or null if not found. + /// output value + /// + /// + /// The name of the configuration element to get + /// The output value to set + /// A value that indicates if the property was found + /// + public static bool TryGetProperty(this IConfigScope config, string property, out uint? value) + { + return TryGetProperty( + config, + property, + static p => p.GetUInt32(), + out value + ); + } + + /// + /// Attempts to get a configuration property from the specified configuration scope + /// and returns the boolean value if found, or null if not found. + /// output value + /// + /// + /// The name of the configuration element to get + /// The output value to set + /// A value that indicates if the property was found + /// + public static bool TryGetProperty(this IConfigScope config, string property, out bool? value) + { + return TryGetProperty( + config, + property, + static p => p.GetBoolean(), + out value + ); + } + /// /// Gets a configuration property from the specified configuration scope /// and invokes your callback function on the element if found to transform the @@ -284,6 +388,84 @@ namespace VNLib.Plugins.Extensions.Loading ); } + /// + /// Gets a configuration property from the specified configuration scope + /// and deserializes the json element if found, or returns the default value + /// if the property is not found. + /// + /// + /// The name of the configuration element to get + /// The default value to return + /// The property value returned from your getter callback, or the default value if not found + /// + [return: NotNullIfNotNull(nameof(defaultValue))] + public static string? GetValueOrDefault(this IConfigScope config, string property, string defaultValue) + { + return GetValueOrDefault( + config, + property, + static p => p.GetString(), + defaultValue + ); + } + + /// + /// Gets a configuration property of type int32 from the specified configuration + /// scope and, or returns the default value if the property is not found. + /// + /// + /// The name of the configuration element to get + /// The default value to return + /// The property value returned from your getter callback, or the default value if not found + /// + public static int GetValueOrDefault(this IConfigScope config, string property, int defaultValue) + { + return GetValueOrDefault( + config, + property, + static p => p.GetInt32(), + defaultValue + ); + } + + /// + /// Gets a configuration property of type uint32 from the specified configuration + /// scope and, or returns the default value if the property is not found. + /// + /// + /// The name of the configuration element to get + /// The default value to return + /// The property value returned from your getter callback, or the default value if not found + /// + public static uint GetValueOrDefault(this IConfigScope config, string property, uint defaultValue) + { + return GetValueOrDefault( + config, + property, + static p => p.GetUInt32(), + defaultValue + ); + } + + /// + /// Gets a configuration property of type boolean from the specified configuration + /// scope and, or returns the default value if the property is not found. + /// + /// + /// The name of the configuration element to get + /// The default value to return + /// The property value returned from your getter callback, or the default value if not found + /// + public static bool GetValueOrDefault(this IConfigScope config, string property, bool defaultValue) + { + return GetValueOrDefault( + config, + property, + static p => p.GetBoolean(), + defaultValue + ); + } + /// /// Gets the configuration property name for the type /// @@ -522,22 +704,22 @@ namespace VNLib.Plugins.Extensions.Loading return []; } - if (searchPaths.ValueKind == JsonValueKind.Array) - { - //Get the plugins path or throw because it should ALWAYS be defined if this method is called - return searchPaths.EnumerateArray() - .Select(static p => p.GetString()!) - .Select(Path.GetFullPath) //Get absolute file paths - .ToArray(); - } - else if (searchPaths.ValueKind == JsonValueKind.String) + switch (searchPaths.ValueKind) { - return [Path.GetFullPath(searchPaths.GetString()!)]; - } - else - { - return []; - } + case JsonValueKind.Array: + + //Get the plugins path or throw because it should ALWAYS be defined if this method is called + return searchPaths.EnumerateArray() + .Select(static p => p.GetString()!) + .Select(Path.GetFullPath) //Get absolute file paths + .ToArray(); + + case JsonValueKind.String: + return [ Path.GetFullPath(searchPaths.GetString()!) ]; + + default: + return []; + } } } } diff --git a/lib/VNLib.Plugins.Extensions.Loading/src/IAsyncBackgroundWork.cs b/lib/VNLib.Plugins.Extensions.Loading/src/IAsyncBackgroundWork.cs index 9fb66a2..a86129c 100644 --- a/lib/VNLib.Plugins.Extensions.Loading/src/IAsyncBackgroundWork.cs +++ b/lib/VNLib.Plugins.Extensions.Loading/src/IAsyncBackgroundWork.cs @@ -1,12 +1,12 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Extensions.Loading -* File: LoadingExtensions.cs +* File: IAsyncBackgroundWork.cs * -* LoadingExtensions.cs is part of VNLib.Plugins.Extensions.Loading which is part of the larger -* VNLib collection of libraries and utilities. +* IAsyncBackgroundWork.cs is part of VNLib.Plugins.Extensions.Loading which is +* part of the larger VNLib collection of libraries and utilities. * * VNLib.Plugins.Extensions.Loading is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -22,9 +22,10 @@ * along with this program. If not, see https://www.gnu.org/licenses/. */ +using System.Threading; using System.Threading.Tasks; + using VNLib.Utils.Logging; -using System.Threading; namespace VNLib.Plugins.Extensions.Loading { diff --git a/lib/sql-providers/mysql/VNLib.Plugins.Extensions.Loading.Sql.MySql/src/MYSqlExport.cs b/lib/sql-providers/mysql/VNLib.Plugins.Extensions.Loading.Sql.MySql/src/MYSqlExport.cs index efe5410..3bafc23 100644 --- a/lib/sql-providers/mysql/VNLib.Plugins.Extensions.Loading.Sql.MySql/src/MYSqlExport.cs +++ b/lib/sql-providers/mysql/VNLib.Plugins.Extensions.Loading.Sql.MySql/src/MYSqlExport.cs @@ -48,6 +48,8 @@ namespace VNLib.Plugins.Extensions.Sql { private async Task BuildConnStringAsync() { + IOnDemandSecret pwd = plugin.Secrets().GetOnDemandSecret("db_password"); + MySqlConnectionStringBuilder sb; //See if the user suggested a raw connection string @@ -58,7 +60,7 @@ namespace VNLib.Plugins.Extensions.Sql //If the user did not provide a password, try to get it from secret storage if (string.IsNullOrWhiteSpace(sb.Password)) { - using ISecretResult? password = await plugin.TryGetSecretAsync("db_password"); + using ISecretResult? password = await pwd.FetchSecretAsync(); sb.Password = password?.Result.ToString(); } @@ -76,62 +78,62 @@ namespace VNLib.Plugins.Extensions.Sql sb = value.Deserialize(opt)!; //Get the db password from the secret manager - using ISecretResult? secret = await plugin.TryGetSecretAsync("db_password"); + using ISecretResult? secret = await pwd.FetchSecretAsync(); sb.Password = secret?.Result.ToString(); } else { //Get the password from the secret manager - using ISecretResult? secret = await plugin.TryGetSecretAsync("db_password"); + using ISecretResult? secret = await pwd.FetchSecretAsync(); sb = new() { - Server = config["hostname"].GetString(), - Database = config["catalog"].GetString(), - UserID = config["username"].GetString(), - Pooling = true, - MinimumPoolSize = config.GetValueOrDefault("min_pool_size", p => p.GetUInt32(), 10u), - MaximumPoolSize = config.GetValueOrDefault("max_pool_size", p => p.GetUInt32(), 50u), - Password = secret?.Result.ToString(), + Pooling = true, + Server = config.GetRequiredProperty("hostname"), + Database = config.GetRequiredProperty("catalog"), + UserID = config.GetRequiredProperty("username"), + MinimumPoolSize = config.GetValueOrDefault("min_pool_size", 10u), + MaximumPoolSize = config.GetValueOrDefault("max_pool_size", 50u), + Password = secret?.Result.ToString(), }; - if (config.TryGetProperty("port", p => p.GetUInt16(), out ushort port)) + if (config.TryGetProperty("port", out ushort port)) { sb.Port = port; } - if (config.TryGetProperty("ssl_mode", p => p.GetString(), out string? sslMode) + if (config.TryGetProperty("ssl_mode", out string? sslMode) && Enum.TryParse(sslMode, true, out MySqlSslMode mode)) { sb.SslMode = mode; } - if (config.TryGetProperty("connection_lifetime", value => value.GetUInt32(), out uint connLife)) + if (config.TryGetProperty("connection_lifetime", out uint connLife)) { sb.ConnectionLifeTime = connLife; } - if (config.TryGetProperty("connection_timeout", value => value.GetUInt32(), out uint connTimeout)) + if (config.TryGetProperty("connection_timeout", out uint connTimeout)) { sb.ConnectionTimeout = connTimeout; } - if (config.TryGetProperty("pipe_name", value => value.GetString(), out string? pipeName)) + if (config.TryGetProperty("pipe_name", out string? pipeName)) { sb.PipeName = pipeName; } - if (config.TryGetProperty("allow_load_local_infile", value => value.GetBoolean(), out bool allowLoadLocalInfile)) + if (config.TryGetProperty("allow_load_local_infile", out bool allowLoadLocalInfile)) { sb.AllowLoadLocalInfile = allowLoadLocalInfile; } - if (config.TryGetProperty("default_command_timeout", value => value.GetUInt32(), out uint defaultCommandTimeout)) + if (config.TryGetProperty("default_command_timeout", out uint defaultCommandTimeout)) { sb.DefaultCommandTimeout = defaultCommandTimeout; } - if (config.TryGetProperty("interactive_session", value => value.GetBoolean(), out bool interactiveSession)) + if (config.TryGetProperty("interactive_session", out bool interactiveSession)) { sb.InteractiveSession = interactiveSession; } diff --git a/lib/sql-providers/sqlite/VNLib.Plugins.Extensions.Loading.Sql.SQLite/src/SQLiteExport.cs b/lib/sql-providers/sqlite/VNLib.Plugins.Extensions.Loading.Sql.SQLite/src/SQLiteExport.cs index ff74051..e712e29 100644 --- a/lib/sql-providers/sqlite/VNLib.Plugins.Extensions.Loading.Sql.SQLite/src/SQLiteExport.cs +++ b/lib/sql-providers/sqlite/VNLib.Plugins.Extensions.Loading.Sql.SQLite/src/SQLiteExport.cs @@ -49,18 +49,20 @@ namespace VNLib.Plugins.Extensions.Sql private async Task BuildConnStringAsync() { + IOnDemandSecret pwd = plugin.Secrets().GetOnDemandSecret("db_password"); + SqliteConnectionStringBuilder sb; //See if the user suggested a raw connection string - if (config.TryGetProperty("connection_string", ps => ps.GetString(), out string? conString)) + if (config.TryGetProperty("connection_string", out string? conString)) { sb = new(conString); //If the user did not provide a password, try to get it from secret storage if (string.IsNullOrWhiteSpace(sb.Password)) { - using ISecretResult? password = await plugin.TryGetSecretAsync("db_password"); - sb.Password = password?.Result.ToString(); + using ISecretResult? secret = await pwd.FetchSecretAsync(); + sb.Password = secret?.Result.ToString(); } } else if (config.TryGetValue("json", out JsonElement value)) @@ -75,25 +77,24 @@ namespace VNLib.Plugins.Extensions.Sql sb = value.Deserialize(opt)!; //Get the password from the secret manager - using ISecretResult? secret = await plugin.TryGetSecretAsync("db_password"); + using ISecretResult? secret = await pwd.FetchSecretAsync(); sb.Password = secret?.Result.ToString(); } else { //Get the password from the secret manager - using ISecretResult? secret = await plugin.TryGetSecretAsync("db_password"); + using ISecretResult? secret = await pwd.FetchSecretAsync(); // Build connection strin sb = new() { - DataSource = config["source"].GetString(), - Pooling = true, - Cache = SqliteCacheMode.Default, - RecursiveTriggers = config.GetValueOrDefault("recursive_triggers", p => p.GetBoolean(), false), - DefaultTimeout = config.GetValueOrDefault("timeout", p => p.GetInt32(), 30), - Mode = config.GetValueOrDefault("mode", p => (SqliteOpenMode)p.GetInt32(), SqliteOpenMode.ReadWriteCreate), - - Password = secret?.Result.ToString(), + Pooling = true, + Cache = SqliteCacheMode.Default, + DataSource = config.GetRequiredProperty("source"), + RecursiveTriggers = config.GetValueOrDefault("recursive_triggers", false), + DefaultTimeout = config.GetValueOrDefault("timeout", 30), + Mode = config.GetValueOrDefault("mode", p => (SqliteOpenMode)p.GetInt32(), SqliteOpenMode.ReadWriteCreate), + Password = secret?.Result.ToString(), }; } @@ -119,7 +120,7 @@ namespace VNLib.Plugins.Extensions.Sql b.UseSqlite(connString); //Write debug loggin to the debug log if the user has it enabled or the plugin is in debug mode - if (config.GetValueOrDefault("debug", p => p.GetBoolean(), false) || plugin.IsDebug()) + if (config.GetValueOrDefault("debug", false) || plugin.IsDebug()) { //Write the SQL to the debug log b.LogTo((v) => plugin.Log.Debug("SQLite: {v}", v)); diff --git a/lib/sql-providers/sqlite/VNLib.Plugins.Extensions.Loading.Sql.SQLite/src/VNLib.Plugins.Extensions.Loading.Sql.SQLite.csproj b/lib/sql-providers/sqlite/VNLib.Plugins.Extensions.Loading.Sql.SQLite/src/VNLib.Plugins.Extensions.Loading.Sql.SQLite.csproj index b27fc00..9df3236 100644 --- a/lib/sql-providers/sqlite/VNLib.Plugins.Extensions.Loading.Sql.SQLite/src/VNLib.Plugins.Extensions.Loading.Sql.SQLite.csproj +++ b/lib/sql-providers/sqlite/VNLib.Plugins.Extensions.Loading.Sql.SQLite/src/VNLib.Plugins.Extensions.Loading.Sql.SQLite.csproj @@ -49,7 +49,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/lib/sql-providers/sqlserver/VNLib.Plugins.Extensions.Loading.Sql.SQLServer/src/SqlServerExport.cs b/lib/sql-providers/sqlserver/VNLib.Plugins.Extensions.Loading.Sql.SQLServer/src/SqlServerExport.cs index 89769f5..8374c29 100644 --- a/lib/sql-providers/sqlserver/VNLib.Plugins.Extensions.Loading.Sql.SQLServer/src/SqlServerExport.cs +++ b/lib/sql-providers/sqlserver/VNLib.Plugins.Extensions.Loading.Sql.SQLServer/src/SqlServerExport.cs @@ -47,17 +47,19 @@ namespace VNLib.Plugins.Extensions.Sql { private async Task BuildConnStringAsync() { + IOnDemandSecret pwd = plugin.Secrets().GetOnDemandSecret("db_password"); + SqlConnectionStringBuilder sb; //See if the user suggested a raw connection string - if (config.TryGetProperty("connection_string", ps => ps.GetString(), out string? conString)) + if (config.TryGetProperty("connection_string", out string? conString)) { sb = new(conString); //If the user did not provide a password, try to get it from secret storage if (string.IsNullOrWhiteSpace(sb.Password)) { - using ISecretResult? password = await plugin.TryGetSecretAsync("db_password"); + using ISecretResult? password = await pwd.FetchSecretAsync(); sb.Password = password?.Result.ToString(); } } @@ -74,41 +76,40 @@ namespace VNLib.Plugins.Extensions.Sql sb = value.Deserialize(opt)!; //Get the password from the secret manager - using ISecretResult? secret = await plugin.TryGetSecretAsync("db_password"); + using ISecretResult? secret = await pwd.FetchSecretAsync(); sb.Password = secret?.Result.ToString(); } else { - //Get the password from the secret manager - using ISecretResult? secret = await plugin.TryGetSecretAsync("db_password"); + using ISecretResult? secret = await pwd.FetchSecretAsync(); // Build connection string sb = new() { - DataSource = config["hostname"].GetString(), - InitialCatalog = config["catalog"].GetString(), - UserID = config["username"].GetString(), - Pooling = true, - - - ApplicationName = config.GetValueOrDefault("application_name", p => p.GetString(), string.Empty), - HostNameInCertificate = config.GetValueOrDefault("hostname_in_certificate", p => p.GetString(), string.Empty), - PacketSize = config.GetValueOrDefault("packet_size", p => p.GetInt32(), 8000), - Encrypt = config.GetValueOrDefault("encrypted", p => p.GetBoolean(), false), - IntegratedSecurity = config.GetValueOrDefault("integrated_security", p => p.GetBoolean(), false), - MultipleActiveResultSets = config.GetValueOrDefault("multiple_active_result_sets", p => p.GetBoolean(), false), - ConnectTimeout = config.GetValueOrDefault("connect_timeout", p => p.GetInt32(), 15), - LoadBalanceTimeout = config.GetValueOrDefault("load_balance_timeout", p => p.GetInt32(), 0), - MaxPoolSize = config.GetValueOrDefault("max_pool_size", p => p.GetInt32(), 100), - MinPoolSize = config.GetValueOrDefault("min_pool_size", p => p.GetInt32(), 0), - TransactionBinding = config.GetValueOrDefault("transaction_binding", p => p.GetString(), "Implicit Unbind"), - TypeSystemVersion = config.GetValueOrDefault("type_system_version", p => p.GetString(), "Latest"), - WorkstationID = config.GetValueOrDefault("workstation_id", p => p.GetString(), string.Empty), - CurrentLanguage = config.GetValueOrDefault("current_language", p => p.GetString(), "us_english"), - PersistSecurityInfo = config.GetValueOrDefault("persist_security_info", p => p.GetBoolean(), false), - Replication = config.GetValueOrDefault("replication", p => p.GetBoolean(), false), - TrustServerCertificate = config.GetValueOrDefault("trust_server_certificate", p => p.GetBoolean(), false), - UserInstance = config.GetValueOrDefault("user_instance", p => p.GetBoolean(), false), + DataSource = config.GetRequiredProperty("hostname"), + InitialCatalog = config.GetRequiredProperty("catalog"), + UserID = config.GetRequiredProperty("username"), + + //Pooling should be enabled unless the users explictly disables it + Pooling = config.GetValueOrDefault("pooling", true), + ApplicationName = config.GetValueOrDefault("application_name", string.Empty), + HostNameInCertificate = config.GetValueOrDefault("hostname_in_certificate", string.Empty), + PacketSize = config.GetValueOrDefault("packet_size", 8000), + Encrypt = config.GetValueOrDefault("encrypted", false), + IntegratedSecurity = config.GetValueOrDefault("integrated_security", false), + MultipleActiveResultSets = config.GetValueOrDefault("multiple_active_result_sets", false), + ConnectTimeout = config.GetValueOrDefault("connect_timeout", 15), + LoadBalanceTimeout = config.GetValueOrDefault("load_balance_timeout", 0), + MaxPoolSize = config.GetValueOrDefault("max_pool_size", 100), + MinPoolSize = config.GetValueOrDefault("min_pool_size", 0), + TransactionBinding = config.GetValueOrDefault("transaction_binding", "Implicit Unbind"), + TypeSystemVersion = config.GetValueOrDefault("type_system_version", "Latest"), + WorkstationID = config.GetValueOrDefault("workstation_id", string.Empty), + CurrentLanguage = config.GetValueOrDefault("current_language", "us_english"), + PersistSecurityInfo = config.GetValueOrDefault("persist_security_info", false), + Replication = config.GetValueOrDefault("replication", false), + TrustServerCertificate = config.GetValueOrDefault("trust_server_certificate", false), + UserInstance = config.GetValueOrDefault("user_instance", false), Password = secret?.Result.ToString(), }; @@ -136,7 +137,7 @@ namespace VNLib.Plugins.Extensions.Sql b.UseSqlServer(connString); //Write debug loggin to the debug log if the user has it enabled or the plugin is in debug mode - if (config.GetValueOrDefault("debug", p => p.GetBoolean(), false) || plugin.IsDebug()) + if (config.GetValueOrDefault("debug", false) || plugin.IsDebug()) { //Write the SQL to the debug log b.LogTo((v) => plugin.Log.Debug("SqlServer: {v}", v)); diff --git a/lib/sql-providers/sqlserver/VNLib.Plugins.Extensions.Loading.Sql.SQLServer/src/VNLib.Plugins.Extensions.Loading.Sql.SQLServer.csproj b/lib/sql-providers/sqlserver/VNLib.Plugins.Extensions.Loading.Sql.SQLServer/src/VNLib.Plugins.Extensions.Loading.Sql.SQLServer.csproj index 7015b8c..d99249b 100644 --- a/lib/sql-providers/sqlserver/VNLib.Plugins.Extensions.Loading.Sql.SQLServer/src/VNLib.Plugins.Extensions.Loading.Sql.SQLServer.csproj +++ b/lib/sql-providers/sqlserver/VNLib.Plugins.Extensions.Loading.Sql.SQLServer/src/VNLib.Plugins.Extensions.Loading.Sql.SQLServer.csproj @@ -49,7 +49,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + -- cgit