2019-02-25 08:48:22 -05:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2015-06-24 09:09:22 -04:00
|
|
|
|
|
|
|
|
#include "cli/apisetupcommand.hpp"
|
|
|
|
|
#include "cli/apisetuputility.hpp"
|
2015-11-26 02:09:24 -05:00
|
|
|
#include "cli/variableutility.hpp"
|
2015-06-24 09:09:22 -04:00
|
|
|
#include "base/logger.hpp"
|
|
|
|
|
#include "base/console.hpp"
|
2015-06-25 11:20:23 -04:00
|
|
|
#include <iostream>
|
2015-06-24 09:09:22 -04:00
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
namespace po = boost::program_options;
|
|
|
|
|
|
|
|
|
|
REGISTER_CLICOMMAND("api/setup", ApiSetupCommand);
|
|
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
String ApiSetupCommand::GetDescription() const
|
2015-06-24 09:09:22 -04:00
|
|
|
{
|
|
|
|
|
return "Setup for Icinga 2 API.";
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
String ApiSetupCommand::GetShortDescription() const
|
2015-06-24 09:09:22 -04:00
|
|
|
{
|
2017-08-11 10:23:24 -04:00
|
|
|
return "setup for API";
|
2015-06-24 09:09:22 -04:00
|
|
|
}
|
|
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
ImpersonationLevel ApiSetupCommand::GetImpersonationLevel() const
|
2015-06-24 09:09:22 -04:00
|
|
|
{
|
2019-01-04 09:29:25 -05:00
|
|
|
return ImpersonateIcinga;
|
2015-06-24 09:09:22 -04:00
|
|
|
}
|
|
|
|
|
|
2019-04-26 04:51:39 -04:00
|
|
|
void ApiSetupCommand::InitParameters(boost::program_options::options_description& visibleDesc,
|
2026-01-23 07:31:01 -05:00
|
|
|
[[maybe_unused]] boost::program_options::options_description& hiddenDesc) const
|
2015-06-24 09:09:22 -04:00
|
|
|
{
|
2019-04-26 04:51:39 -04:00
|
|
|
visibleDesc.add_options()
|
|
|
|
|
("cn", po::value<std::string>(), "The certificate's common name");
|
2015-06-24 09:09:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-10-26 02:03:41 -04:00
|
|
|
* The entry point for the "api setup" CLI command.
|
2015-06-24 09:09:22 -04:00
|
|
|
*
|
|
|
|
|
* @returns An exit status.
|
|
|
|
|
*/
|
2026-01-23 07:31:01 -05:00
|
|
|
int ApiSetupCommand::Run(const boost::program_options::variables_map& vm, [[maybe_unused]] const std::vector<std::string>& ap) const
|
2015-06-24 09:09:22 -04:00
|
|
|
{
|
2019-04-26 04:51:39 -04:00
|
|
|
String cn;
|
2015-11-26 02:09:24 -05:00
|
|
|
|
2019-04-26 04:51:39 -04:00
|
|
|
if (vm.count("cn")) {
|
|
|
|
|
cn = vm["cn"].as<std::string>();
|
|
|
|
|
} else {
|
|
|
|
|
cn = VariableUtility::GetVariable("NodeName");
|
|
|
|
|
|
|
|
|
|
if (cn.IsEmpty())
|
|
|
|
|
cn = Utility::GetFQDN();
|
|
|
|
|
}
|
2015-11-26 02:09:24 -05:00
|
|
|
|
2018-07-26 11:09:06 -04:00
|
|
|
if (!ApiSetupUtility::SetupMaster(cn, true))
|
2015-10-22 09:56:27 -04:00
|
|
|
return 1;
|
2015-06-24 09:09:22 -04:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|