mirror of https://github.com/Icinga/icinga2.git
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:
commit
b878086565
|
@ -135,20 +135,19 @@ added.
|
||||||
|
|
||||||
## CLI command: Api <a id="cli-command-api"></a>
|
## 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
|
Provides helper functions to enable and setup the
|
||||||
ApiUser objects with hashed password strings.
|
[Icinga 2 API](12-icinga2-api.md#icinga2-api-setup).
|
||||||
More details in the [Icinga 2 API](12-icinga2-api.md#icinga2-api-setup) chapter.
|
|
||||||
|
### 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)
|
icinga2 - The Icinga 2 network monitoring daemon (version: v2.11.0)
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
icinga2 <command> [<arguments>]
|
icinga2 api setup [<arguments>]
|
||||||
|
|
||||||
Supported commands:
|
Setup for Icinga 2 API.
|
||||||
* api setup (setup for API)
|
|
||||||
* api user (API user creation helper)
|
|
||||||
|
|
||||||
Global options:
|
Global options:
|
||||||
-h [ --help ] show this help message
|
-h [ --help ] show this help message
|
||||||
|
@ -156,15 +155,18 @@ Global options:
|
||||||
--color use VT100 color codes even when stdout is not a
|
--color use VT100 color codes even when stdout is not a
|
||||||
terminal
|
terminal
|
||||||
-D [ --define ] arg define a constant
|
-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
|
-I [ --include ] arg add include search directory
|
||||||
-x [ --log-level ] arg specify the log level for the console log.
|
-x [ --log-level ] arg specify the log level for the console log.
|
||||||
The valid value is either debug, notice,
|
The valid value is either debug, notice,
|
||||||
information (default), warning, or critical
|
information (default), warning, or critical
|
||||||
-X [ --script-debugger ] whether to enable the script debugger
|
-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>
|
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/>
|
Icinga home page: <https://icinga.com/>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,11 @@ ImpersonationLevel ApiSetupCommand::GetImpersonationLevel() const
|
||||||
return ImpersonateIcinga;
|
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
|
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 (vm.count("cn")) {
|
||||||
|
cn = vm["cn"].as<std::string>();
|
||||||
|
} else {
|
||||||
|
cn = VariableUtility::GetVariable("NodeName");
|
||||||
|
|
||||||
if (cn.IsEmpty())
|
if (cn.IsEmpty())
|
||||||
cn = Utility::GetFQDN();
|
cn = Utility::GetFQDN();
|
||||||
|
}
|
||||||
|
|
||||||
if (!ApiSetupUtility::SetupMaster(cn, true))
|
if (!ApiSetupUtility::SetupMaster(cn, true))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -20,7 +20,8 @@ public:
|
||||||
|
|
||||||
String GetDescription() const override;
|
String GetDescription() const override;
|
||||||
String GetShortDescription() 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;
|
int Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const override;
|
||||||
ImpersonationLevel GetImpersonationLevel() const override;
|
ImpersonationLevel GetImpersonationLevel() const override;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue