diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:34:54 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:34:54 +0000 |
commit | 0915b3ef56dfac3113cce55a59a5765dc94976be (patch) | |
tree | a8fea11d50b4f083e1bf0f90025ece7f0824784a /lib/remote/configpackageutility.hpp | |
parent | Initial commit. (diff) | |
download | icinga2-0915b3ef56dfac3113cce55a59a5765dc94976be.tar.xz icinga2-0915b3ef56dfac3113cce55a59a5765dc94976be.zip |
Adding upstream version 2.13.6.upstream/2.13.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/remote/configpackageutility.hpp')
-rw-r--r-- | lib/remote/configpackageutility.hpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/remote/configpackageutility.hpp b/lib/remote/configpackageutility.hpp new file mode 100644 index 0000000..240f591 --- /dev/null +++ b/lib/remote/configpackageutility.hpp @@ -0,0 +1,73 @@ +/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ + +#ifndef CONFIGMODULEUTILITY_H +#define CONFIGMODULEUTILITY_H + +#include "remote/i2-remote.hpp" +#include "base/application.hpp" +#include "base/dictionary.hpp" +#include "base/process.hpp" +#include "base/string.hpp" +#include "base/defer.hpp" +#include "base/shared.hpp" +#include <vector> + +namespace icinga +{ + +/** + * Helper functions. + * + * @ingroup remote + */ +class ConfigPackageUtility +{ + +public: + static String GetPackageDir(); + + static void CreatePackage(const String& name); + static void DeletePackage(const String& name); + static std::vector<String> GetPackages(); + static bool PackageExists(const String& name); + + static String CreateStage(const String& packageName, const Dictionary::Ptr& files = nullptr); + static void DeleteStage(const String& packageName, const String& stageName); + static std::vector<String> GetStages(const String& packageName); + static String GetActiveStageFromFile(const String& packageName); + static String GetActiveStage(const String& packageName); + static void SetActiveStage(const String& packageName, const String& stageName); + static void SetActiveStageToFile(const String& packageName, const String& stageName); + static void ActivateStage(const String& packageName, const String& stageName); + static void AsyncTryActivateStage(const String& packageName, const String& stageName, bool activate, bool reload, + const Shared<Defer>::Ptr& resetPackageUpdates); + + static std::vector<std::pair<String, bool> > GetFiles(const String& packageName, const String& stageName); + + static bool ContainsDotDot(const String& path); + static bool ValidatePackageName(const String& packageName); + + static inline + bool ValidateStageName(const String& stageName) + { + return ValidateFreshName(stageName); + } + + static std::mutex& GetStaticPackageMutex(); + static std::mutex& GetStaticActiveStageMutex(); + +private: + static void CollectPaths(const String& path, std::vector<std::pair<String, bool> >& paths); + + static void WritePackageConfig(const String& packageName); + static void WriteStageConfig(const String& packageName, const String& stageName); + + static void TryActivateStageCallback(const ProcessResult& pr, const String& packageName, const String& stageName, bool activate, + bool reload, const Shared<Defer>::Ptr& resetPackageUpdates); + + static bool ValidateFreshName(const String& name); +}; + +} + +#endif /* CONFIGMODULEUTILITY_H */ |