Add cli option to use settings from env variables
Currently [in docker it is possible to do configuration through environment variables](https://col.la/dockercodeconfigviaenv), which works using the start-collabora-online.sh start-collabora-online.pl scripts. This commit lets COOLWSD listen to the same environment variables directly Change-Id: I75762ad620132037523fa82167a3ff17075c7027 Signed-off-by: Skyler Grey <skyler.grey@collabora.com>pull/7288/head
parent
d94dbf8c32
commit
1b3218df04
|
@ -30,5 +30,7 @@ coolwsd OPTIONS
|
||||||
.PP
|
.PP
|
||||||
\fB\-\-nocaps\fR Use a non\-privileged forkit, with increase in security problems.
|
\fB\-\-nocaps\fR Use a non\-privileged forkit, with increase in security problems.
|
||||||
.PP
|
.PP
|
||||||
|
\fB\-\-use\-env\-vars\fR Override coolwsd.xml config with options from the environment variables described in https://col.la/dockercodeconfigviaenv
|
||||||
|
.PP
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
coolforkit(1), coolconvert(1), coolconfig(1), coolwsd-systemplate-setup(1), coolmount(1)
|
coolforkit(1), coolconvert(1), coolconfig(1), coolwsd-systemplate-setup(1), coolmount(1)
|
||||||
|
|
|
@ -901,6 +901,7 @@ bool COOLWSD::NoSeccomp = false;
|
||||||
bool COOLWSD::AdminEnabled = true;
|
bool COOLWSD::AdminEnabled = true;
|
||||||
bool COOLWSD::UnattendedRun = false;
|
bool COOLWSD::UnattendedRun = false;
|
||||||
bool COOLWSD::SignalParent = false;
|
bool COOLWSD::SignalParent = false;
|
||||||
|
bool COOLWSD::UseEnvVarOptions = false;
|
||||||
std::string COOLWSD::RouteToken;
|
std::string COOLWSD::RouteToken;
|
||||||
#if ENABLE_DEBUG
|
#if ENABLE_DEBUG
|
||||||
bool COOLWSD::SingleKit = false;
|
bool COOLWSD::SingleKit = false;
|
||||||
|
@ -2232,7 +2233,9 @@ void COOLWSD::innerInitialize(Application& self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override any settings passed on the command-line.
|
// Override any settings passed on the command-line or via environment variables
|
||||||
|
if (UseEnvVarOptions)
|
||||||
|
initializeEnvOptions();
|
||||||
AutoPtr<AppConfigMap> overrideConfig(new AppConfigMap(_overrideSettings));
|
AutoPtr<AppConfigMap> overrideConfig(new AppConfigMap(_overrideSettings));
|
||||||
conf.addWriteable(overrideConfig, PRIO_APPLICATION); // Highest priority
|
conf.addWriteable(overrideConfig, PRIO_APPLICATION); // Highest priority
|
||||||
|
|
||||||
|
@ -2998,6 +3001,16 @@ void COOLWSD::defineOptions(OptionSet& optionSet)
|
||||||
.required(false)
|
.required(false)
|
||||||
.repeatable(false));
|
.repeatable(false));
|
||||||
|
|
||||||
|
optionSet.addOption(Option("use-env-vars", "",
|
||||||
|
"Use the environment variables defined on "
|
||||||
|
"https://sdk.collaboraonline.com/docs/installation/"
|
||||||
|
"CODE_Docker_image.html#setting-the-application-configuration-"
|
||||||
|
"dynamically-via-environment-variables to set options. "
|
||||||
|
"'DONT_GEN_SSL_CERT' is forcibly enabled and 'extra_params' is "
|
||||||
|
"ignored even when using this option.")
|
||||||
|
.required(false)
|
||||||
|
.repeatable(false));
|
||||||
|
|
||||||
#if ENABLE_DEBUG
|
#if ENABLE_DEBUG
|
||||||
optionSet.addOption(Option("unitlib", "", "Unit testing library path.")
|
optionSet.addOption(Option("unitlib", "", "Unit testing library path.")
|
||||||
.required(false)
|
.required(false)
|
||||||
|
@ -3066,6 +3079,8 @@ void COOLWSD::handleOption(const std::string& optionName,
|
||||||
LoTemplate = value;
|
LoTemplate = value;
|
||||||
else if (optionName == "signal")
|
else if (optionName == "signal")
|
||||||
SignalParent = true;
|
SignalParent = true;
|
||||||
|
else if (optionName == "use-env-vars")
|
||||||
|
UseEnvVarOptions = true;
|
||||||
|
|
||||||
#if ENABLE_DEBUG
|
#if ENABLE_DEBUG
|
||||||
else if (optionName == "unitlib")
|
else if (optionName == "unitlib")
|
||||||
|
@ -3096,6 +3111,45 @@ void COOLWSD::handleOption(const std::string& optionName,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void COOLWSD::initializeEnvOptions()
|
||||||
|
{
|
||||||
|
int n = 0;
|
||||||
|
char* aliasGroup;
|
||||||
|
while ((aliasGroup = std::getenv(("aliasgroup" + std::to_string(n + 1)).c_str())) != nullptr)
|
||||||
|
{
|
||||||
|
bool first = true;
|
||||||
|
std::istringstream aliasGroupStream;
|
||||||
|
aliasGroupStream.str(aliasGroup);
|
||||||
|
for (std::string alias; std::getline(aliasGroupStream, alias, ',');)
|
||||||
|
{
|
||||||
|
if (first)
|
||||||
|
{
|
||||||
|
_overrideSettings["storage.wopi.alias_groups.group[" + std::to_string(n) +
|
||||||
|
"].host"] = alias;
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_overrideSettings["storage.wopi.alias_groups.group[" + std::to_string(n) +
|
||||||
|
"].alias"] = alias;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
if (n >= 1)
|
||||||
|
{
|
||||||
|
_overrideSettings["alias_groups[@mode]"] = "groups";
|
||||||
|
}
|
||||||
|
|
||||||
|
char* optionValue;
|
||||||
|
if ((optionValue = std::getenv("username")) != nullptr) _overrideSettings["admin_console.username"] = optionValue;
|
||||||
|
if ((optionValue = std::getenv("password")) != nullptr) _overrideSettings["admin_console.password"] = optionValue;
|
||||||
|
if ((optionValue = std::getenv("server_name")) != nullptr) _overrideSettings["server_name"] = optionValue;
|
||||||
|
if ((optionValue = std::getenv("dictionaries")) != nullptr) _overrideSettings["allowed_languages"] = optionValue;
|
||||||
|
if ((optionValue = std::getenv("remoteconfigurl")) != nullptr) _overrideSettings["remote_config.remote_url"] = optionValue;
|
||||||
|
}
|
||||||
|
|
||||||
#if !MOBILEAPP
|
#if !MOBILEAPP
|
||||||
|
|
||||||
void COOLWSD::displayHelp()
|
void COOLWSD::displayHelp()
|
||||||
|
|
|
@ -249,6 +249,7 @@ public:
|
||||||
static bool AdminEnabled;
|
static bool AdminEnabled;
|
||||||
static bool UnattendedRun; //< True when run from an unattended test, not interactive.
|
static bool UnattendedRun; //< True when run from an unattended test, not interactive.
|
||||||
static bool SignalParent;
|
static bool SignalParent;
|
||||||
|
static bool UseEnvVarOptions;
|
||||||
static std::string RouteToken;
|
static std::string RouteToken;
|
||||||
#if ENABLE_DEBUG
|
#if ENABLE_DEBUG
|
||||||
static bool SingleKit;
|
static bool SingleKit;
|
||||||
|
@ -518,6 +519,7 @@ protected:
|
||||||
|
|
||||||
void defineOptions(Poco::Util::OptionSet& options) override;
|
void defineOptions(Poco::Util::OptionSet& options) override;
|
||||||
void handleOption(const std::string& name, const std::string& value) override;
|
void handleOption(const std::string& name, const std::string& value) override;
|
||||||
|
void initializeEnvOptions();
|
||||||
int main(const std::vector<std::string>& args) override;
|
int main(const std::vector<std::string>& args) override;
|
||||||
|
|
||||||
/// Handle various global static destructors.
|
/// Handle various global static destructors.
|
||||||
|
|
Loading…
Reference in New Issue