diff --git a/doc/11-cli-commands.md b/doc/11-cli-commands.md index 46c6e718c..883dd3995 100644 --- a/doc/11-cli-commands.md +++ b/doc/11-cli-commands.md @@ -135,20 +135,19 @@ added. ## CLI command: Api -Provides the helper functions `api setup` and `api user`. The first to enable the REST API, the second to create -ApiUser objects with hashed password strings. -More details in the [Icinga 2 API](12-icinga2-api.md#icinga2-api-setup) chapter. +Provides helper functions to enable and setup the +[Icinga 2 API](12-icinga2-api.md#icinga2-api-setup). + +### CLI command: Api Setup ``` -# icinga2 api --help +# icinga2 api setup --help icinga2 - The Icinga 2 network monitoring daemon (version: v2.11.0) Usage: - icinga2 [] + icinga2 api setup [] -Supported commands: - * api setup (setup for API) - * api user (API user creation helper) +Setup for Icinga 2 API. Global options: -h [ --help ] show this help message @@ -156,15 +155,18 @@ Global options: --color use VT100 color codes even when stdout is not a terminal -D [ --define ] arg define a constant - -a [ --app ] arg application library name (default: icinga) - -l [ --library ] arg load a library -I [ --include ] arg add include search directory -x [ --log-level ] arg specify the log level for the console log. The valid value is either debug, notice, information (default), warning, or critical -X [ --script-debugger ] whether to enable the script debugger +Command options: + --cn arg The certificate's common name + Report bugs at +Get support: +Documentation: Icinga home page: ``` diff --git a/lib/cli/apisetupcommand.cpp b/lib/cli/apisetupcommand.cpp index fcfb9c8cd..81b9d8db6 100644 --- a/lib/cli/apisetupcommand.cpp +++ b/lib/cli/apisetupcommand.cpp @@ -27,9 +27,11 @@ ImpersonationLevel ApiSetupCommand::GetImpersonationLevel() const return ImpersonateIcinga; } -int ApiSetupCommand::GetMaxArguments() const +void ApiSetupCommand::InitParameters(boost::program_options::options_description& visibleDesc, + boost::program_options::options_description& hiddenDesc) const { - return -1; + visibleDesc.add_options() + ("cn", po::value(), "The certificate's common name"); } /** @@ -39,10 +41,16 @@ int ApiSetupCommand::GetMaxArguments() const */ int ApiSetupCommand::Run(const boost::program_options::variables_map& vm, const std::vector& ap) const { - String cn = VariableUtility::GetVariable("NodeName"); + String cn; - if (cn.IsEmpty()) - cn = Utility::GetFQDN(); + if (vm.count("cn")) { + cn = vm["cn"].as(); + } else { + cn = VariableUtility::GetVariable("NodeName"); + + if (cn.IsEmpty()) + cn = Utility::GetFQDN(); + } if (!ApiSetupUtility::SetupMaster(cn, true)) return 1; diff --git a/lib/cli/apisetupcommand.hpp b/lib/cli/apisetupcommand.hpp index 9d0864eb0..be2693d13 100644 --- a/lib/cli/apisetupcommand.hpp +++ b/lib/cli/apisetupcommand.hpp @@ -20,7 +20,8 @@ public: String GetDescription() const override; String GetShortDescription() const override; - int GetMaxArguments() const override; + void InitParameters(boost::program_options::options_description& visibleDesc, + boost::program_options::options_description& hiddenDesc) const override; int Run(const boost::program_options::variables_map& vm, const std::vector& ap) const override; ImpersonationLevel GetImpersonationLevel() const override; };