2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2015-07-21 16:10:13 +02:00
|
|
|
|
|
|
|
#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"
|
2022-03-07 17:50:15 +01:00
|
|
|
#include "base/defer.hpp"
|
|
|
|
#include "base/shared.hpp"
|
2015-07-21 16:10:13 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper functions.
|
|
|
|
*
|
|
|
|
* @ingroup remote
|
|
|
|
*/
|
2017-12-31 07:22:16 +01:00
|
|
|
class ConfigPackageUtility
|
2015-07-21 16:10:13 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2018-01-04 04:25:35 +01:00
|
|
|
static String GetPackageDir();
|
2015-07-21 16:10:13 +02:00
|
|
|
|
2015-08-28 17:58:29 +02:00
|
|
|
static void CreatePackage(const String& name);
|
|
|
|
static void DeletePackage(const String& name);
|
2018-01-04 04:25:35 +01:00
|
|
|
static std::vector<String> GetPackages();
|
2015-08-28 17:58:29 +02:00
|
|
|
static bool PackageExists(const String& name);
|
2015-07-21 16:10:13 +02:00
|
|
|
|
2017-11-30 08:36:35 +01:00
|
|
|
static String CreateStage(const String& packageName, const Dictionary::Ptr& files = nullptr);
|
2015-08-28 17:58:29 +02:00
|
|
|
static void DeleteStage(const String& packageName, const String& stageName);
|
|
|
|
static std::vector<String> GetStages(const String& packageName);
|
2019-04-16 16:37:38 +02:00
|
|
|
static String GetActiveStageFromFile(const String& packageName);
|
2015-08-28 17:58:29 +02:00
|
|
|
static String GetActiveStage(const String& packageName);
|
2019-04-16 16:37:38 +02:00
|
|
|
static void SetActiveStage(const String& packageName, const String& stageName);
|
2019-04-26 14:51:28 +02:00
|
|
|
static void SetActiveStageToFile(const String& packageName, const String& stageName);
|
2015-08-28 17:58:29 +02:00
|
|
|
static void ActivateStage(const String& packageName, const String& stageName);
|
2022-03-07 17:50:15 +01:00
|
|
|
static void AsyncTryActivateStage(const String& packageName, const String& stageName, bool activate, bool reload,
|
|
|
|
const Shared<Defer>::Ptr& resetPackageUpdates);
|
2015-07-21 16:10:13 +02:00
|
|
|
|
2015-08-28 17:58:29 +02:00
|
|
|
static std::vector<std::pair<String, bool> > GetFiles(const String& packageName, const String& stageName);
|
2015-07-21 16:10:13 +02:00
|
|
|
|
|
|
|
static bool ContainsDotDot(const String& path);
|
2021-08-02 13:09:04 +02:00
|
|
|
static bool ValidatePackageName(const String& packageName);
|
|
|
|
|
|
|
|
static inline
|
|
|
|
bool ValidateStageName(const String& stageName)
|
|
|
|
{
|
|
|
|
return ValidateFreshName(stageName);
|
|
|
|
}
|
2015-07-21 16:10:13 +02:00
|
|
|
|
2021-02-02 10:16:04 +01:00
|
|
|
static std::mutex& GetStaticPackageMutex();
|
|
|
|
static std::mutex& GetStaticActiveStageMutex();
|
2017-09-20 16:40:02 +02:00
|
|
|
|
2015-07-21 16:10:13 +02:00
|
|
|
private:
|
|
|
|
static void CollectPaths(const String& path, std::vector<std::pair<String, bool> >& paths);
|
|
|
|
|
2015-08-28 17:58:29 +02:00
|
|
|
static void WritePackageConfig(const String& packageName);
|
|
|
|
static void WriteStageConfig(const String& packageName, const String& stageName);
|
2015-07-21 16:10:13 +02:00
|
|
|
|
2022-03-07 17:50:15 +01:00
|
|
|
static void TryActivateStageCallback(const ProcessResult& pr, const String& packageName, const String& stageName, bool activate,
|
|
|
|
bool reload, const Shared<Defer>::Ptr& resetPackageUpdates);
|
2021-08-02 13:09:04 +02:00
|
|
|
|
|
|
|
static bool ValidateFreshName(const String& name);
|
2015-07-21 16:10:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIGMODULEUTILITY_H */
|