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