MCPcopy Create free account
hub / github.com/Icinga/icinga2 / Run

Method Run

lib/cli/caremovecommand.cpp:59–94  ·  view source on GitHub ↗

* The entry point for the "ca remove" CLI command. * * @returns An exit status. */

Source from the content-addressed store, hash-verified

57 * @returns An exit status.
58 */
59int CARemoveCommand::Run(const boost::program_options::variables_map&, const std::vector<std::string>& ap) const
60{
61 String fingerPrint = ap[0];
62 String requestFile = ApiListener::GetCertificateRequestsDir() + "/" + fingerPrint + ".json";
63
64 if (!Utility::PathExists(requestFile)) {
65 Log(LogCritical, "cli")
66 << "No request exists for fingerprint '" << fingerPrint << "'.";
67 return 1;
68 }
69
70 Dictionary::Ptr request = Utility::LoadJsonFile(requestFile);
71 std::shared_ptr<X509> certRequest = StringToCertificate(request->Get("cert_request"));
72
73 if (!certRequest) {
74 Log(LogCritical, "cli", "Certificate request is invalid. Could not parse X.509 certificate for the 'cert_request' attribute.");
75 return 1;
76 }
77
78 String cn = GetCertificateCN(certRequest);
79
80 if (request->Contains("cert_response")) {
81 Log(LogCritical, "cli")
82 << "Certificate request for CN '" << cn << "' already signed, removal is not possible.";
83 return 1;
84 }
85
86 Utility::SaveJsonFile(ApiListener::GetCertificateRequestsDir() + "/" + fingerPrint + ".removed", 0600, request);
87
88 Utility::Remove(requestFile);
89
90 Log(LogInformation, "cli")
91 << "Certificate request for CN " << cn << " removed.";
92
93 return 0;
94}

Callers

nothing calls this directly

Calls 6

PathExistsFunction · 0.85
LogClass · 0.85
StringToCertificateFunction · 0.85
GetCertificateCNFunction · 0.85
GetMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected