]> granicus.if.org Git - icinga2/blob - lib/cli/pkiticketcommand.cpp
Added ca restore command+docs to undo effects of ca remove
[icinga2] / lib / cli / pkiticketcommand.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "cli/pkiticketcommand.hpp"
4 #include "remote/pkiutility.hpp"
5 #include "cli/variableutility.hpp"
6 #include "base/logger.hpp"
7 #include <iostream>
8
9 using namespace icinga;
10 namespace po = boost::program_options;
11
12 REGISTER_CLICOMMAND("pki/ticket", PKITicketCommand);
13
14 String PKITicketCommand::GetDescription() const
15 {
16         return "Generates an Icinga 2 ticket";
17 }
18
19 String PKITicketCommand::GetShortDescription() const
20 {
21         return "generates a ticket";
22 }
23
24 void PKITicketCommand::InitParameters(boost::program_options::options_description& visibleDesc,
25         boost::program_options::options_description& hiddenDesc) const
26 {
27         visibleDesc.add_options()
28                 ("cn", po::value<std::string>(), "Certificate common name")
29                 ("salt", po::value<std::string>(), "Ticket salt");
30 }
31
32 /**
33  * The entry point for the "pki ticket" CLI command.
34  *
35  * @returns An exit status.
36  */
37 int PKITicketCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
38 {
39         if (!vm.count("cn")) {
40                 Log(LogCritical, "cli", "Common name (--cn) must be specified.");
41                 return 1;
42         }
43
44         String salt = VariableUtility::GetVariable("TicketSalt");
45
46         if (vm.count("salt"))
47                 salt = vm["salt"].as<std::string>();
48
49         if (salt.IsEmpty()) {
50                 Log(LogCritical, "cli", "Ticket salt (--salt) must be specified.");
51                 return 1;
52         }
53
54         return PkiUtility::GenTicket(vm["cn"].as<std::string>(), salt, std::cout);
55 }