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:
parent
a281e9906d
commit
3e7c0f7ca1
@ -11,6 +11,7 @@ namespace Setup
|
|||||||
private static string[] _args = null;
|
private static string[] _args = null;
|
||||||
private static IDictionary<string, string> _parameters = null;
|
private static IDictionary<string, string> _parameters = null;
|
||||||
private static string _domain = null;
|
private static string _domain = null;
|
||||||
|
private static string _url = null;
|
||||||
private static string _certPassword = null;
|
private static string _certPassword = null;
|
||||||
private static bool _ssl = false;
|
private static bool _ssl = false;
|
||||||
private static bool _letsEncrypt = false;
|
private static bool _letsEncrypt = false;
|
||||||
@ -20,14 +21,19 @@ namespace Setup
|
|||||||
_args = args;
|
_args = args;
|
||||||
_parameters = ParseParameters();
|
_parameters = ParseParameters();
|
||||||
|
|
||||||
_domain = _parameters.ContainsKey("domain") ? _parameters["domain"].ToLowerInvariant() : "localhost";
|
_domain = _parameters.ContainsKey("domain") ?
|
||||||
_letsEncrypt = _parameters.ContainsKey("letsencrypt") ? _parameters["letsencrypt"].ToLowerInvariant() == "y" : false;
|
_parameters["domain"].ToLowerInvariant() : "localhost";
|
||||||
_ssl = _letsEncrypt || (_parameters.ContainsKey("ssl") ? _parameters["ssl"].ToLowerInvariant() == "y" : false);
|
_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);
|
_certPassword = Helpers.SecureRandomString(32, alpha: true, numeric: true);
|
||||||
|
|
||||||
MakeIdentityCert();
|
MakeIdentityCert();
|
||||||
BuildNginxConfig();
|
BuildNginxConfig();
|
||||||
BuildEnvironmentFiles();
|
BuildEnvironmentFiles();
|
||||||
|
BuildAppSettingsFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void MakeIdentityCert()
|
private static void MakeIdentityCert()
|
||||||
@ -159,17 +165,16 @@ server {{
|
|||||||
|
|
||||||
private static void BuildEnvironmentFiles()
|
private static void BuildEnvironmentFiles()
|
||||||
{
|
{
|
||||||
var url = _ssl ? $"https://{_domain}" : $"http://{_domain}";
|
|
||||||
var dbPass = _parameters.ContainsKey("db_pass") ? _parameters["db_pass"].ToLowerInvariant() : "REPLACE";
|
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;" +
|
var dbConnectionString = "Server=tcp:mssql,1433;Initial Catalog=vault;Persist Security Info=False;User ID=sa;" +
|
||||||
$"Password={dbPass};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;" +
|
$"Password={dbPass};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;" +
|
||||||
"Connection Timeout=30;";
|
"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}
|
sw.Write($@"globalSettings:baseServiceUri:vault={_url}
|
||||||
globalSettings:baseServiceUri:api={url}/api
|
globalSettings:baseServiceUri:api={_url}/api
|
||||||
globalSettings:baseServiceUri:identity={url}/identity
|
globalSettings:baseServiceUri:identity={_url}/identity
|
||||||
globalSettings:sqlServer:connectionString={dbConnectionString}
|
globalSettings:sqlServer:connectionString={dbConnectionString}
|
||||||
globalSettings:identityServer:certificatePassword={_certPassword}
|
globalSettings:identityServer:certificatePassword={_certPassword}
|
||||||
globalSettings:duo:aKey={Helpers.SecureRandomString(32, alpha: true, numeric: true)}
|
globalSettings:duo:aKey={Helpers.SecureRandomString(32, alpha: true, numeric: true)}
|
||||||
@ -177,7 +182,7 @@ globalSettings:yubico:clientId=REPLACE
|
|||||||
globalSettings:yubico: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
|
sw.Write($@"ACCEPT_EULA=Y
|
||||||
MSSQL_PID=Express
|
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()
|
private static IDictionary<string, string> ParseParameters()
|
||||||
{
|
{
|
||||||
var dict = new Dictionary<string, string>();
|
var dict = new Dictionary<string, string>();
|
||||||
|
Loading…
Reference in New Issue
Block a user