mirror of https://github.com/Icinga/icinga2.git
Merge pull request #6577 from Icinga/fix/setup-api-including-users-file
Include api user configuration file during api setup
This commit is contained in:
commit
b81f7a7415
|
@ -207,6 +207,15 @@ bool ApiSetupUtility::SetupMasterApiUser()
|
||||||
|
|
||||||
bool ApiSetupUtility::SetupMasterEnableApi()
|
bool ApiSetupUtility::SetupMasterEnableApi()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Ensure the api-users.conf file is included, when conf.d inclusion is disabled.
|
||||||
|
*/
|
||||||
|
if (!NodeUtility::GetConfigurationIncludeState("\"conf.d\"", true))
|
||||||
|
NodeUtility::UpdateConfiguration("\"conf.d/api-users.conf\"", true, false);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enable the API feature
|
||||||
|
*/
|
||||||
Log(LogInformation, "cli", "Enabling the 'api' feature.");
|
Log(LogInformation, "cli", "Enabling the 'api' feature.");
|
||||||
|
|
||||||
FeatureUtility::EnableFeatures({ "api" });
|
FeatureUtility::EnableFeatures({ "api" });
|
||||||
|
|
|
@ -265,6 +265,49 @@ void NodeUtility::SerializeObject(std::ostream& fp, const Dictionary::Ptr& objec
|
||||||
fp << "}\n\n";
|
fp << "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns true if the include is found, otherwise false
|
||||||
|
*/
|
||||||
|
bool NodeUtility::GetConfigurationIncludeState(const String& value, bool recursive) {
|
||||||
|
String configurationFile = Configuration::ConfigDir + "/icinga2.conf";
|
||||||
|
|
||||||
|
Log(LogInformation, "cli")
|
||||||
|
<< "Reading '" << configurationFile << "'.";
|
||||||
|
|
||||||
|
std::ifstream ifp(configurationFile.CStr());
|
||||||
|
|
||||||
|
String affectedInclude = value;
|
||||||
|
|
||||||
|
if (recursive)
|
||||||
|
affectedInclude = "include_recursive " + affectedInclude;
|
||||||
|
else
|
||||||
|
affectedInclude = "include " + affectedInclude;
|
||||||
|
|
||||||
|
bool isIncluded = false;
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while(std::getline(ifp, line)) {
|
||||||
|
/*
|
||||||
|
* Trying to find if the inclusion is enabled.
|
||||||
|
* First hit breaks out of the loop.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (line.compare(0, affectedInclude.GetLength(), affectedInclude) == 0) {
|
||||||
|
isIncluded = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We can safely break out here, since an enabled include always win.
|
||||||
|
*/
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ifp.close();
|
||||||
|
|
||||||
|
return isIncluded;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* include = false, will comment out the include statement
|
* include = false, will comment out the include statement
|
||||||
* include = true, will add an include statement or uncomment a statement if one is existing
|
* include = true, will add an include statement or uncomment a statement if one is existing
|
||||||
|
|
|
@ -44,6 +44,7 @@ public:
|
||||||
|
|
||||||
static bool WriteNodeConfigObjects(const String& filename, const Array::Ptr& objects);
|
static bool WriteNodeConfigObjects(const String& filename, const Array::Ptr& objects);
|
||||||
|
|
||||||
|
static bool GetConfigurationIncludeState(const String& value, bool recursive);
|
||||||
static bool UpdateConfiguration(const String& value, bool include, bool recursive);
|
static bool UpdateConfiguration(const String& value, bool include, bool recursive);
|
||||||
static void UpdateConstant(const String& name, const String& value);
|
static void UpdateConstant(const String& name, const String& value);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue