From 69c9a84562945c9aca6fc7645e823acde83cb381 Mon Sep 17 00:00:00 2001 From: IzyPro Date: Fri, 19 May 2023 21:44:50 +0100 Subject: [PATCH] - Security Optimization - Query Filters Fixes and Optimizations - Package Assembly as DB Name Fix(MongoDB) --- README.md | 4 ++-- WatchDog/WatchDog.csproj | 2 +- WatchDog/WatchDogExtension.cs | 5 ++--- WatchDog/src/Data/ExternalDbContext.cs | 4 ++-- WatchDog/src/Models/WatchDogConfigModel.cs | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3487e6e..66bb08d 100644 --- a/README.md +++ b/README.md @@ -43,12 +43,12 @@ It leverages `SignalR` for real-time monitoring and `LiteDb` a Serverless MongoD Install via .NET CLI ```bash -dotnet add package WatchDog.NET --version 1.4.9 +dotnet add package WatchDog.NET --version 1.4.10 ``` Install via Package Manager ```bash -Install-Package WatchDog.NET --version 1.4.9 +Install-Package WatchDog.NET --version 1.4.10 ``` diff --git a/WatchDog/WatchDog.csproj b/WatchDog/WatchDog.csproj index 05be014..962858e 100644 --- a/WatchDog/WatchDog.csproj +++ b/WatchDog/WatchDog.csproj @@ -12,7 +12,7 @@ Israel Ulelu, Kelechi Onyekwere WatchDog.NET MIT - 1.4.9 + 1.4.10 - Security Optimization - Query Filters Fixes and Optimizations - Package Assembly as DB Name Fix(MongoDB) diff --git a/WatchDog/WatchDogExtension.cs b/WatchDog/WatchDogExtension.cs index ba94923..e6c4597 100644 --- a/WatchDog/WatchDogExtension.cs +++ b/WatchDog/WatchDogExtension.cs @@ -26,7 +26,6 @@ public static class WatchDogExtension public static IServiceCollection AddWatchDogServices(this IServiceCollection services, [Optional] Action configureOptions) { - string mongoDbName = Assembly.GetCallingAssembly().GetName().Name.Replace('.', '_') + "_WatchDogDB"; var options = new WatchDogSettings(); if (configureOptions != null) configureOptions(options); @@ -35,7 +34,7 @@ public static IServiceCollection AddWatchDogServices(this IServiceCollection ser AutoClearModel.ClearTimeSchedule = options.ClearTimeSchedule; WatchDogExternalDbConfig.ConnectionString = options.SetExternalDbConnString; WatchDogDatabaseDriverOption.DatabaseDriverOption = options.DbDriverOption; - WatchDogExternalDbConfig.MongoDbName = mongoDbName; + WatchDogExternalDbConfig.MongoDbName = Assembly.GetCallingAssembly().GetName().Name?.Replace('.', '_') + "_WatchDogDB"; if (!string.IsNullOrEmpty(WatchDogExternalDbConfig.ConnectionString) && WatchDogDatabaseDriverOption.DatabaseDriverOption == 0) throw new WatchDogDBDriverException("Missing DB Driver Option: DbDriverOption is required at .AddWatchDogServices()"); @@ -64,7 +63,7 @@ public static IServiceCollection AddWatchDogServices(this IServiceCollection ser { if (WatchDogDatabaseDriverOption.DatabaseDriverOption == src.Enums.WatchDogDbDriverEnum.Mongo) { - ExternalDbContext.MigrateNoSql(mongoDbName); + ExternalDbContext.MigrateNoSql(); } else { diff --git a/WatchDog/src/Data/ExternalDbContext.cs b/WatchDog/src/Data/ExternalDbContext.cs index 5db1b65..500035b 100644 --- a/WatchDog/src/Data/ExternalDbContext.cs +++ b/WatchDog/src/Data/ExternalDbContext.cs @@ -54,12 +54,12 @@ public static void BootstrapTables() } - public static void MigrateNoSql(string databaseName) + public static void MigrateNoSql() { try { var mongoClient = CreateMongoDBConnection(); - var database = mongoClient.GetDatabase(databaseName); + var database = mongoClient.GetDatabase(WatchDogExternalDbConfig.MongoDbName); _ = database.GetCollection(Constants.WatchLogTableName); _ = database.GetCollection(Constants.WatchLogExceptionTableName); _ = database.GetCollection(Constants.LogsTableName); diff --git a/WatchDog/src/Models/WatchDogConfigModel.cs b/WatchDog/src/Models/WatchDogConfigModel.cs index 37b3c49..d0f7d2e 100644 --- a/WatchDog/src/Models/WatchDogConfigModel.cs +++ b/WatchDog/src/Models/WatchDogConfigModel.cs @@ -20,7 +20,7 @@ public class WatchDogSettings public static class WatchDogExternalDbConfig { public static string ConnectionString { get; set; } = string.Empty; - public static string MongoDbName { get; set; } = string.Empty; + public static string MongoDbName { get; set; } = "WatchDogDb"; } public static class WatchDogDatabaseDriverOption