diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..2fb0e97e6e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,347 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "compounds": [ + { + "name": "Min Server", + "configurations": [ + "Identity", + "API" + ], + "presentation": { + "hidden": false, + "group": "AA_compounds", + "order": 1 + }, + "stopAll": true + }, + { + "name": "Admin, API, Identity", + "configurations": [ + "Admin", + "API", + "Identity" + ], + "presentation": { + "hidden": false, + "group": "AA_compounds", + "order": 3 + }, + "stopAll": true + }, + { + "name": "Full Server", + "configurations": [ + "Admin", + "API", + "EventsProcessor", + "Identity", + "Sso", + "Icons", + ], + "presentation": { + "hidden": false, + "group": "AA_compounds", + "order": 4 + }, + "stopAll": true + }, + { + "name": "Self Host: Bit", + "configurations": [ + "Admin-SelfHost", + "API-SelfHost", + "EventsProcessor-SelfHost", + "Identity-SelfHost", + "Sso-SelfHost", + ], + "presentation": { + "hidden": false, + "group": "AA_compounds", + "order": 2 + }, + "stopAll": true + }, + { + "name": "Self Host: OSS", + "configurations": [ + "Admin-SelfHost", + "API-SelfHost", + "EventsProcessor-SelfHost", + "Identity-SelfHost", + ], + "presentation": { + "hidden": false, + "group": "AA_compounds", + "order": 99 + }, + "stopAll": true + } + ], + "configurations": [ + { + "name": "Identity", + "presentation": { + "hidden": false, + "group": "cloud", + "order": 10 + }, + "requireExactSource": true, + "type": "coreclr", + "request": "launch", + "preLaunchTask": "buildIdentity", + "program": "${workspaceFolder}/src/Identity/bin/Debug/net5.0/Identity.dll", + "args": [], + "cwd": "${workspaceFolder}/src/Identity", + "stopAtEntry": false, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": "API", + "presentation": { + "hidden": false, + "group": "cloud", + "order": 10 + }, + "requireExactSource": true, + "type": "coreclr", + "request": "launch", + "preLaunchTask": "buildAPI", + "program": "${workspaceFolder}/src/Api/bin/Debug/net5.0/Api.dll", + "args": [], + "cwd": "${workspaceFolder}/src/Api", + "stopAtEntry": false, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": "Admin", + "presentation": { + "hidden": false, + "group": "cloud", + "order": 20 + }, + "requireExactSource": true, + "type": "coreclr", + "request": "launch", + "preLaunchTask": "buildAdmin", + "OS-COMMENT4": "If you have changed target frameworks, make sure to update the program path.", + "program": "${workspaceFolder}/src/Admin/bin/Debug/net5.0/Admin.dll", + "args": [], + "cwd": "${workspaceFolder}/src/Admin", + "stopAtEntry": false, + "OS-COMMENT5": "Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser", + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": "Sso", + "presentation": { + "hidden": false, + "group": "cloud", + "order": 50 + }, + "requireExactSource": true, + "type": "coreclr", + "request": "launch", + "preLaunchTask": "buildSso", + "program": "${workspaceFolder}/bitwarden_license/src/Sso/bin/Debug/net5.0/Sso.dll", + "args": [], + "cwd": "${workspaceFolder}/bitwarden_license/src/Sso", + "stopAtEntry": false, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": "EventsProcessor", + "presentation": { + "hidden": false, + "group": "cloud", + "order": 90 + }, + "requireExactSource": true, + "type": "coreclr", + "request": "launch", + "preLaunchTask": "buildEventsProcessor", + "program": "${workspaceFolder}/src/EventsProcessor/bin/Debug/net5.0/EventsProcessor.dll", + "args": [], + "cwd": "${workspaceFolder}/src/EventsProcessor", + "stopAtEntry": false, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": "Icons", + "presentation": { + "hidden": false, + "group": "cloud", + "order": 90 + }, + "requireExactSource": true, + "type": "coreclr", + "request": "launch", + "preLaunchTask": "buildIcons", + "program": "${workspaceFolder}/src/Icons/bin/Debug/net5.0/Icons.dll", + "args": [], + "cwd": "${workspaceFolder}/src/Icons", + "stopAtEntry": false, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": "Identity-SelfHost", + "presentation": { + "hidden": true, + "group": "self-host", + "order": 999 + }, + "requireExactSource": true, + "type": "coreclr", + "request": "launch", + "preLaunchTask": "buildIdentity", + "program": "${workspaceFolder}/src/Identity/bin/Debug/net5.0/Identity.dll", + "args": [], + "cwd": "${workspaceFolder}/src/Identity", + "stopAtEntry": false, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_URLS": "http://localhost:33657", + "developSelfHosted": "true" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": "API-SelfHost", + "presentation": { + "hidden": true, + "group": "self-host", + "order": 999 + }, + "requireExactSource": true, + "type": "coreclr", + "request": "launch", + "preLaunchTask": "buildAPI", + "program": "${workspaceFolder}/src/Api/bin/Debug/net5.0/Api.dll", + "args": [], + "cwd": "${workspaceFolder}/src/Api", + "stopAtEntry": false, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_URLS": "http://localhost:4001", + "developSelfHosted": "true" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": "Admin-SelfHost", + "presentation": { + "hidden": true, + "group": "self-host", + "order": 999 + }, + "requireExactSource": true, + "type": "coreclr", + "request": "launch", + "preLaunchTask": "buildAdmin", + "OS-COMMENT4": "If you have changed target frameworks, make sure to update the program path.", + "program": "${workspaceFolder}/src/Admin/bin/Debug/net5.0/Admin.dll", + "args": [], + "cwd": "${workspaceFolder}/src/Admin", + "stopAtEntry": false, + "OS-COMMENT5": "Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser", + "env": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_URLS": "http://localhost:62912", + "developSelfHosted": "true" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": "Sso-SelfHost", + "presentation": { + "hidden": true, + "group": "self-host", + "order": 999 + }, + "requireExactSource": true, + "type": "coreclr", + "request": "launch", + "preLaunchTask": "buildSso", + "program": "${workspaceFolder}/bitwarden_license/src/Sso/bin/Debug/net5.0/Sso.dll", + "args": [], + "cwd": "${workspaceFolder}/bitwarden_license/src/Sso", + "stopAtEntry": false, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_URLS": "http://localhost:51822", + "developSelfHosted": "true" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": "EventsProcessor-SelfHost", + "presentation": { + "hidden": true, + "group": "self-host", + "order": 999 + }, + "requireExactSource": true, + "type": "coreclr", + "request": "launch", + "preLaunchTask": "buildEventsProcessor", + "program": "${workspaceFolder}/src/EventsProcessor/bin/Debug/net5.0/EventsProcessor.dll", + "args": [], + "cwd": "${workspaceFolder}/src/EventsProcessor", + "stopAtEntry": false, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_URLS": "http://localhost:46274", + "developSelfHosted": "true" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ], +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000000..9837893855 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,125 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "buildIcons", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/src/Icons/Icons.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "buildPortal", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/bitwarden_license/src/Portal/Portal.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "buildSso", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/bitwarden_license/src/Sso/Sso.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "buildEventsProcessor", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/src/EventsProcessor/EventsProcessor.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "buildAdmin", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/src/Admin/Admin.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "buildIdentity", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/src/Identity/Identity.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "buildAPI", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/src/Api/Api.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile", + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "clean", + "type": "shell", + "command": "dotnet clean", + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared", + "showReuseMessage": true, + "clear": false + }, + "problemMatcher": "$msCompile" + }, + { + "label": "test", + "type": "shell", + "command": "dotnet test", + "group": { + "kind": "test", + "isDefault": true + }, + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared", + "showReuseMessage": true, + "clear": false + }, + "problemMatcher": "$msCompile" + } + ] +} diff --git a/bitwarden_license/src/Sso/Properties/launchSettings.json b/bitwarden_license/src/Sso/Properties/launchSettings.json index 8367fbeb72..e9c6e1dd1c 100644 --- a/bitwarden_license/src/Sso/Properties/launchSettings.json +++ b/bitwarden_license/src/Sso/Properties/launchSettings.json @@ -22,6 +22,15 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } + }, + "Sso-SelfHost": { + "commandName": "Project", + "launchBrowser": false, + "applicationUrl": "http://localhost:51823", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "developSelfHosted": "true" + } } } } diff --git a/bitwarden_license/src/Sso/Sso.csproj b/bitwarden_license/src/Sso/Sso.csproj index 3c95f46325..db322b5b5b 100644 --- a/bitwarden_license/src/Sso/Sso.csproj +++ b/bitwarden_license/src/Sso/Sso.csproj @@ -4,7 +4,6 @@ bitwarden-Sso - diff --git a/bitwarden_license/src/Sso/Startup.cs b/bitwarden_license/src/Sso/Startup.cs index 2b45504543..0156ed6d1f 100644 --- a/bitwarden_license/src/Sso/Startup.cs +++ b/bitwarden_license/src/Sso/Startup.cs @@ -34,7 +34,7 @@ namespace Bit.Sso services.AddOptions(); // Settings - var globalSettings = services.AddGlobalSettingsServices(Configuration); + var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment); // Stripe Billing StripeConfiguration.ApiKey = globalSettings.Stripe.ApiKey; diff --git a/dev/helpers/mssql/run_migrations.sh b/dev/helpers/mssql/run_migrations.sh index 97cd4b69a4..4024b16958 100755 --- a/dev/helpers/mssql/run_migrations.sh +++ b/dev/helpers/mssql/run_migrations.sh @@ -12,6 +12,20 @@ DATABASE="vault_dev" USER="SA" PASSWD=$MSSQL_PASSWORD +while getopts "rs" arg; do + case $arg in + r) + echo "Rerunning the last migration" + RERUN=1 + ;; + s) + echo "Running for self-host environment" + LAST_MIGRATION_FILE="/mnt/data/last_self_host_migration" + DATABASE="vault_dev_self_host" + ;; + esac +done + if [ ! -f "$LAST_MIGRATION_FILE" ]; then echo "$LAST_MIGRATION_FILE not found!" echo "This will run all migrations which might cause unexpected behaviour if the database is not empty." @@ -30,17 +44,6 @@ fi [ -z "$LAST_MIGRATION" ] PERFORM_MIGRATION=$? -while getopts "r" arg; do - case $arg in - r) - RERUN=1 - ;; - esac -done - -if [ -n "$RERUN" ]; then - echo "Rerunning the last migration" -fi # Create database if it does not already exist QUERY="IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '$DATABASE') diff --git a/src/Admin/Properties/launchSettings.json b/src/Admin/Properties/launchSettings.json index 4e1b92a719..579b1e11a0 100644 --- a/src/Admin/Properties/launchSettings.json +++ b/src/Admin/Properties/launchSettings.json @@ -22,6 +22,15 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "applicationUrl": "http://localhost:62911/" + }, + "Admin-SelfHost": { + "commandName": "Project", + "launchBrowser": false, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "developSelfHosted": "true" + }, + "applicationUrl": "http://localhost:62912/" } } } diff --git a/src/Admin/Startup.cs b/src/Admin/Startup.cs index 8ba71017b8..61a354251e 100644 --- a/src/Admin/Startup.cs +++ b/src/Admin/Startup.cs @@ -38,7 +38,7 @@ namespace Bit.Admin services.AddOptions(); // Settings - var globalSettings = services.AddGlobalSettingsServices(Configuration); + var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment); services.Configure(Configuration.GetSection("AdminSettings")); // Data Protection diff --git a/src/Api/Properties/launchSettings.json b/src/Api/Properties/launchSettings.json index ccbec652d6..5cf88eb93d 100644 --- a/src/Api/Properties/launchSettings.json +++ b/src/Api/Properties/launchSettings.json @@ -22,6 +22,15 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } + }, + "Api-SelfHost": { + "commandName": "Project", + "launchBrowser": false, + "applicationUrl": "http://localhost:4000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "developSelfHosted": "true" + } } } -} \ No newline at end of file +} diff --git a/src/Api/Startup.cs b/src/Api/Startup.cs index 57e0c1acd3..db84ec3367 100644 --- a/src/Api/Startup.cs +++ b/src/Api/Startup.cs @@ -43,7 +43,7 @@ namespace Bit.Api services.AddOptions(); // Settings - var globalSettings = services.AddGlobalSettingsServices(Configuration); + var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment); if (!globalSettings.SelfHosted) { services.Configure(Configuration.GetSection("IpRateLimitOptions")); diff --git a/src/Billing/Startup.cs b/src/Billing/Startup.cs index 28f17ef8cb..7ad1070e6d 100644 --- a/src/Billing/Startup.cs +++ b/src/Billing/Startup.cs @@ -18,13 +18,15 @@ namespace Bit.Billing { public class Startup { - public Startup(IConfiguration configuration) + public Startup(IWebHostEnvironment env, IConfiguration configuration) { CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); Configuration = configuration; + Environment = env; } public IConfiguration Configuration { get; } + public IWebHostEnvironment Environment { get; set; } public void ConfigureServices(IServiceCollection services) { @@ -32,7 +34,7 @@ namespace Bit.Billing services.AddOptions(); // Settings - var globalSettings = services.AddGlobalSettingsServices(Configuration); + var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment); services.Configure(Configuration.GetSection("BillingSettings")); // Stripe Billing diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index bafa7703e5..449749fa1b 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -15,6 +15,7 @@ + diff --git a/src/Core/Services/Implementations/LicensingService.cs b/src/Core/Services/Implementations/LicensingService.cs index 4190c5373e..6eb17e22cc 100644 --- a/src/Core/Services/Implementations/LicensingService.cs +++ b/src/Core/Services/Implementations/LicensingService.cs @@ -45,12 +45,12 @@ namespace Bit.Core.Services _logger = logger; _globalSettings = globalSettings; - var certThumbprint = environment.IsDevelopment() && !_globalSettings.SelfHosted ? + var certThumbprint = environment.IsDevelopment() ? "207E64A231E8AA32AAF68A61037C075EBEBD553F" : "‎B34876439FCDA2846505B2EFBBA6C4A951313EBE"; if (_globalSettings.SelfHosted) { - _certificate = CoreHelpers.GetEmbeddedCertificateAsync("licensing.cer", null) + _certificate = CoreHelpers.GetEmbeddedCertificateAsync(environment.IsDevelopment() ? "licensing_dev.cer" : "licensing.cer", null) .GetAwaiter().GetResult(); } else if (CoreHelpers.SettingHasValue(_globalSettings.Storage?.ConnectionString) && diff --git a/src/Core/Settings/GlobalSettings.cs b/src/Core/Settings/GlobalSettings.cs index 5259c75643..1f6c242038 100644 --- a/src/Core/Settings/GlobalSettings.cs +++ b/src/Core/Settings/GlobalSettings.cs @@ -424,6 +424,7 @@ namespace Bit.Core.Settings public class InstallationSettings { private string _identityUri; + private string _apiUri; public Guid Id { get; set; } public string Key { get; set; } @@ -432,6 +433,10 @@ namespace Bit.Core.Settings get => string.IsNullOrWhiteSpace(_identityUri) ? "https://identity.bitwarden.com" : _identityUri; set => _identityUri = value; } + public string ApiUri + { + get => string.IsNullOrWhiteSpace(_apiUri) ? "https://api.biwarden.com" : _apiUri; + } } public class AmazonSettings diff --git a/src/Core/licensing_dev.cer b/src/Core/licensing_dev.cer new file mode 100644 index 0000000000..0dbb09c3c6 Binary files /dev/null and b/src/Core/licensing_dev.cer differ diff --git a/src/Events/Properties/launchSettings.json b/src/Events/Properties/launchSettings.json index 7324a34834..f1d0b1b270 100644 --- a/src/Events/Properties/launchSettings.json +++ b/src/Events/Properties/launchSettings.json @@ -22,6 +22,15 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "applicationUrl": "http://localhost:46273/" + }, + "Events-SelfHost": { + "commandName": "Project", + "launchBrowser": false, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "developSelfHosted": "true" + }, + "applicationUrl": "http://localhost:46274/" } } } diff --git a/src/Events/Startup.cs b/src/Events/Startup.cs index 6cf103df69..6eb78da3a4 100644 --- a/src/Events/Startup.cs +++ b/src/Events/Startup.cs @@ -31,7 +31,7 @@ namespace Bit.Events services.AddOptions(); // Settings - var globalSettings = services.AddGlobalSettingsServices(Configuration); + var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment); // Repositories services.AddSqlServerRepositories(globalSettings); diff --git a/src/EventsProcessor/Startup.cs b/src/EventsProcessor/Startup.cs index 32feb9de7e..a09179a243 100644 --- a/src/EventsProcessor/Startup.cs +++ b/src/EventsProcessor/Startup.cs @@ -30,7 +30,7 @@ namespace Bit.EventsProcessor services.AddOptions(); // Settings - services.AddGlobalSettingsServices(Configuration); + services.AddGlobalSettingsServices(Configuration, Environment); // Hosted Services services.AddHostedService(); diff --git a/src/Icons/Startup.cs b/src/Icons/Startup.cs index 5e5bb27820..b8209f63f9 100644 --- a/src/Icons/Startup.cs +++ b/src/Icons/Startup.cs @@ -16,13 +16,15 @@ namespace Bit.Icons { public class Startup { - public Startup(IConfiguration configuration) + public Startup(IWebHostEnvironment env, IConfiguration configuration) { CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); Configuration = configuration; + Environment = env; } public IConfiguration Configuration { get; } + public IWebHostEnvironment Environment { get; } public void ConfigureServices(IServiceCollection services) { @@ -30,7 +32,7 @@ namespace Bit.Icons services.AddOptions(); // Settings - var globalSettings = services.AddGlobalSettingsServices(Configuration); + var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment); var iconsSettings = new IconsSettings(); ConfigurationBinder.Bind(Configuration.GetSection("IconsSettings"), iconsSettings); services.AddSingleton(s => iconsSettings); diff --git a/src/Identity/Properties/launchSettings.json b/src/Identity/Properties/launchSettings.json index 02a586ab61..7ee9b9ed5c 100644 --- a/src/Identity/Properties/launchSettings.json +++ b/src/Identity/Properties/launchSettings.json @@ -15,6 +15,15 @@ "ASPNETCORE_ENVIRONMENT": "Development" } }, + "Identity-SelfHost": { + "commandName": "Project", + "launchBrowser": false, + "applicationUrl": "http://localhost:33657", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "developSelfHosted": "true" + } + }, "Identity": { "commandName": "Project", "launchBrowser": false, @@ -24,4 +33,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/Identity/Startup.cs b/src/Identity/Startup.cs index a38b33fa01..35c6db2503 100644 --- a/src/Identity/Startup.cs +++ b/src/Identity/Startup.cs @@ -38,7 +38,7 @@ namespace Bit.Identity services.AddOptions(); // Settings - var globalSettings = services.AddGlobalSettingsServices(Configuration); + var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment); if (!globalSettings.SelfHosted) { services.Configure(Configuration.GetSection("IpRateLimitOptions")); diff --git a/src/Notifications/Startup.cs b/src/Notifications/Startup.cs index 4ca7b728ec..9a5a17d1d9 100644 --- a/src/Notifications/Startup.cs +++ b/src/Notifications/Startup.cs @@ -32,7 +32,7 @@ namespace Bit.Notifications services.AddOptions(); // Settings - var globalSettings = services.AddGlobalSettingsServices(Configuration); + var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment); // Identity services.AddIdentityAuthenticationServices(globalSettings, Environment, config => diff --git a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs index a6a2bb3be2..5109f7a727 100644 --- a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs +++ b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs @@ -462,10 +462,17 @@ namespace Bit.SharedWeb.Utilities } public static GlobalSettings AddGlobalSettingsServices(this IServiceCollection services, - IConfiguration configuration) + IConfiguration configuration, IWebHostEnvironment environment) { var globalSettings = new GlobalSettings(); ConfigurationBinder.Bind(configuration.GetSection("GlobalSettings"), globalSettings); + + if (environment.IsDevelopment() && configuration.GetValue("developSelfHosted")) + { + // Override settings with selfHostedOverride settings + ConfigurationBinder.Bind(configuration.GetSection("Dev:SelfHostOverride:GlobalSettings"), globalSettings); + } + services.AddSingleton(s => globalSettings); services.AddSingleton(s => globalSettings); return globalSettings;