1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00

make web appsettings overrides

This commit is contained in:
Kyle Spearrin 2017-08-07 21:16:56 -04:00
parent a281e9906d
commit 3e7c0f7ca1

View File

@ -11,6 +11,7 @@ namespace Setup
private static string[] _args = null;
private static IDictionary<string, string> _parameters = null;
private static string _domain = null;
private static string _url = null;
private static string _certPassword = null;
private static bool _ssl = false;
private static bool _letsEncrypt = false;
@ -20,14 +21,19 @@ namespace Setup
_args = args;
_parameters = ParseParameters();
_domain = _parameters.ContainsKey("domain") ? _parameters["domain"].ToLowerInvariant() : "localhost";
_letsEncrypt = _parameters.ContainsKey("letsencrypt") ? _parameters["letsencrypt"].ToLowerInvariant() == "y" : false;
_ssl = _letsEncrypt || (_parameters.ContainsKey("ssl") ? _parameters["ssl"].ToLowerInvariant() == "y" : false);
_domain = _parameters.ContainsKey("domain") ?
_parameters["domain"].ToLowerInvariant() : "localhost";
_letsEncrypt = _parameters.ContainsKey("letsencrypt") ?
_parameters["letsencrypt"].ToLowerInvariant() == "y" : false;
_ssl = _letsEncrypt || (_parameters.ContainsKey("ssl") ?
_parameters["ssl"].ToLowerInvariant() == "y" : false);
_url = _ssl ? $"https://{_domain}" : $"http://{_domain}";
_certPassword = Helpers.SecureRandomString(32, alpha: true, numeric: true);
MakeIdentityCert();
BuildNginxConfig();
BuildEnvironmentFiles();
BuildAppSettingsFiles();
}
private static void MakeIdentityCert()
@ -159,17 +165,16 @@ server {{
private static void BuildEnvironmentFiles()
{
var url = _ssl ? $"https://{_domain}" : $"http://{_domain}";
var dbPass = _parameters.ContainsKey("db_pass") ? _parameters["db_pass"].ToLowerInvariant() : "REPLACE";
var dbConnectionString = "Server=tcp:mssql,1433;Initial Catalog=vault;Persist Security Info=False;User ID=sa;" +
$"Password={dbPass};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;" +
"Connection Timeout=30;";
using(var sw = File.CreateText("/bitwarden/global.override.env"))
using(var sw = File.CreateText("/bitwarden/docker/global.override.env"))
{
sw.Write($@"globalSettings:baseServiceUri:vault={url}
globalSettings:baseServiceUri:api={url}/api
globalSettings:baseServiceUri:identity={url}/identity
sw.Write($@"globalSettings:baseServiceUri:vault={_url}
globalSettings:baseServiceUri:api={_url}/api
globalSettings:baseServiceUri:identity={_url}/identity
globalSettings:sqlServer:connectionString={dbConnectionString}
globalSettings:identityServer:certificatePassword={_certPassword}
globalSettings:duo:aKey={Helpers.SecureRandomString(32, alpha: true, numeric: true)}
@ -177,7 +182,7 @@ globalSettings:yubico:clientId=REPLACE
globalSettings:yubico:REPLACE");
}
using(var sw = File.CreateText("/bitwarden/mssql.override.env"))
using(var sw = File.CreateText("/bitwarden/docker/mssql.override.env"))
{
sw.Write($@"ACCEPT_EULA=Y
MSSQL_PID=Express
@ -185,6 +190,19 @@ SA_PASSWORD={dbPass}");
}
}
private static void BuildAppSettingsFiles()
{
Directory.CreateDirectory("/bitwarden/web/");
using(var sw = File.CreateText("/bitwarden/web/settings.js"))
{
sw.Write($@"var bitwardenAppSettings = {{
apiUri: ""{_url}/api"",
identityUri: ""{_url}/identity"",
whitelistDomains: [""{_domain}""]
}};");
}
}
private static IDictionary<string, string> ParseParameters()
{
var dict = new Dictionary<string, string>();