Merge pull request #7148 from Icinga/feature/api-setup-cn

Add --cn parameter to 'api setup' CLI command allowing hostname overrides
This commit is contained in:
Michael Friedrich 2019-04-26 12:04:58 +02:00 committed by GitHub
commit b878086565
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 16 deletions

View File

@ -135,20 +135,19 @@ added.
## CLI command: Api <a id="cli-command-api"></a>
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 <a id="cli-command-api-setup "></a>
```
# icinga2 api --help
# icinga2 api setup --help
icinga2 - The Icinga 2 network monitoring daemon (version: v2.11.0)
Usage:
icinga2 <command> [<arguments>]
icinga2 api setup [<arguments>]
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 <https://github.com/Icinga/icinga2>
Get support: <https://icinga.com/support/>
Documentation: <https://icinga.com/docs/>
Icinga home page: <https://icinga.com/>
```

View File

@ -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<std::string>(), "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<std::string>& ap) const
{
String cn = VariableUtility::GetVariable("NodeName");
String cn;
if (cn.IsEmpty())
cn = Utility::GetFQDN();
if (vm.count("cn")) {
cn = vm["cn"].as<std::string>();
} else {
cn = VariableUtility::GetVariable("NodeName");
if (cn.IsEmpty())
cn = Utility::GetFQDN();
}
if (!ApiSetupUtility::SetupMaster(cn, true))
return 1;

View File

@ -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<std::string>& ap) const override;
ImpersonationLevel GetImpersonationLevel() const override;
};