summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-12-22 12:08:01 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-12-22 12:08:01 -0500
commitd6ef6f627ae049c29c2241d39261dee7de3da663 (patch)
tree0d3ff3199d41c49c25aa82ff9faf95df382c38dc /src/SMAPI.Web
parent139e267aaaeca9ad84e2a46b1068967b5599f1b6 (diff)
downloadSMAPI-d6ef6f627ae049c29c2241d39261dee7de3da663.tar.gz
SMAPI-d6ef6f627ae049c29c2241d39261dee7de3da663.tar.bz2
SMAPI-d6ef6f627ae049c29c2241d39261dee7de3da663.zip
configure MongoDB connection string directly
Diffstat (limited to 'src/SMAPI.Web')
-rw-r--r--src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs25
-rw-r--r--src/SMAPI.Web/Startup.cs4
-rw-r--r--src/SMAPI.Web/appsettings.Development.json4
-rw-r--r--src/SMAPI.Web/appsettings.json6
4 files changed, 8 insertions, 31 deletions
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
{
/// <summary>The config settings for mod compatibility list.</summary>
@@ -8,14 +6,8 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels
/*********
** Accessors
*********/
- /// <summary>The MongoDB hostname.</summary>
- public string Host { get; set; }
-
- /// <summary>The MongoDB username (if any).</summary>
- public string Username { get; set; }
-
- /// <summary>The MongoDB password (if any).</summary>
- public string Password { get; set; }
+ /// <summary>The MongoDB connection string.</summary>
+ public string ConnectionString { get; set; }
/// <summary>The database name.</summary>
public string Database { get; set; }
@@ -27,18 +19,7 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels
/// <summary>Get whether a MongoDB instance is configured.</summary>
public bool IsConfigured()
{
- return !string.IsNullOrWhiteSpace(this.Host);
- }
-
- /// <summary>Get the MongoDB connection string.</summary>
- 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<MongoDbRunner>().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": {