From 7590ea37f9e6a6c7972f9a1ac89c77653600ac13 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 8 Aug 2017 23:06:28 -0400 Subject: [PATCH] convert more services to local resources --- src/Api/settings.json | 1 + src/Billing/settings.json | 1 + src/Core/Core.csproj | 1 + src/Core/GlobalSettings.cs | 3 +++ src/Core/Utilities/CoreHelpers.cs | 2 +- src/Core/Utilities/LoggerFactoryExtensions.cs | 8 ++++---- src/Core/Utilities/ServiceCollectionExtensions.cs | 6 +++--- src/Identity/settings.json | 1 + util/Setup/Program.cs | 7 ++++++- 9 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Api/settings.json b/src/Api/settings.json index 11ff21bf1..31839f2ae 100644 --- a/src/Api/settings.json +++ b/src/Api/settings.json @@ -2,6 +2,7 @@ "globalSettings": { "selfHosted": false, "siteName": "bitwarden", + "projectName": "Api", "stripeApiKey": "SECRET", "baseServiceUri": { "vault": "http://localhost:4001", diff --git a/src/Billing/settings.json b/src/Billing/settings.json index 5c735556e..481f843ad 100644 --- a/src/Billing/settings.json +++ b/src/Billing/settings.json @@ -2,6 +2,7 @@ "globalSettings": { "selfHosted": false, "siteName": "bitwarden", + "projectName": "Billing", "stripeApiKey": "SECRET", "baseServiceUri": { "vault": "http://localhost:4001", diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index 6d2022c99..9bbbf5f8c 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -51,6 +51,7 @@ + diff --git a/src/Core/GlobalSettings.cs b/src/Core/GlobalSettings.cs index 46b89db31..ebcef09f5 100644 --- a/src/Core/GlobalSettings.cs +++ b/src/Core/GlobalSettings.cs @@ -5,6 +5,8 @@ public bool SelfHosted { get; set; } public virtual string SiteName { get; set; } public virtual string StripeApiKey { get; set; } + public virtual string ProjectName { get; set; } + public virtual string LogDirectory { get; set; } public virtual BaseServiceUriSettings BaseServiceUri { get; set; } = new BaseServiceUriSettings(); public virtual SqlServerSettings SqlServer { get; set; } = new SqlServerSettings(); public virtual MailSettings Mail { get; set; } = new MailSettings(); @@ -68,6 +70,7 @@ public class DataProtectionSettings { public string CertificateThumbprint { get; set; } + public string Directory { get; set; } } public class DocumentDbSettings diff --git a/src/Core/Utilities/CoreHelpers.cs b/src/Core/Utilities/CoreHelpers.cs index 2e277541f..ed442e9cb 100644 --- a/src/Core/Utilities/CoreHelpers.cs +++ b/src/Core/Utilities/CoreHelpers.cs @@ -280,7 +280,7 @@ namespace Bit.Core.Utilities public static bool SettingHasValue(string setting) { - if(string.IsNullOrWhiteSpace(setting) || setting.Equals("SECRET")) + if(string.IsNullOrWhiteSpace(setting) || setting.Equals("SECRET") || setting.Equals("REPLACE")) { return false; } diff --git a/src/Core/Utilities/LoggerFactoryExtensions.cs b/src/Core/Utilities/LoggerFactoryExtensions.cs index 6e24f4061..81d8ea7d0 100644 --- a/src/Core/Utilities/LoggerFactoryExtensions.cs +++ b/src/Core/Utilities/LoggerFactoryExtensions.cs @@ -26,15 +26,15 @@ namespace Bit.Core.Utilities .Enrich.FromLogContext() .Filter.ByIncludingOnly(filter); - if(globalSettings.DocumentDb != null && !string.IsNullOrWhiteSpace(globalSettings.DocumentDb.Uri) && - !string.IsNullOrWhiteSpace(globalSettings.DocumentDb.Key)) + if(globalSettings.DocumentDb != null && CoreHelpers.SettingHasValue(globalSettings.DocumentDb.Uri) && + CoreHelpers.SettingHasValue(globalSettings.DocumentDb.Key)) { config.WriteTo.AzureDocumentDB(new Uri(globalSettings.DocumentDb.Uri), globalSettings.DocumentDb.Key, timeToLive: TimeSpan.FromDays(7)); } - else + else if(CoreHelpers.SettingHasValue(globalSettings.LogDirectory)) { - // local file sink + config.WriteTo.RollingFile($"{globalSettings.LogDirectory}/{globalSettings.ProjectName}/{{Date}}.txt"); } var serilog = config.CreateLogger(); diff --git a/src/Core/Utilities/ServiceCollectionExtensions.cs b/src/Core/Utilities/ServiceCollectionExtensions.cs index a7f81ca50..4e7c50a61 100644 --- a/src/Core/Utilities/ServiceCollectionExtensions.cs +++ b/src/Core/Utilities/ServiceCollectionExtensions.cs @@ -222,10 +222,10 @@ namespace Bit.Core.Utilities return; } - if(globalSettings.SelfHosted) + if(globalSettings.SelfHosted && CoreHelpers.SettingHasValue(globalSettings.DataProtection.Directory)) { - var dir = new DirectoryInfo("/etc/bitwarden/core/aspnet-dataprotection"); - services.AddDataProtection().PersistKeysToFileSystem(dir); + services.AddDataProtection() + .PersistKeysToFileSystem(new DirectoryInfo(globalSettings.DataProtection.Directory)); } #if NET461 diff --git a/src/Identity/settings.json b/src/Identity/settings.json index 149e3dd0d..0ba274093 100644 --- a/src/Identity/settings.json +++ b/src/Identity/settings.json @@ -2,6 +2,7 @@ "globalSettings": { "selfHosted": false, "siteName": "bitwarden", + "projectName": "Identity", "stripeApiKey": "SECRET", "baseServiceUri": { "vault": "http://localhost:4001", diff --git a/util/Setup/Program.cs b/util/Setup/Program.cs index 2679f1f9d..c27b183e8 100644 --- a/util/Setup/Program.cs +++ b/util/Setup/Program.cs @@ -10,6 +10,7 @@ namespace Setup { private static string[] _args = null; private static IDictionary _parameters = null; + private static string _outputDir = null; private static string _domain = null; private static string _url = null; private static string _identityCertPassword = null; @@ -22,6 +23,8 @@ namespace Setup _args = args; _parameters = ParseParameters(); + _outputDir = _parameters.ContainsKey("out") ? + _parameters["out"].ToLowerInvariant() : "/etc/bitwarden"; _domain = _parameters.ContainsKey("domain") ? _parameters["domain"].ToLowerInvariant() : "localhost"; _letsEncrypt = _parameters.ContainsKey("letsencrypt") ? @@ -253,8 +256,10 @@ globalSettings:baseServiceUri:api={_url}/api globalSettings:baseServiceUri:identity={_url}/identity globalSettings:sqlServer:connectionString={dbConnectionString} globalSettings:identityServer:certificatePassword={_identityCertPassword} -globalSettings:attachment:baseDirectory=/etc/bitwarden/core/attachments +globalSettings:attachment:baseDirectory={_outputDir}/core/attachments globalSettings:attachment:baseUrl={_url}/attachments +globalSettings:dataProtection:directory={_outputDir}/core/aspnet-dataprotection +globalSettings:logDirectory={_outputDir}/core/logs globalSettings:duo:aKey={Helpers.SecureRandomString(32, alpha: true, numeric: true)} globalSettings:yubico:clientId=REPLACE globalSettings:yubico:REPLACE");