summaryrefslogtreecommitdiffstats
path: root/lib/remote/configpackageutility.hpp
blob: 240f5919c04f7970cd3a1cd544648b02cb15eb5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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 */