From 082f285bc7ce156ad0750bb48d46ed65a2e4aedb Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 22 Dec 2019 00:44:13 -0500 Subject: streamline local environments, update technical docs & privacy page --- src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs') diff --git a/src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs index 3c508300..e2e18477 100644 --- a/src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs +++ b/src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs @@ -24,6 +24,12 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /********* ** Public method *********/ + /// Get whether a MongoDB instance is configured. + public bool IsConfigured() + { + return !string.IsNullOrWhiteSpace(this.Host); + } + /// Get the MongoDB connection string. public string GetConnectionString() { -- cgit From d6ef6f627ae049c29c2241d39261dee7de3da663 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 22 Dec 2019 12:08:01 -0500 Subject: configure MongoDB connection string directly --- docs/technical/web.md | 4 +--- .../Framework/ConfigModels/MongoDbConfig.cs | 25 +++------------------- src/SMAPI.Web/Startup.cs | 4 ++-- src/SMAPI.Web/appsettings.Development.json | 4 +--- src/SMAPI.Web/appsettings.json | 6 ++---- 5 files changed, 9 insertions(+), 34 deletions(-) (limited to 'src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs') diff --git a/docs/technical/web.md b/docs/technical/web.md index 697ec280..67e86c8b 100644 --- a/docs/technical/web.md +++ b/docs/technical/web.md @@ -366,9 +366,7 @@ Initial setup: `ApiClients.AzureBlobConnectionString` | The connection string for the Azure Blob storage account created in step 2. `ApiClients.GitHubUsername`
`ApiClients.GitHubPassword` | The login credentials for the GitHub account with which to fetch release info. If these are omitted, GitHub will impose much stricter rate limits. `ApiClients:NexusApiKey` | The [Nexus API authentication key](https://github.com/Pathoschild/FluentNexus#init-a-client). - `MongoDB:Host` | The hostname for the MongoDB instance. - `MongoDB:Username` | The login username for the MongoDB instance. - `MongoDB:Password` | The login password for the MongoDB instance. + `MongoDB:ConnectionString` | The connection string for the MongoDB instance. `MongoDB:Database` | The MongoDB database name (e.g. `smapi` in production or `smapi-edge` in testing environments). Optional settings: diff --git a/src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs index e2e18477..c7b6cb00 100644 --- a/src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs +++ b/src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs @@ -1,5 +1,3 @@ -using System; - namespace StardewModdingAPI.Web.Framework.ConfigModels { /// The config settings for mod compatibility list. @@ -8,14 +6,8 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /********* ** Accessors *********/ - /// The MongoDB hostname. - public string Host { get; set; } - - /// The MongoDB username (if any). - public string Username { get; set; } - - /// The MongoDB password (if any). - public string Password { get; set; } + /// The MongoDB connection string. + public string ConnectionString { get; set; } /// The database name. public string Database { get; set; } @@ -27,18 +19,7 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /// Get whether a MongoDB instance is configured. public bool IsConfigured() { - return !string.IsNullOrWhiteSpace(this.Host); - } - - /// Get the MongoDB connection string. - public string GetConnectionString() - { - bool isLocal = this.Host == "localhost"; - bool hasLogin = !string.IsNullOrWhiteSpace(this.Username) && !string.IsNullOrWhiteSpace(this.Password); - - return $"mongodb{(isLocal ? "" : "+srv")}://" - + (hasLogin ? $"{Uri.EscapeDataString(this.Username)}:{Uri.EscapeDataString(this.Password)}@" : "") - + $"{this.Host}/{this.Database}?retryWrites=true&w=majority"; + return !string.IsNullOrWhiteSpace(this.ConnectionString); } } } diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index 338cd2d5..29086472 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -100,7 +100,7 @@ namespace StardewModdingAPI.Web { // get connection string string connectionString = mongoConfig.IsConfigured() - ? mongoConfig.GetConnectionString() + ? mongoConfig.ConnectionString : serv.GetRequiredService().ConnectionString; // get client @@ -121,7 +121,7 @@ namespace StardewModdingAPI.Web if (mongoConfig.IsConfigured()) { - config.UseMongoStorage(mongoConfig.GetConnectionString(), $"{mongoConfig.Database}-hangfire", new MongoStorageOptions + config.UseMongoStorage(mongoConfig.ConnectionString, $"{mongoConfig.Database}-hangfire", new MongoStorageOptions { MigrationOptions = new MongoMigrationOptions(MongoMigrationStrategy.Drop), CheckConnection = false // error on startup takes down entire process diff --git a/src/SMAPI.Web/appsettings.Development.json b/src/SMAPI.Web/appsettings.Development.json index a6e48c69..54460c46 100644 --- a/src/SMAPI.Web/appsettings.Development.json +++ b/src/SMAPI.Web/appsettings.Development.json @@ -18,9 +18,7 @@ }, "MongoDB": { - "Host": null, - "Username": null, - "Password": null, + "ConnectionString": null, "Database": "smapi-edge" }, diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json index 0f61ebb9..caeb381f 100644 --- a/src/SMAPI.Web/appsettings.json +++ b/src/SMAPI.Web/appsettings.json @@ -50,10 +50,8 @@ }, "MongoDB": { - "Host": null, - "Username": null, - "Password": null, - "Database": null + "ConnectionString": null, + "Database": "smapi" }, "ModCompatibilityList": { -- cgit