using System; namespace StardewModdingAPI.Web.Framework.ConfigModels { /// The config settings for mod compatibility list. internal class MongoDbConfig { /********* ** 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; } /********* ** Public method *********/ /// Get the MongoDB connection string. /// The initial database for which to authenticate. 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"; } } }