Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cli option to use settings from env variables #7160

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions man/coolwsd.1
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ coolwsd OPTIONS
.PP
\fB\-\-nocaps\fR Use a non\-privileged forkit, with increase in security problems.
.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"
coolforkit(1), coolconvert(1), coolconfig(1), coolwsd-systemplate-setup(1), coolmount(1)
56 changes: 55 additions & 1 deletion wsd/COOLWSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ bool COOLWSD::NoSeccomp = false;
bool COOLWSD::AdminEnabled = true;
bool COOLWSD::UnattendedRun = false;
bool COOLWSD::SignalParent = false;
bool COOLWSD::UseEnvVarOptions = false;
std::string COOLWSD::RouteToken;
#if ENABLE_DEBUG
bool COOLWSD::SingleKit = false;
Expand Down Expand Up @@ -2122,7 +2123,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));
conf.addWriteable(overrideConfig, PRIO_APPLICATION); // Highest priority

Expand Down Expand Up @@ -2888,6 +2891,16 @@ void COOLWSD::defineOptions(OptionSet& optionSet)
.required(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
optionSet.addOption(Option("unitlib", "", "Unit testing library path.")
.required(false)
Expand Down Expand Up @@ -2956,6 +2969,8 @@ void COOLWSD::handleOption(const std::string& optionName,
LoTemplate = value;
else if (optionName == "signal")
SignalParent = true;
else if (optionName == "use-env-vars")
UseEnvVarOptions = true;

#if ENABLE_DEBUG
else if (optionName == "unitlib")
Expand Down Expand Up @@ -2986,6 +3001,45 @@ void COOLWSD::handleOption(const std::string& optionName,
#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

void COOLWSD::displayHelp()
Expand Down
2 changes: 2 additions & 0 deletions wsd/COOLWSD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class COOLWSD final : public Poco::Util::ServerApplication
static bool AdminEnabled;
static bool UnattendedRun; //< True when run from an unattended test, not interactive.
static bool SignalParent;
static bool UseEnvVarOptions;
static std::string RouteToken;
#if ENABLE_DEBUG
static bool SingleKit;
Expand Down Expand Up @@ -518,6 +519,7 @@ class COOLWSD final : public Poco::Util::ServerApplication

void defineOptions(Poco::Util::OptionSet& options) override;
void handleOption(const std::string& name, const std::string& value) override;
void initializeEnvOptions();
int main(const std::vector<std::string>& args) override;

/// Handle various global static destructors.
Expand Down