mirror of https://github.com/Icinga/icinga2.git
Cli: Ensure that repository path is created on 'node add' command
fixes #7743
This commit is contained in:
parent
6961a922b6
commit
6332921fb6
|
@ -21,9 +21,12 @@
|
|||
#include "cli/nodeutility.hpp"
|
||||
#include "cli/repositoryutility.hpp"
|
||||
#include "base/logger.hpp"
|
||||
#include "base/console.hpp"
|
||||
#include "base/application.hpp"
|
||||
#include "base/objectlock.hpp"
|
||||
#include "base/tlsutility.hpp"
|
||||
#include "base/scriptvariable.hpp"
|
||||
#include "base/json.hpp"
|
||||
#include "base/objectlock.hpp"
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
@ -383,6 +386,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
|
|||
RepositoryUtility::CommitChangeLog();
|
||||
|
||||
/* store the new inventory for next run */
|
||||
NodeUtility::CreateRepositoryPath();
|
||||
Utility::SaveJsonFile(inventory_path, inventory);
|
||||
|
||||
std::cout << "Make sure to reload Icinga 2 for these changes to take effect." << std::endl;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "base/tlsutility.hpp"
|
||||
#include "base/convert.hpp"
|
||||
#include "base/utility.hpp"
|
||||
#include "base/scriptvariable.hpp"
|
||||
#include "base/json.hpp"
|
||||
#include "base/netstring.hpp"
|
||||
#include "base/stdiostream.hpp"
|
||||
|
@ -55,6 +56,20 @@ String NodeUtility::GetNodeSettingsFile(const String& name)
|
|||
return GetRepositoryPath() + "/" + SHA256(name) + ".settings";
|
||||
}
|
||||
|
||||
void NodeUtility::CreateRepositoryPath(void)
|
||||
{
|
||||
if (!Utility::PathExists(GetRepositoryPath()))
|
||||
Utility::MkDirP(GetRepositoryPath(), 0750);
|
||||
|
||||
String user = ScriptVariable::Get("RunAsUser");
|
||||
String group = ScriptVariable::Get("RunAsGroup");
|
||||
|
||||
if (!Utility::SetFileOwnership(GetRepositoryPath(), user, group)) {
|
||||
Log(LogWarning, "cli")
|
||||
<< "Cannot set ownership for user '" << user << "' group '" << group << "' on file '" << GetRepositoryPath() << "'. Verify it yourself!";
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<String> NodeUtility::GetNodeCompletionSuggestions(const String& word)
|
||||
{
|
||||
std::vector<String> suggestions;
|
||||
|
@ -147,6 +162,7 @@ void NodeUtility::AddNode(const String& name)
|
|||
node->Set("zone", name);
|
||||
node->Set("repository", Empty);
|
||||
|
||||
CreateRepositoryPath();
|
||||
Utility::SaveJsonFile(path, node);
|
||||
}
|
||||
|
||||
|
@ -159,6 +175,7 @@ void NodeUtility::AddNodeSettings(const String& name, const String& host,
|
|||
settings->Set("port", port);
|
||||
settings->Set("log_duration", log_duration);
|
||||
|
||||
CreateRepositoryPath();
|
||||
Utility::SaveJsonFile(GetNodeSettingsFile(name), settings);
|
||||
}
|
||||
|
||||
|
@ -444,6 +461,7 @@ int NodeUtility::UpdateBlackAndWhiteList(const String& type, const String& zone_
|
|||
lists->Add(new_filter);
|
||||
|
||||
String list_path = GetBlackAndWhiteListPath(type);
|
||||
CreateRepositoryPath();
|
||||
Utility::SaveJsonFile(list_path, lists);
|
||||
|
||||
return 0;
|
||||
|
@ -488,6 +506,7 @@ int NodeUtility::RemoveBlackAndWhiteList(const String& type, const String& zone_
|
|||
}
|
||||
|
||||
String list_path = GetBlackAndWhiteListPath(type);
|
||||
CreateRepositoryPath();
|
||||
Utility::SaveJsonFile(list_path, lists);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
static String GetRepositoryPath(void);
|
||||
static String GetNodeRepositoryFile(const String& name);
|
||||
static String GetNodeSettingsFile(const String& name);
|
||||
static void CreateRepositoryPath(void);
|
||||
static std::vector<String> GetNodeCompletionSuggestions(const String& word);
|
||||
|
||||
static void PrintNodes(std::ostream& fp);
|
||||
|
|
Loading…
Reference in New Issue