summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-07-07 00:29:22 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-09-14 18:47:16 -0400
commite00fb85ee7822bc7fed2d6bd5a2e4c207a799418 (patch)
tree6ae80165b86d8ce20d4b44a3fa05ceb4d8433301 /src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs
parentf18ad1210cd813d6ddff665841ac712d62d18b1f (diff)
downloadSMAPI-e00fb85ee7822bc7fed2d6bd5a2e4c207a799418.tar.gz
SMAPI-e00fb85ee7822bc7fed2d6bd5a2e4c207a799418.tar.bz2
SMAPI-e00fb85ee7822bc7fed2d6bd5a2e4c207a799418.zip
migrate compatibility list's wiki data to MongoDB cache (#651)
Diffstat (limited to 'src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs')
-rw-r--r--src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs
new file mode 100644
index 00000000..352eb960
--- /dev/null
+++ b/src/SMAPI.Web/Framework/ConfigModels/MongoDbConfig.cs
@@ -0,0 +1,36 @@
+using System;
+
+namespace StardewModdingAPI.Web.Framework.ConfigModels
+{
+ /// <summary>The config settings for mod compatibility list.</summary>
+ internal class MongoDbConfig
+ {
+ /*********
+ ** 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; }
+
+
+ /*********
+ ** Public method
+ *********/
+ /// <summary>Get the MongoDB connection string.</summary>
+ /// <param name="authDatabase">The initial database for which to authenticate.</param>
+ public string GetConnectionString(string authDatabase)
+ {
+ 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}/{authDatabase}retryWrites=true&w=majority";
+ }
+ }
+}