]> granicus.if.org Git - icinga2/blob - lib/cli/pkisigncsrcommand.cpp
add some object locking to the Dump method (which could theoreticylly suffer from...
[icinga2] / lib / cli / pkisigncsrcommand.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "cli/pkisigncsrcommand.hpp"
4 #include "remote/pkiutility.hpp"
5 #include "base/logger.hpp"
6
7 using namespace icinga;
8 namespace po = boost::program_options;
9
10 REGISTER_CLICOMMAND("pki/sign-csr", PKISignCSRCommand);
11
12 String PKISignCSRCommand::GetDescription() const
13 {
14         return "Reads a Certificate Signing Request from stdin and prints a signed certificate on stdout.";
15 }
16
17 String PKISignCSRCommand::GetShortDescription() const
18 {
19         return "signs a CSR";
20 }
21
22 void PKISignCSRCommand::InitParameters(boost::program_options::options_description& visibleDesc,
23         boost::program_options::options_description& hiddenDesc) const
24 {
25         visibleDesc.add_options()
26                 ("csr", po::value<std::string>(), "CSR file path (input)")
27                 ("cert", po::value<std::string>(), "Certificate file path (output)");
28 }
29
30 std::vector<String> PKISignCSRCommand::GetArgumentSuggestions(const String& argument, const String& word) const
31 {
32         if (argument == "csr" || argument == "cert")
33                 return GetBashCompletionSuggestions("file", word);
34         else
35                 return CLICommand::GetArgumentSuggestions(argument, word);
36 }
37
38 /**
39  * The entry point for the "pki sign-csr" CLI command.
40  *
41  * @returns An exit status.
42  */
43 int PKISignCSRCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
44 {
45         if (!vm.count("csr")) {
46                 Log(LogCritical, "cli", "Certificate signing request file path (--csr) must be specified.");
47                 return 1;
48         }
49
50         if (!vm.count("cert")) {
51                 Log(LogCritical, "cli", "Certificate file path (--cert) must be specified.");
52                 return 1;
53         }
54
55         return PkiUtility::SignCsr(vm["csr"].as<std::string>(), vm["cert"].as<std::string>());
56 }