cli: add CLI to manage openid realms.
This commit is contained in:
parent
b84d2592fb
commit
0decd11efb
|
@ -362,6 +362,7 @@ fn main() {
|
||||||
.insert("network", network_commands())
|
.insert("network", network_commands())
|
||||||
.insert("node", node_commands())
|
.insert("node", node_commands())
|
||||||
.insert("user", user_commands())
|
.insert("user", user_commands())
|
||||||
|
.insert("openid", openid_commands())
|
||||||
.insert("remote", remote_commands())
|
.insert("remote", remote_commands())
|
||||||
.insert("garbage-collection", garbage_collection_commands())
|
.insert("garbage-collection", garbage_collection_commands())
|
||||||
.insert("acme", acme_mgmt_cli())
|
.insert("acme", acme_mgmt_cli())
|
||||||
|
|
|
@ -24,3 +24,5 @@ mod disk;
|
||||||
pub use disk::*;
|
pub use disk::*;
|
||||||
mod node;
|
mod node;
|
||||||
pub use node::*;
|
pub use node::*;
|
||||||
|
mod openid;
|
||||||
|
pub use openid::*;
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
use anyhow::Error;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler};
|
||||||
|
|
||||||
|
use proxmox_backup::{config, api2, api2::types::REALM_ID_SCHEMA};
|
||||||
|
|
||||||
|
|
||||||
|
#[api(
|
||||||
|
input: {
|
||||||
|
properties: {
|
||||||
|
"output-format": {
|
||||||
|
schema: OUTPUT_FORMAT,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)]
|
||||||
|
/// List configured OpenId realms
|
||||||
|
fn list_openid_realms(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
|
||||||
|
|
||||||
|
let output_format = get_output_format(¶m);
|
||||||
|
|
||||||
|
let info = &api2::config::access::openid::API_METHOD_LIST_OPENID_REALMS;
|
||||||
|
let mut data = match info.handler {
|
||||||
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let options = default_table_format_options()
|
||||||
|
.column(ColumnConfig::new("realm"))
|
||||||
|
.column(ColumnConfig::new("issuer-url"))
|
||||||
|
.column(ColumnConfig::new("comment"));
|
||||||
|
|
||||||
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
||||||
|
|
||||||
|
Ok(Value::Null)
|
||||||
|
}
|
||||||
|
#[api(
|
||||||
|
input: {
|
||||||
|
properties: {
|
||||||
|
realm: {
|
||||||
|
schema: REALM_ID_SCHEMA,
|
||||||
|
},
|
||||||
|
"output-format": {
|
||||||
|
schema: OUTPUT_FORMAT,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)]
|
||||||
|
|
||||||
|
/// Show OpenID realm configuration
|
||||||
|
fn show_openid_realm(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
|
||||||
|
|
||||||
|
let output_format = get_output_format(¶m);
|
||||||
|
|
||||||
|
let info = &api2::config::access::openid::API_METHOD_READ_OPENID_REALM;
|
||||||
|
let mut data = match info.handler {
|
||||||
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let options = default_table_format_options();
|
||||||
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
||||||
|
|
||||||
|
Ok(Value::Null)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn openid_commands() -> CommandLineInterface {
|
||||||
|
|
||||||
|
let cmd_def = CliCommandMap::new()
|
||||||
|
.insert("list", CliCommand::new(&&API_METHOD_LIST_OPENID_REALMS))
|
||||||
|
.insert("show", CliCommand::new(&&API_METHOD_SHOW_OPENID_REALM)
|
||||||
|
.arg_param(&["realm"])
|
||||||
|
.completion_cb("realm", config::domains::complete_openid_realm_name)
|
||||||
|
)
|
||||||
|
.insert("create",
|
||||||
|
CliCommand::new(&api2::config::access::openid::API_METHOD_CREATE_OPENID_REALM)
|
||||||
|
.arg_param(&["realm"])
|
||||||
|
.arg_param(&["realm"])
|
||||||
|
.completion_cb("realm", config::domains::complete_openid_realm_name)
|
||||||
|
)
|
||||||
|
.insert("update",
|
||||||
|
CliCommand::new(&api2::config::access::openid::API_METHOD_UPDATE_OPENID_REALM)
|
||||||
|
.arg_param(&["realm"])
|
||||||
|
.arg_param(&["realm"])
|
||||||
|
.completion_cb("realm", config::domains::complete_openid_realm_name)
|
||||||
|
)
|
||||||
|
.insert("delete",
|
||||||
|
CliCommand::new(&api2::config::access::openid::API_METHOD_DELETE_OPENID_REALM)
|
||||||
|
.arg_param(&["realm"])
|
||||||
|
.arg_param(&["realm"])
|
||||||
|
.completion_cb("realm", config::domains::complete_openid_realm_name)
|
||||||
|
)
|
||||||
|
;
|
||||||
|
|
||||||
|
cmd_def.into()
|
||||||
|
}
|
|
@ -118,3 +118,12 @@ pub fn complete_realm_name(_arg: &str, _param: &HashMap<String, String>) -> Vec<
|
||||||
Err(_) => return vec![],
|
Err(_) => return vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn complete_openid_realm_name(_arg: &str, _param: &HashMap<String, String>) -> Vec<String> {
|
||||||
|
match config() {
|
||||||
|
Ok((data, _digest)) => data.sections.iter()
|
||||||
|
.filter_map(|(id, (t, _))| if t == "openid" { Some(id.to_string()) } else { None })
|
||||||
|
.collect(),
|
||||||
|
Err(_) => return vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue