1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "cli/pkinewcertcommand.hpp"
4 #include "remote/pkiutility.hpp"
5 #include "base/logger.hpp"
7 using namespace icinga;
8 namespace po = boost::program_options;
10 REGISTER_CLICOMMAND("pki/new-cert", PKINewCertCommand);
12 String PKINewCertCommand::GetDescription() const
14 return "Creates a new Certificate Signing Request, a self-signed X509 certificate or both.";
17 String PKINewCertCommand::GetShortDescription() const
19 return "creates a new CSR";
22 void PKINewCertCommand::InitParameters(boost::program_options::options_description& visibleDesc,
23 boost::program_options::options_description& hiddenDesc) const
25 visibleDesc.add_options()
26 ("cn", po::value<std::string>(), "Common Name")
27 ("key", po::value<std::string>(), "Key file path (output)")
28 ("csr", po::value<std::string>(), "CSR file path (optional, output)")
29 ("cert", po::value<std::string>(), "Certificate file path (optional, output)");
32 std::vector<String> PKINewCertCommand::GetArgumentSuggestions(const String& argument, const String& word) const
34 if (argument == "key" || argument == "csr" || argument == "cert")
35 return GetBashCompletionSuggestions("file", word);
37 return CLICommand::GetArgumentSuggestions(argument, word);
41 * The entry point for the "pki new-cert" CLI command.
43 * @returns An exit status.
45 int PKINewCertCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
47 if (!vm.count("cn")) {
48 Log(LogCritical, "cli", "Common name (--cn) must be specified.");
52 if (!vm.count("key")) {
53 Log(LogCritical, "cli", "Key file path (--key) must be specified.");
60 csr = vm["csr"].as<std::string>();
63 cert = vm["cert"].as<std::string>();
65 return PkiUtility::NewCert(vm["cn"].as<std::string>(), vm["key"].as<std::string>(), csr, cert);